Migrated redirect settings to welcome_page_urls (#14083)

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

This migrates the existing settings onto the Tier objects, so that users
with Tiers enabled can seamless move from global settings to Tier level
settings - without losing/modifying data/functionality.
This commit is contained in:
Fabien 'egg' O'Carroll 2022-02-01 11:00:13 +02:00 committed by GitHub
parent dd7227d622
commit 155ee6055d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,45 @@
const logging = require('@tryghost/logging');
// For DML - data changes
const {createTransactionalMigration} = require('../../utils');
module.exports = createTransactionalMigration(
async function up(knex) {
logging.info('Setting welcome_page_url from settings');
const paidSignupRedirect = await knex('settings')
.select('value')
.where('key', 'members_paid_signup_redirect')
.first();
const freeSignupRedirect = await knex('settings')
.select('value')
.where('key', 'members_free_signup_redirect')
.first();
if (paidSignupRedirect) {
logging.info(`Setting paid Tiers welcome_page_url to ${paidSignupRedirect.value}`);
await knex('products')
.update('welcome_page_url', paidSignupRedirect.value)
.where('type', 'paid');
} else {
logging.info(`No members_paid_signup_redirect setting found`);
}
if (freeSignupRedirect) {
logging.info(`Setting free Tiers welcome_page_url to ${freeSignupRedirect.value}`);
await knex('products')
.update('welcome_page_url', freeSignupRedirect.value)
.where('type', 'free');
} else {
logging.info(`No members_paid_signup_redirect setting found`);
}
},
async function down(knex) {
logging.info('Setting welcome_page_url to NULL');
await knex('products')
.update('welcome_page_url', null);
}
);