mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 05:14:12 +03:00
Added migration to populate recipient_filter
no-issue This populates the recipient_filter column for existing emails based on the visibility of the related post at the time of the migration.
This commit is contained in:
parent
918c721bd1
commit
601b6ce174
@ -0,0 +1,35 @@
|
||||
const {createTransactionalMigration} = require('../../utils');
|
||||
const logging = require('../../../../../shared/logging');
|
||||
|
||||
module.exports = createTransactionalMigration(
|
||||
async function up(connection) {
|
||||
logging.info('Updating emails.recipient_filter values based on posts.visibility');
|
||||
|
||||
const paidPostIds = (await connection('posts')
|
||||
.select('id')
|
||||
.where('visibility', 'paid')).map(row => row.id);
|
||||
|
||||
const membersPostIds = (await connection('posts')
|
||||
.select('id')
|
||||
.where('visibility', 'members')).map(row => row.id);
|
||||
|
||||
const publicPostIds = (await connection('posts')
|
||||
.select('id')
|
||||
.where('visibility', 'public')).map(row => row.id);
|
||||
|
||||
await connection('emails')
|
||||
.update('recipient_filter', 'paid')
|
||||
.whereIn('post_id', paidPostIds);
|
||||
|
||||
await connection('emails')
|
||||
.update('recipient_filter', 'all')
|
||||
.whereIn('post_id', membersPostIds.concat(publicPostIds));
|
||||
},
|
||||
|
||||
async function down(connection) {
|
||||
logging.info('Updating emails.recipient_filter values to paid');
|
||||
await connection('emails')
|
||||
.update('recipient_filter', 'paid');
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user