From d2acf3aada47793bcec33bf06d6703961ae0cdea Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 19 Aug 2022 15:11:41 +0100 Subject: [PATCH] Fixed attribution table missing on cascade delete refs: https://github.com/TryGhost/Ghost/issues/15252 - all columns with a foreign key (references prop) must have a deletion strategy - we just found a bug with this in the comments table - see referenced issue - this fix adjusts the schema and migration for this change before its released so we don't have to write a horrible migration later --- .../2022-08-16-14-25-add-subscription-created-events-table.js | 2 +- ghost/core/core/server/data/schema/schema.js | 2 +- ghost/core/test/unit/server/data/schema/integrity.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ghost/core/core/server/data/migrations/versions/5.10/2022-08-16-14-25-add-subscription-created-events-table.js b/ghost/core/core/server/data/migrations/versions/5.10/2022-08-16-14-25-add-subscription-created-events-table.js index 83c91dbf73..50b71e31a5 100644 --- a/ghost/core/core/server/data/migrations/versions/5.10/2022-08-16-14-25-add-subscription-created-events-table.js +++ b/ghost/core/core/server/data/migrations/versions/5.10/2022-08-16-14-25-add-subscription-created-events-table.js @@ -4,7 +4,7 @@ module.exports = addTable('members_subscription_created_events', { id: {type: 'string', maxlength: 24, nullable: false, primary: true}, created_at: {type: 'dateTime', nullable: false}, member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true}, - subscription_id: {type: 'string', maxlength: 24, nullable: false, references: 'members_stripe_customers_subscriptions.id'}, + subscription_id: {type: 'string', maxlength: 24, nullable: false, references: 'members_stripe_customers_subscriptions.id', cascadeDelete: true}, attribution_id: {type: 'string', maxlength: 24, nullable: true}, attribution_type: {type: 'string', maxlength: 50, nullable: true}, attribution_url: {type: 'string', maxlength: 2000, nullable: true} diff --git a/ghost/core/core/server/data/schema/schema.js b/ghost/core/core/server/data/schema/schema.js index 0b2ad9bb8c..b99dc4b2e8 100644 --- a/ghost/core/core/server/data/schema/schema.js +++ b/ghost/core/core/server/data/schema/schema.js @@ -608,7 +608,7 @@ module.exports = { id: {type: 'string', maxlength: 24, nullable: false, primary: true}, created_at: {type: 'dateTime', nullable: false}, member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true}, - subscription_id: {type: 'string', maxlength: 24, nullable: false, references: 'members_stripe_customers_subscriptions.id'}, + subscription_id: {type: 'string', maxlength: 24, nullable: false, references: 'members_stripe_customers_subscriptions.id', cascadeDelete: true}, attribution_id: {type: 'string', maxlength: 24, nullable: true}, attribution_type: {type: 'string', maxlength: 50, nullable: true}, attribution_url: {type: 'string', maxlength: 2000, nullable: true} diff --git a/ghost/core/test/unit/server/data/schema/integrity.test.js b/ghost/core/test/unit/server/data/schema/integrity.test.js index abd0580da8..73547d8e5a 100644 --- a/ghost/core/test/unit/server/data/schema/integrity.test.js +++ b/ghost/core/test/unit/server/data/schema/integrity.test.js @@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route */ describe('DB version integrity', function () { // Only these variables should need updating - const currentSchemaHash = '75ee5448311cbfb4c65e3843b6750d29'; + const currentSchemaHash = 'ec9f46178cb70d3297d266203659ef4c'; const currentFixturesHash = '0ae1887dd0b42508be946bdbd20d41c8'; const currentSettingsHash = 'd54210758b7054e2174fd34aa2320ad7'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';