mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Added backfill migration for members created events (#15294)
closes https://github.com/TryGhost/Team/issues/1836 - Uses the timestamps from the members table to determine the timestamps for the events - Clears the table when downgrading to prevent having multiple rows for the same member Co-authored-by: Fabien "egg" O'Carroll <fabien@allou.is>
This commit is contained in:
parent
9abfae2ddb
commit
1f11282228
1 changed files with 32 additions and 0 deletions
|
@ -0,0 +1,32 @@
|
|||
const ObjectID = require('bson-objectid').default;
|
||||
const logging = require('@tryghost/logging');
|
||||
|
||||
const {createTransactionalMigration} = require('../../utils');
|
||||
|
||||
module.exports = createTransactionalMigration(
|
||||
async function up(knex) {
|
||||
const members = await knex('members')
|
||||
.select('id', 'created_at');
|
||||
|
||||
if (members.length === 0) {
|
||||
logging.warn(`Skipping migration because no members found`);
|
||||
return;
|
||||
}
|
||||
|
||||
const toInsert = members.map((member) => {
|
||||
return {
|
||||
id: ObjectID().toHexString(),
|
||||
member_id: member.id,
|
||||
created_at: member.created_at,
|
||||
source: 'member'
|
||||
};
|
||||
});
|
||||
|
||||
logging.info(`Inserting ${toInsert.length} members created events`);
|
||||
await knex.batchInsert('members_created_events', toInsert);
|
||||
},
|
||||
async function down(knex) {
|
||||
logging.info(`Clearing all members created events`);
|
||||
await knex('members_created_events').del();
|
||||
}
|
||||
);
|
Loading…
Add table
Reference in a new issue