Updated unsplash setting migration to be idempotent

refs https://github.com/TryGhost/Ghost/issues/10318

- Previous version of migration was not following the idempotence rule of migrations
This commit is contained in:
Naz 2021-02-17 16:17:07 +13:00 committed by naz
parent e0cc314f91
commit abb8c1df74

View File

@ -2,6 +2,8 @@ const logging = require('../../../../../shared/logging');
const {createIrreversibleMigration} = require('../../utils');
module.exports = createIrreversibleMigration(async (knex) => {
logging.info('Updating unsplash setting value');
const unsplashSetting = await knex('settings')
.select('value')
.where({
@ -10,6 +12,12 @@ module.exports = createIrreversibleMigration(async (knex) => {
.first();
let isActive;
if (unsplashSetting && (unsplashSetting.value === 'true' || unsplashSetting.value === 'false')) {
logging.warn(`Skipping update of unsplash value. Current value is already boolean: ${unsplashSetting.value}`);
return;
}
try {
const value = JSON.parse(unsplashSetting.value);
isActive = typeof value.isActive === 'boolean' ? value.isActive : true;