diff --git a/ghost/core/core/server/data/migrations/versions/5.8/2022-08-03-15-28-add-trial-start-column-to-stripe-subscriptions.js b/ghost/core/core/server/data/migrations/versions/5.8/2022-08-03-15-28-add-trial-start-column-to-stripe-subscriptions.js new file mode 100644 index 0000000000..59c33efdcd --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.8/2022-08-03-15-28-add-trial-start-column-to-stripe-subscriptions.js @@ -0,0 +1,6 @@ +const {createAddColumnMigration} = require('../../utils'); + +module.exports = createAddColumnMigration('members_stripe_customers_subscriptions', 'trial_start_at', { + type: 'dateTime', + nullable: true +}); diff --git a/ghost/core/core/server/data/migrations/versions/5.8/2022-08-03-15-29-add-trial-end-column-to-stripe-subscriptions.js b/ghost/core/core/server/data/migrations/versions/5.8/2022-08-03-15-29-add-trial-end-column-to-stripe-subscriptions.js new file mode 100644 index 0000000000..47029b2be2 --- /dev/null +++ b/ghost/core/core/server/data/migrations/versions/5.8/2022-08-03-15-29-add-trial-end-column-to-stripe-subscriptions.js @@ -0,0 +1,6 @@ +const {createAddColumnMigration} = require('../../utils'); + +module.exports = createAddColumnMigration('members_stripe_customers_subscriptions', 'trial_end_at', { + type: 'dateTime', + nullable: true +}); diff --git a/ghost/core/core/server/data/schema/schema.js b/ghost/core/core/server/data/schema/schema.js index fc05881815..846e65f47e 100644 --- a/ghost/core/core/server/data/schema/schema.js +++ b/ghost/core/core/server/data/schema/schema.js @@ -585,6 +585,8 @@ module.exports = { updated_by: {type: 'string', maxlength: 24, nullable: true}, mrr: {type: 'integer', unsigned: true, nullable: false, defaultTo: 0}, offer_id: {type: 'string', maxlength: 24, nullable: true, unique: false, references: 'offers.id'}, + trial_start_at: {type: 'dateTime', nullable: true}, + trial_end_at: {type: 'dateTime', nullable: true}, /* Below fields are now redundant as we link prie_id to stripe_prices table */ plan_id: {type: 'string', maxlength: 255, nullable: false, unique: false}, plan_nickname: {type: 'string', maxlength: 50, nullable: false}, 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 3c7726e78c..a5a3847994 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 = '01156d65accecd6a056a6a8341e8b81f'; + const currentSchemaHash = '45337ae85129a98e4c1b551cc91790da'; const currentFixturesHash = 'a75211a41f515202280be7cb287e101f'; const currentSettingsHash = 'd54210758b7054e2174fd34aa2320ad7'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; diff --git a/ghost/members-api/lib/repositories/member.js b/ghost/members-api/lib/repositories/member.js index f8370ae181..7179bc809f 100644 --- a/ghost/members-api/lib/repositories/member.js +++ b/ghost/members-api/lib/repositories/member.js @@ -803,6 +803,9 @@ module.exports = class MemberRepository { default_payment_card_last4: paymentMethod && paymentMethod.card && paymentMethod.card.last4 || null, stripe_price_id: subscriptionPriceData.id, plan_id: subscriptionPriceData.id, + // trial start and end are returned as Stripe timestamps and need coversion + trial_start_at: subscription.trial_start ? new Date(subscription.trial_start * 1000) : null, + trial_end_at: subscription.trial_end ? new Date(subscription.trial_end * 1000) : null, // NOTE: Defaulting to interval as migration to nullable field // turned out to be much bigger problem. // Ideally, would need nickname field to be nullable on the DB level @@ -1371,4 +1374,3 @@ module.exports = class MemberRepository { return true; } }; -