0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Updated migrations to always set group,types,flags

refs #10318

Because settings are not populated with the correct group and flags, we
must _always_ set these. Then we can check to see if there are values
which need migrating, and if not, can safely exit and leave the values
as default.
This commit is contained in:
Fabien O'Carroll 2020-06-30 12:05:58 +02:00 committed by Fabien 'egg' O'Carroll
parent fa2c9a4da1
commit f2f40a5f4a
2 changed files with 63 additions and 16 deletions

View file

@ -8,6 +8,35 @@ module.exports = {
async up(config) {
const knex = config.transacting;
const defaultOperations = [{
key: 'members_from_address',
flags: 'RO'
}, {
key: 'members_allow_free_signup'
}, {
key: 'stripe_product_name'
}, {
key: 'stripe_secret_key'
}, {
key: 'stripe_publishable_key'
}, {
key: 'stripe_plans'
}];
for (const operation of defaultOperations) {
logging.info(`Updating ${operation.key} setting group,type,flags`);
await knex('settings')
.where({
key: operation.key
})
.update({
group: 'members',
type: 'members',
flags: operation.flags || ''
});
}
const membersSubscriptionSettingsJSON = await knex('settings')
.select('value')
.where('key', 'members_subscription_settings')
@ -35,10 +64,9 @@ module.exports = {
});
});
const operations = [{
const valueOperations = [{
key: 'members_from_address',
value: membersFromAddress,
flags: 'RO'
value: membersFromAddress
}, {
key: 'members_allow_free_signup',
value: membersAllowSelfSignup.toString()
@ -56,17 +84,14 @@ module.exports = {
value: JSON.stringify(stripePlans)
}];
for (const operation of operations) {
logging.info(`Updating ${operation.key} setting`);
for (const operation of valueOperations) {
logging.info(`Updating ${operation.key} setting value`);
await knex('settings')
.where({
key: operation.key
})
.update({
value: operation.value,
group: 'members',
flags: operation.flags || '',
type: 'members'
value: operation.value
});
}

View file

@ -8,6 +8,31 @@ module.exports = {
async up(config) {
const knex = config.transacting;
const defaultOperations = [{
key: 'stripe_connect_publishable_key'
}, {
key: 'stripe_connect_secret_key'
}, {
key: 'stripe_connect_livemode'
}, {
key: 'stripe_connect_display_name'
}, {
key: 'stripe_connect_account_id'
}];
for (const operation of defaultOperations) {
logging.info(`Updating ${operation.key} setting group,type,flags`);
await knex('settings')
.where({
key: operation.key
})
.update({
group: 'members',
flags: '',
type: 'members'
});
}
const stripeConnectIntegrationJSON = await knex('settings')
.select('value')
.where('key', 'stripe_connect_integration')
@ -20,7 +45,7 @@ module.exports = {
const stripeConnectIntegration = JSON.parse(stripeConnectIntegrationJSON.value);
const operations = [{
const valueOperations = [{
key: 'stripe_connect_publishable_key',
value: stripeConnectIntegration.public_key || ''
}, {
@ -37,17 +62,14 @@ module.exports = {
value: stripeConnectIntegration.account_id || ''
}];
for (const operation of operations) {
logging.info(`Updating ${operation.key} setting`);
for (const operation of valueOperations) {
logging.info(`Updating ${operation.key} setting value`);
await knex('settings')
.where({
key: operation.key
})
.update({
value: operation.value,
group: 'members',
flags: '',
type: 'members'
value: operation.value
});
}