mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Updated newsletter sender name column as nullable (#14476)
refs TryGhost/Team#1513 - nullable `sender_name` allows us to use auto fallback of site title for sender name without setting any explicit value for it.
This commit is contained in:
parent
cc26c9aa9f
commit
5218cf194d
4 changed files with 41 additions and 27 deletions
|
@ -0,0 +1,33 @@
|
||||||
|
const logging = require('@tryghost/logging');
|
||||||
|
const {createNonTransactionalMigration} = require('../../utils');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: This doesn't use knex.alterTable as it doesn't work for down migration.
|
||||||
|
* It tries to insert a `null` into non `nullable` column while altering column
|
||||||
|
*/
|
||||||
|
module.exports = createNonTransactionalMigration(
|
||||||
|
async function up(knex) {
|
||||||
|
logging.info('Dropping NOT NULL constraint for: sender_name in table: newsletters');
|
||||||
|
|
||||||
|
await knex.schema.table('newsletters', function (table) {
|
||||||
|
table.dropColumn('sender_name');
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.table('newsletters', function (table) {
|
||||||
|
table.string('sender_name', 191).nullable();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async function down(knex) {
|
||||||
|
logging.info('Adding NOT NULL constraint for: sender_name in table: newsletters');
|
||||||
|
|
||||||
|
await knex.schema.table('newsletters', function (table) {
|
||||||
|
table.dropColumn('sender_name');
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.table('newsletters', function (table) {
|
||||||
|
// SQLite doesn't allow adding a non nullable column without any default
|
||||||
|
table.string('sender_name', 191).notNullable().defaultTo('Ghost');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -13,7 +13,7 @@ module.exports = {
|
||||||
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
||||||
description: {type: 'string', maxlength: 2000, nullable: true},
|
description: {type: 'string', maxlength: 2000, nullable: true},
|
||||||
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
||||||
sender_name: {type: 'string', maxlength: 191, nullable: false},
|
sender_name: {type: 'string', maxlength: 191, nullable: true},
|
||||||
sender_email: {type: 'string', maxlength: 191, nullable: true},
|
sender_email: {type: 'string', maxlength: 191, nullable: true},
|
||||||
sender_reply_to: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'newsletter', validations: {isIn: [['newsletter', 'support']]}},
|
sender_reply_to: {type: 'string', maxlength: 191, nullable: false, defaultTo: 'newsletter', validations: {isIn: [['newsletter', 'support']]}},
|
||||||
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'active'},
|
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'active'},
|
||||||
|
|
|
@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
|
||||||
*/
|
*/
|
||||||
describe('DB version integrity', function () {
|
describe('DB version integrity', function () {
|
||||||
// Only these variables should need updating
|
// Only these variables should need updating
|
||||||
const currentSchemaHash = 'ff2c43dc264d712397a912e9709a0410';
|
const currentSchemaHash = '026d0bffc2be9420c1d9fccf76656dac';
|
||||||
const currentFixturesHash = 'a08bedf7a552498ed6f4a0d72c732dd5';
|
const currentFixturesHash = 'a08bedf7a552498ed6f4a0d72c732dd5';
|
||||||
const currentSettingsHash = '71fa38d0c805c18ceebe0fda80886230';
|
const currentSettingsHash = '71fa38d0c805c18ceebe0fda80886230';
|
||||||
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
||||||
|
|
|
@ -17,36 +17,17 @@ describe('Unit: models/newsletter', function () {
|
||||||
|
|
||||||
describe('validation', function () {
|
describe('validation', function () {
|
||||||
describe('blank', function () {
|
describe('blank', function () {
|
||||||
it('name cannot be blank', function () {
|
it('throws validation error for mandatory fields', function () {
|
||||||
return models.Newsletter.add({
|
return models.Newsletter.add({})
|
||||||
sender_name: 'Jamie',
|
|
||||||
sender_email: 'jamie@example.com',
|
|
||||||
sender_reply_to: 'newsletter',
|
|
||||||
visibility: 'members',
|
|
||||||
sort_order: 0
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
throw new Error('expected ValidationError');
|
|
||||||
})
|
|
||||||
.catch(function (err) {
|
|
||||||
should(err[0] instanceof errors.ValidationError).eql(true);
|
|
||||||
err[0].message.should.match(/newsletters\.name/);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('sender name cannot be blank', function () {
|
|
||||||
return models.Newsletter.add({
|
|
||||||
name: 'Daily report 2',
|
|
||||||
sender_email: 'jamie@example.com',
|
|
||||||
sender_reply_to: 'newsletter',
|
|
||||||
sort_order: 0
|
|
||||||
})
|
|
||||||
.then(function () {
|
.then(function () {
|
||||||
throw new Error('expected ValidationError');
|
throw new Error('expected ValidationError');
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
|
err.length.should.eql(2);
|
||||||
(err[0] instanceof errors.ValidationError).should.eql(true);
|
(err[0] instanceof errors.ValidationError).should.eql(true);
|
||||||
err[0].message.should.match(/newsletters\.sender_name/);
|
(err[1] instanceof errors.ValidationError).should.eql(true);
|
||||||
|
err[0].message.should.match(/newsletters\.name/);
|
||||||
|
err[1].message.should.match(/newsletters\.slug/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue