From 8f5d6ebf8c2d2b517827b08a2a71d5ec312127dc Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 14 Jul 2021 12:16:44 +0400 Subject: [PATCH] Removed use of deprecated new Error() syntax refs https://github.com/TryGhost/Ghost/commit/2f1123d6ca7894fc21499739f46f0ae5c9eda73a refs https://github.com/TryGhost/Ghost/commit/6f1a3e17749e878a379830f12672b266c15bc835 - The use of new Error() has been deprecated. Refactoring the migration to use `createIrreversibleMigration` made most sense to have central error handling for migration which are not meant to be reverted. --- .../3.0/14-remove-subscribers-flag.js | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/core/server/data/migrations/versions/3.0/14-remove-subscribers-flag.js b/core/server/data/migrations/versions/3.0/14-remove-subscribers-flag.js index 1ad4377829..a7bfc0a81d 100644 --- a/core/server/data/migrations/versions/3.0/14-remove-subscribers-flag.js +++ b/core/server/data/migrations/versions/3.0/14-remove-subscribers-flag.js @@ -1,28 +1,24 @@ const logging = require('@tryghost/logging'); +const {createIrreversibleMigration} = require('../../utils'); -module.exports = { - async up({connection}) { - let result = await connection('settings') - .where('key', '=', 'labs') - .select('value'); +module.exports = createIrreversibleMigration(async (knex) => { + let result = await knex('settings') + .where('key', '=', 'labs') + .select('value'); - if (!result || !result[0]) { - logging.warn(`Could not find labs setting`); - result = [{}]; - } - - const labs = JSON.parse(result[0].value); - - labs.members = !!labs.members || !!labs.subscribers; - - logging.info(`Updating labs setting removing subscribers (was ${labs.subscribers}) settings members to ${labs.members}`); - labs.subscribers = undefined; - - await connection('settings') - .where('key', '=', 'labs') - .update('value', JSON.stringify(labs)); - }, - async down() { - throw new Error(); + if (!result || !result[0]) { + logging.warn(`Could not find labs setting`); + result = [{}]; } -}; + + const labs = JSON.parse(result[0].value); + + labs.members = !!labs.members || !!labs.subscribers; + + logging.info(`Updating labs setting removing subscribers (was ${labs.subscribers}) settings members to ${labs.members}`); + labs.subscribers = undefined; + + await knex('settings') + .where('key', '=', 'labs') + .update('value', JSON.stringify(labs)); +});