Fixed migrations for missing settings

refs #10318

If migrating from a previous version that does not include the setting
being migrated from we can safely not update the new setting, and just
rely on its default value being present. When rolling back we can use
defaults if the new setting does not exist.
This commit is contained in:
Fabien O'Carroll 2020-06-30 09:54:14 +02:00 committed by Fabien 'egg' O'Carroll
parent bf736717e4
commit 3b8cdb1657
3 changed files with 41 additions and 11 deletions

View File

@ -37,6 +37,11 @@ module.exports = {
.select('value')
.first();
if (!oldSetting) {
logging.warn(`Could not find setting ${renameMapping.from}, not updating ${renameMapping.to} value`);
return;
}
const updatedValue = renameMapping.getToValue ? renameMapping.getToValue(oldSetting.value) : oldSetting.value;
logging.info(`Updating ${renameMapping.to} with value from ${renameMapping.from}`);
@ -58,6 +63,11 @@ module.exports = {
.select('value')
.first();
if (!newSetting) {
logging.warn(`Could not find setting ${renameMapping.to}, not updating ${renameMapping.from} value`);
return;
}
const updatedValue = renameMapping.getFromValue ? renameMapping.getFromValue(newSetting.value) : newSetting.value;
logging.info(`Updating ${renameMapping.from} with value from ${renameMapping.to}`);

View File

@ -13,6 +13,11 @@ module.exports = {
.where('key', 'members_subscription_settings')
.first();
if (!membersSubscriptionSettingsJSON) {
logging.warn(`Could not find members_subscription_settings - using default values`);
return;
}
const membersSubscriptionSettings = JSON.parse(membersSubscriptionSettingsJSON.value);
const membersFromAddress = membersSubscriptionSettings.fromAddress;
@ -84,20 +89,30 @@ module.exports = {
const stripePlans = await getSetting('stripe_plans');
const allowSelfSignupBoolean = allowSelfSignup.value === 'true';
const allowSelfSignupBoolean = allowSelfSignup && allowSelfSignup.value === 'true';
const membersSubscriptionSettings = {
fromAddress: membersFromAddress.value,
fromAddress: membersFromAddress ? membersFromAddress.value : 'noreply',
allowSelfSignup: allowSelfSignupBoolean,
paymentProcessors: [{
adapter: 'stripe',
config: {
secret_token: stripeDirectSecretKey.value,
public_token: stripeDirectPublishableKey.value,
secret_token: stripeDirectSecretKey ? stripeDirectSecretKey.value : null,
public_token: stripeDirectPublishableKey ? stripeDirectPublishableKey.value : null,
product: {
name: stripeProductName.value
name: stripeProductName ? stripeProductName.value : 'Ghost Subscription'
},
plans: JSON.parse(stripePlans.value)
plans: stripePlans ? JSON.parse(stripePlans.value) : [{
name: 'Monthly',
currency: 'usd',
interval: 'month',
amount: 500
}, {
name: 'Yearly',
currency: 'usd',
interval: 'year',
amount: 5000
}]
}
}]
};

View File

@ -13,6 +13,11 @@ module.exports = {
.where('key', 'stripe_connect_integration')
.first();
if (!stripeConnectIntegrationJSON) {
logging.warn(`Could not find stripe_connect_integration - using default values`);
return;
}
const stripeConnectIntegration = JSON.parse(stripeConnectIntegrationJSON.value);
const operations = [{
@ -64,11 +69,11 @@ module.exports = {
const secretKey = await getSetting('stripe_connect_secret_key');
const stripeConnectIntegration = {
account_id: accountId.value,
display_name: displayName.value,
livemode: livemode.value,
public_key: publishableKey.value,
secret_key: secretKey.value
account_id: accountId ? accountId.value : null,
display_name: displayName ? displayName.value : null,
livemode: livemode ? livemode.value : null,
public_key: publishableKey ? publishableKey.value : null,
secret_key: secretKey ? secretKey.value : null
};
const now = knex.raw('CURRENT_TIMESTAMP');