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:
parent
21af34a0d4
commit
d05c6f84ca
1 changed files with 31 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
);
|
Loading…
Add table
Reference in a new issue