0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Added migration that backfills newsletter_id on all subscribe events (#14597)

refs https://github.com/TryGhost/Team/issues/1478

Sets the newsletter_id to the id of the default newsletter.
This commit is contained in:
Simon Backx 2022-04-27 17:52:06 +02:00 committed by GitHub
parent 21af34a0d4
commit d05c6f84ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,31 @@
const logging = require('@tryghost/logging');
const {createTransactionalMigration} = require('../../utils');
module.exports = createTransactionalMigration(
async function up(knex) {
// Get the default newsletter
const newsletter = await knex('newsletters')
.where('status', 'active')
.orderBy('sort_order', 'asc')
.orderBy('created_at', 'asc')
.orderBy('id', 'asc')
.first('id');
if (!newsletter) {
logging.error(`Default newsletter not found - skipping`);
return;
}
// Set subscribe events
const updatedRows = await knex('members_subscribe_events')
.update({
newsletter_id: newsletter.id
})
.where('newsletter_id', null);
logging.info(`Updated ${updatedRows} members_subscribe_events with default newsletter id`);
},
async function down() {
// Not required
}
);