🐛 Fixed a foreign key to point to the right column

pr https://github.com/TryGhost/Ghost/pull/12713
This commit is contained in:
Thibaut Patel 2021-03-09 13:51:51 +01:00 committed by Thibaut Patel
parent 6a512a50f9
commit 2eb5f19090
2 changed files with 36 additions and 2 deletions

View File

@ -61,14 +61,14 @@ module.exports = createIrreversibleMigration(async (knex) => {
fromTable: 'members_stripe_customers_subscriptions', fromTable: 'members_stripe_customers_subscriptions',
fromColumn: 'customer_id', fromColumn: 'customer_id',
toTable: 'members_stripe_customers', toTable: 'members_stripe_customers',
toColumn: 'id', toColumn: 'customer_id',
transaction: knex transaction: knex
}); });
await addForeign({ await addForeign({
fromTable: 'members_stripe_customers_subscriptions', fromTable: 'members_stripe_customers_subscriptions',
fromColumn: 'customer_id', fromColumn: 'customer_id',
toTable: 'members_stripe_customers', toTable: 'members_stripe_customers',
toColumn: 'id', toColumn: 'customer_id',
cascadeDelete: true, cascadeDelete: true,
transaction: knex transaction: knex
}); });

View File

@ -0,0 +1,34 @@
const logging = require('../../../../../shared/logging');
const {createIrreversibleMigration} = require('../../utils');
const {addForeign, dropForeign} = require('../../../schema/commands');
module.exports = createIrreversibleMigration(async (knex) => {
if (knex.client.config.client !== 'sqlite3') {
return logging.warn('Skipping fixing foreign key for members_stripe_customers_subscriptions - database is not SQLite3');
}
logging.info('Fixing foreign keys for members_stripe_customers_subscriptions');
await dropForeign({
fromTable: 'members_stripe_customers_subscriptions',
fromColumn: 'customer_id',
toTable: 'members_stripe_customers',
toColumn: 'id',
transaction: knex
});
await dropForeign({
fromTable: 'members_stripe_customers_subscriptions',
fromColumn: 'customer_id',
toTable: 'members_stripe_customers',
toColumn: 'customer_id',
transaction: knex
});
await addForeign({
fromTable: 'members_stripe_customers_subscriptions',
fromColumn: 'customer_id',
toTable: 'members_stripe_customers',
toColumn: 'customer_id',
cascadeDelete: true,
transaction: knex
});
});