mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed null values in settings default newsletter migration (#14638)
refs https://ghost.slack.com/archives/C02G9E68C/p1651484563907609 - When the site has an empty name, it is set to `NULL` in settings. - The name column is not nullable in newsletters, breaking the migration in that case. - Fixed by excluding all non-nullable columns - Replaced JS Date object with raw SQL `CURRENT_TIMESTAMP`
This commit is contained in:
parent
438a368a01
commit
ab4ea4850d
1 changed files with 34 additions and 27 deletions
|
@ -4,6 +4,8 @@ const logging = require('@tryghost/logging');
|
|||
const startsWith = require('lodash/startsWith');
|
||||
const {createTransactionalMigration} = require('../../utils');
|
||||
|
||||
module.exports = createTransactionalMigration(
|
||||
async function up(knex) {
|
||||
// This uses the default settings from core/server/data/schema/default-settings/default-settings.json
|
||||
const newsletter = {
|
||||
id: (new ObjectId()).toHexString(),
|
||||
|
@ -28,11 +30,9 @@ const newsletter = {
|
|||
show_header_name: false,
|
||||
title_alignment: 'center',
|
||||
title_font_category: 'sans_serif',
|
||||
created_at: new Date()
|
||||
created_at: knex.raw('CURRENT_TIMESTAMP')
|
||||
};
|
||||
|
||||
module.exports = createTransactionalMigration(
|
||||
async function up(knex) {
|
||||
// Make sure the newsletter table is empty
|
||||
const newsletters = await knex('newsletters').count('*', {as: 'total'});
|
||||
|
||||
|
@ -68,6 +68,13 @@ module.exports = createTransactionalMigration(
|
|||
if (startsWith(key, 'newsletter_')) {
|
||||
key = key.slice(11);
|
||||
}
|
||||
|
||||
if (value === null && ['name', 'body_font_category', 'show_badge', 'show_feature_image', 'show_header_icon', 'show_header_title', 'title_alignment', 'title_font_category'].includes(key)) {
|
||||
// Prevent setting null to non-nullable columns
|
||||
// Default to defaults above in that case
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof newsletter[key] === 'boolean') {
|
||||
newsletter[key] = value === 'true';
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue