diff --git a/core/server/data/migrations/versions/3.38/02-populate-email-recipient-filter-column.js b/core/server/data/migrations/versions/3.38/02-populate-email-recipient-filter-column.js new file mode 100644 index 0000000000..9630314acc --- /dev/null +++ b/core/server/data/migrations/versions/3.38/02-populate-email-recipient-filter-column.js @@ -0,0 +1,34 @@ +const {createTransactionalMigration} = require('../../utils'); +const logging = require('../../../../../shared/logging'); + +module.exports = createTransactionalMigration( + async function up(connection) { + logging.info('Updating email_recipient_filter values based on visibility and send_email_when_published'); + await connection('posts') + .update('email_recipient_filter', 'paid') + .where({ + send_email_when_published: true, + visibility: 'paid' + }); + + await connection('posts') + .update('email_recipient_filter', 'all') + .where({ + send_email_when_published: true, + visibility: 'members' + }); + + await connection('posts') + .update('email_recipient_filter', 'all') + .where({ + send_email_when_published: true, + visibility: 'public' + }); + }, + + async function down(connection) { + logging.info('Updating email_recipient_filter values to none'); + await connection('posts') + .update('email_recipient_filter', 'none'); + } +);