diff --git a/core/server/data/migrations/versions/4.0/01-remove-not-null-constraint-from-plan-name-column.js b/core/server/data/migrations/versions/4.0/01-remove-not-null-constraint-from-plan-name-column.js deleted file mode 100644 index 3e3f31a39b..0000000000 --- a/core/server/data/migrations/versions/4.0/01-remove-not-null-constraint-from-plan-name-column.js +++ /dev/null @@ -1,64 +0,0 @@ -const {createNonTransactionalMigration} = require('../../utils'); -const {createTable, deleteTable} = require('../../../schema/commands'); -const logging = require('../../../../../shared/logging'); - -const tableDef = { - id: {type: 'string', maxlength: 24, nullable: false, primary: true}, - customer_id: {type: 'string', maxlength: 255, nullable: false, unique: false, references: 'members_stripe_customers.customer_id', cascadeDelete: true}, - subscription_id: {type: 'string', maxlength: 255, nullable: false, unique: true}, - plan_id: {type: 'string', maxlength: 255, nullable: false, unique: false}, - status: {type: 'string', maxlength: 50, nullable: false}, - cancel_at_period_end: {type: 'bool', nullable: false, defaultTo: false}, - cancellation_reason: {type: 'string', maxlength: 500, nullable: true}, - current_period_end: {type: 'dateTime', nullable: false}, - start_date: {type: 'dateTime', nullable: false}, - default_payment_card_last4: {type: 'string', maxlength: 4, nullable: true}, - created_at: {type: 'dateTime', nullable: false}, - created_by: {type: 'string', maxlength: 24, nullable: false}, - updated_at: {type: 'dateTime', nullable: true}, - updated_by: {type: 'string', maxlength: 24, nullable: true}, - plan_nickname: {type: 'string', maxlength: 50, nullable: true}, - plan_interval: {type: 'string', maxlength: 50, nullable: false}, - plan_amount: {type: 'integer', nullable: false}, - plan_currency: {type: 'string', maxLength: 3, nullable: false} -}; - -module.exports = createNonTransactionalMigration( - async function up(knex) { - if (knex.client.config.client === 'mysql') { - logging.info('Removing NOT_NULL constraint from members_stripe_customers_subscriptions:plan_nickname'); - await knex.schema.alterTable('members_stripe_customers_subscriptions', (table) => { - table.string('plan_nickname').nullable().alter(); - }); - } else { - // SQLite3 doesn't support altering columns, so we have to do a wee dance with a temp table. - logging.info('Creating temporary table temp_members_stripe_customers_subscriptions'); - - await createTable('temp_members_stripe_customers_subscriptions', knex, tableDef); - - logging.info('Copying data to temporary table temp_members_stripe_customers_subscriptions'); - await knex.raw(` - INSERT INTO temp_members_stripe_customers_subscriptions - SELECT * FROM members_stripe_customers_subscriptions - `); - - logging.info('Dropping table members_stripe_customers_subscriptions'); - await deleteTable('members_stripe_customers_subscriptions', knex); - - logging.info('Creating table members_stripe_customers_subscriptions'); - await createTable('members_stripe_customers_subscriptions', knex, tableDef); - - logging.info('Copying data from temporary table to members_stripe_customers_subscriptions'); - await knex.raw(` - INSERT INTO members_stripe_customers_subscriptions - SELECT * FROM temp_members_stripe_customers_subscriptions - `); - - logging.info('Dropping temporary table temp_members_stripe_customers_subscriptions'); - await deleteTable('temp_members_stripe_customers_subscriptions', knex); - } - }, - async function down() { - // noop - we can't add a not null constraint after some of the columns have been nulled - } -); diff --git a/core/server/data/schema/schema.js b/core/server/data/schema/schema.js index 98d1648a20..ea2bc71da3 100644 --- a/core/server/data/schema/schema.js +++ b/core/server/data/schema/schema.js @@ -447,7 +447,7 @@ module.exports = { updated_at: {type: 'dateTime', nullable: true}, updated_by: {type: 'string', maxlength: 24, nullable: true}, /* Below fields eventually should be normalised e.g. stripe_plans table, link to here on plan_id */ - plan_nickname: {type: 'string', maxlength: 50, nullable: true}, + plan_nickname: {type: 'string', maxlength: 50, nullable: false}, plan_interval: {type: 'string', maxlength: 50, nullable: false}, plan_amount: {type: 'integer', nullable: false}, plan_currency: {type: 'string', maxLength: 3, nullable: false} diff --git a/test/unit/data/schema/integrity_spec.js b/test/unit/data/schema/integrity_spec.js index 470101107d..3c6b4b824e 100644 --- a/test/unit/data/schema/integrity_spec.js +++ b/test/unit/data/schema/integrity_spec.js @@ -32,7 +32,7 @@ const defaultSettings = require('../../../../core/server/data/schema/default-set */ describe('DB version integrity', function () { // Only these variables should need updating - const currentSchemaHash = 'd23279e16028161ab337000744480111'; + const currentSchemaHash = '5861ed57418a0195ea01e431b8b55335'; const currentFixturesHash = '370d0da0ab7c45050b2ff30bce8896ba'; const currentSettingsHash = '24453dc02be9df7284acf1748862a545'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';