Updated Offers related tables (#13609)

no-issue

* Removed NOT_NULL constraint from stripe_coupon_id

When handling disconnecting from Stripe - we remove all Stripe data from
our database to ensure we do not have bad/invalid data stored. Removing
this constraint will allow us to set the value to NULL.

* Added created_at column to offer_redemptions

Offer Redemptions are not just a joining table, but an event. A created_at
date allows them to be ordered

Because this is in alpha it is simpler to just drop the tables and
re-add them, due to offer_redemptions depending on offers, we also drop
this table and re-add it.
This commit is contained in:
Fabien 'egg' O'Carroll 2021-10-20 14:22:37 +02:00 committed by GitHub
parent 2756af83bb
commit 4e326123d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 83 additions and 3 deletions

View File

@ -0,0 +1,19 @@
const utils = require('../../utils');
const migration = utils.addTable('offer_redemptions', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
offer_id: {type: 'string', maxlength: 24, nullable: false, references: 'offers.id', cascadeDelete: true},
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', cascadeDelete: true}
});
// This reverses an "addTable" migration so that we
// drop the table going forwards and re-add it going back
const up = migration.down;
const down = migration.up;
migration.up = up;
migration.down = down;
module.exports = migration;

View File

@ -0,0 +1,30 @@
const utils = require('../../utils');
const migration = utils.addTable('offers', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
active: {type: 'boolean', nullable: false, defaultTo: true},
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
code: {type: 'string', maxlength: 191, nullable: false, unique: true},
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id'},
stripe_coupon_id: {type: 'string', maxlength: 255, nullable: false, unique: true},
interval: {type: 'string', maxlength: 50, nullable: false},
currency: {type: 'string', maxlength: 50, nullable: true},
discount_type: {type: 'string', maxlength: 50, nullable: false},
discount_amount: {type: 'integer', nullable: false},
duration: {type: 'string', maxlength: 50, nullable: false},
duration_in_months: {type: 'integer', nullable: true},
portal_title: {type: 'string', maxlength: 191, nullable: false},
portal_description: {type: 'string', maxlength: 2000, nullable: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
});
// This reverses an "addTable" migration so that we
// drop the table going forwards and re-add it going back
const up = migration.down;
const down = migration.up;
migration.up = up;
migration.down = down;
module.exports = migration;

View File

@ -0,0 +1,21 @@
const utils = require('../../utils');
module.exports = utils.addTable('offers', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
active: {type: 'boolean', nullable: false, defaultTo: true},
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
code: {type: 'string', maxlength: 191, nullable: false, unique: true},
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id'},
stripe_coupon_id: {type: 'string', maxlength: 255, nullable: true, unique: true},
interval: {type: 'string', maxlength: 50, nullable: false},
currency: {type: 'string', maxlength: 50, nullable: true},
discount_type: {type: 'string', maxlength: 50, nullable: false},
discount_amount: {type: 'integer', nullable: false},
duration: {type: 'string', maxlength: 50, nullable: false},
duration_in_months: {type: 'integer', nullable: true},
portal_title: {type: 'string', maxlength: 191, nullable: false},
portal_description: {type: 'string', maxlength: 2000, nullable: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
});

View File

@ -0,0 +1,9 @@
const {addTable} = require('../../utils');
module.exports = addTable('offer_redemptions', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
offer_id: {type: 'string', maxlength: 24, nullable: false, references: 'offers.id', cascadeDelete: true},
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', cascadeDelete: true},
created_at: {type: 'dateTime', nullable: false}
});

View File

@ -390,7 +390,7 @@ module.exports = {
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
code: {type: 'string', maxlength: 191, nullable: false, unique: true},
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id'},
stripe_coupon_id: {type: 'string', maxlength: 255, nullable: false, unique: true},
stripe_coupon_id: {type: 'string', maxlength: 255, nullable: true, unique: true},
interval: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['month', 'year']]}},
currency: {type: 'string', maxlength: 50, nullable: true},
discount_type: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['percent', 'amount']]}},
@ -533,7 +533,8 @@ module.exports = {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
offer_id: {type: 'string', maxlength: 24, nullable: false, references: 'offers.id', cascadeDelete: true},
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},
created_at: {type: 'dateTime', nullable: false}
},
members_subscribe_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},

View File

@ -32,7 +32,7 @@ const defaultSettings = require('../../../../../core/server/data/schema/default-
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = '33ec13330fc7384b849ae4b0e506017d';
const currentSchemaHash = '06c1007b471faba9bb82d053f6ba6cc1';
const currentFixturesHash = 'c064a1b57c594e6a8d36f9e884df0a2a';
const currentSettingsHash = 'aa3fcbc8ab119b630aeda7366ead5493';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';