0
Fork 0
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:
Simon Backx 2022-08-24 15:38:00 +02:00 committed by GitHub
parent 9abfae2ddb
commit 1f11282228
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();
}
);