diff --git a/core/server/data/migrations/versions/4.20/05-remove-not-null-constraint-from-portal-title.js b/core/server/data/migrations/versions/4.20/05-remove-not-null-constraint-from-portal-title.js new file mode 100644 index 0000000000..e333971e1c --- /dev/null +++ b/core/server/data/migrations/versions/4.20/05-remove-not-null-constraint-from-portal-title.js @@ -0,0 +1,41 @@ +const logging = require('@tryghost/logging'); +const {createNonTransactionalMigration} = require('../../utils'); +const {addUnique} = require('../../../schema/commands'); + +module.exports = createNonTransactionalMigration( + async function up(knex) { + logging.info('Dropping NOT NULL constraint for: portal_title in table: offers'); + + await knex.schema.table('offers', function (table) { + table.dropColumn('portal_title'); + }); + + await knex.schema.table('offers', function (table) { + table.string('portal_title', 191).nullable(); + }); + + if (knex.client.config.client === 'sqlite3') { + for (const column of ['name', 'code', 'stripe_coupon_id']) { + await addUnique('offers', column, knex); + } + } + }, + async function down(knex) { + logging.info('Adding NOT NULL constraint for: portal_title in table: offers'); + + await knex.schema.table('offers', function (table) { + table.dropColumn('portal_title'); + }); + + await knex.schema.table('offers', function (table) { + table.string('portal_title', 191).notNullable(); + }); + + if (knex.client.config.client === 'sqlite3') { + for (const column of ['name', 'code', 'stripe_coupon_id']) { + await addUnique('offers', column, knex); + } + } + } +); + diff --git a/core/server/data/schema/schema.js b/core/server/data/schema/schema.js index 291f278d87..fd1adc5c68 100644 --- a/core/server/data/schema/schema.js +++ b/core/server/data/schema/schema.js @@ -397,7 +397,7 @@ module.exports = { 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_title: {type: 'string', maxlength: 191, nullable: true}, portal_description: {type: 'string', maxlength: 2000, nullable: true}, created_at: {type: 'dateTime', nullable: false}, updated_at: {type: 'dateTime', nullable: true} diff --git a/test/unit/server/data/schema/integrity.test.js b/test/unit/server/data/schema/integrity.test.js index 6a266814e5..3e480ce4fa 100644 --- a/test/unit/server/data/schema/integrity.test.js +++ b/test/unit/server/data/schema/integrity.test.js @@ -34,7 +34,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route */ describe('DB version integrity', function () { // Only these variables should need updating - const currentSchemaHash = '06c1007b471faba9bb82d053f6ba6cc1'; + const currentSchemaHash = 'e649797a5de92d417744f6f2623c79cf'; const currentFixturesHash = '07d4b0c4cf159b34344a6b5e88c74e9f'; const currentSettingsHash = 'aa3fcbc8ab119b630aeda7366ead5493'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';