mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Removed NOT NULL constraint from portal_title (#13659)
refs https://github.com/TryGhost/Team/issues/1163 We want to make the title for Offers optional, our nullable validation means that we cannot store an empty string, so we must remove the NOT NULL constraint from the column if we want to store either an empty value or null. There is a bug with editing columns in SQLite with `knex` which strips all the indexes, so we have to manually add them afterwards.
This commit is contained in:
parent
4d56e9a7af
commit
d962f0e18e
3 changed files with 43 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -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}
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Add table
Reference in a new issue