🐛 Fixed failing migration from <2.34 to 3.29

closes https://github.com/TryGhost/Ghost/issues/12129

Migrations were failing when upgrading from a version that didn't include stripe member subscriptions table. The `up` migration was checking for the existence of a unique index that was added to the schema in 3.29 but it was using the wrong variable name which meant that it would never return true for an existing index. For most migrations this worked because the index existed but when through 2.34 the table was created from scratch and did included the index at that point.

- fixed variable name and re-ordered variable assignment for better code locality that would have made the typo more visible
This commit is contained in:
Kevin Ansfield 2020-08-17 18:31:00 +01:00
parent c81d11b910
commit 752c1022f9

View File

@ -50,7 +50,6 @@ module.exports = {
// stripe tables have not had any indexes/constraints in the past, add them now with ON DELETE CASCADE
const [membersStripeCustomersIndexes] = await knex.raw('SHOW INDEXES FROM members_stripe_customers');
const [membersStripeCustomersSubscriptionsIndexes] = await knex.raw('SHOW INDEXES from members_stripe_customers_subscriptions');
if (membersStripeCustomersIndexes.find(index => index.Key_name === 'members_stripe_customers_member_id_foreign')) {
logging.warn('Skipping "members_stripe_customers_member_id_foreign" foreign key constraint creation - already exists');
@ -70,7 +69,9 @@ module.exports = {
});
}
if (membersStripeCustomersIndexes.find(index => index.Key_name === 'members_stripe_customers_subscriptions_subscription_id_unique')) {
const [membersStripeCustomersSubscriptionsIndexes] = await knex.raw('SHOW INDEXES from members_stripe_customers_subscriptions');
if (membersStripeCustomersSubscriptionsIndexes.find(index => index.Key_name === 'members_stripe_customers_subscriptions_subscription_id_unique')) {
logging.warn('Skipping "members_stripe_customers_subscriptions_subscription_id_unique" index creation - already exists');
} else {
logging.info('Adding "members_stripe_customers_subscriptions_subscription_id_unique" index');
@ -94,7 +95,6 @@ module.exports = {
return logging.warn('Skipping member tables index removal - database is not MySQL');
}
const [membersStripeCustomersIndexes] = await knex.raw('SHOW INDEXES FROM members_stripe_customers');
const [membersStripeCustomersSubscriptionsIndexes] = await knex.raw('SHOW INDEXES from members_stripe_customers_subscriptions');
if (!membersStripeCustomersSubscriptionsIndexes.find(index => index.Key_name === 'members_stripe_customers_subscriptions_customer_id_foreign')) {
@ -117,6 +117,8 @@ module.exports = {
});
}
const [membersStripeCustomersIndexes] = await knex.raw('SHOW INDEXES FROM members_stripe_customers');
if (!membersStripeCustomersIndexes.find(index => index.Key_name === 'members_stripe_customers_customer_id_unique')) {
logging.warn('Skipping "members_stripe_customers_customer_id_unique" index removal - does not exist');
} else {