From fcc64014452622b8a92b08c444238102035129a9 Mon Sep 17 00:00:00 2001 From: naz Date: Mon, 7 Sep 2020 21:54:55 +1200 Subject: [PATCH] Added routes_hash setting (#12171) refs #11999 - The `routes_hash` setting will be used during the boot process to update the hash of currently loaded routes.yaml file in case it's different from last restart --- .../3.32/03-add-routes-hash-setting.js | 20 +++++++++++++++++++ core/server/data/schema/default-settings.json | 4 ++++ test/regression/settings/settings_spec.js | 5 +++-- test/unit/data/schema/integrity_spec.js | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 core/server/data/migrations/versions/3.32/03-add-routes-hash-setting.js diff --git a/core/server/data/migrations/versions/3.32/03-add-routes-hash-setting.js b/core/server/data/migrations/versions/3.32/03-add-routes-hash-setting.js new file mode 100644 index 0000000000..c1d51d881c --- /dev/null +++ b/core/server/data/migrations/versions/3.32/03-add-routes-hash-setting.js @@ -0,0 +1,20 @@ +const logging = require('../../../../../shared/logging'); +module.exports = { + config: { + transaction: true + }, + + async up({transacting: knex}) { + logging.info('Updating routes_hash to group: core, type: string, flags: null'); + + await knex('settings') + .update({ + group: 'core', + type: 'string', + flags: null + }) + .where('key', 'routes_hash'); + }, + + async down() {} +}; diff --git a/core/server/data/schema/default-settings.json b/core/server/data/schema/default-settings.json index 50f3615f49..1a4c34d60e 100644 --- a/core/server/data/schema/default-settings.json +++ b/core/server/data/schema/default-settings.json @@ -4,6 +4,10 @@ "defaultValue": null, "type": "string" }, + "routes_hash": { + "defaultValue": null, + "type": "string" + }, "next_update_check": { "defaultValue": null, "type": "number" diff --git a/test/regression/settings/settings_spec.js b/test/regression/settings/settings_spec.js index a8c13be6d2..06878a173e 100644 --- a/test/regression/settings/settings_spec.js +++ b/test/regression/settings/settings_spec.js @@ -15,9 +15,10 @@ describe('Settings', function () { return testUtils.startGhost(); }); - // Whitelist: Only this list needs updating when a core setting is added/removed/renamed + // Allowlist: Only this list needs updating when a core setting is added/removed/renamed const coreSettingKeys = [ 'db_hash', + 'routes_hash', 'next_update_check', 'notifications', 'session_secret', @@ -31,7 +32,7 @@ describe('Settings', function () { 'members_stripe_webhook_secret' ]; // If this test is failing, then it is likely a new setting has been added without group migration - // In case of `core` setting modifications, whitelist above needs to be updated + // In case of `core` setting modifications, allowlist above needs to be updated it('should not modify core keys without fixing this test', function () { return db.knex('settings') .where('group', 'core') diff --git a/test/unit/data/schema/integrity_spec.js b/test/unit/data/schema/integrity_spec.js index c08a105809..4c0174d0ed 100644 --- a/test/unit/data/schema/integrity_spec.js +++ b/test/unit/data/schema/integrity_spec.js @@ -23,7 +23,7 @@ describe('DB version integrity', function () { // Only these variables should need updating const currentSchemaHash = '42a966364eb4b5851e807133374821da'; const currentFixturesHash = '29148c40dfaf4f828c5fca95666f6545'; - const currentSettingsHash = 'a079e294592f6effe0738e671d053e20'; + const currentSettingsHash = 'c8daa2c9632bb75f9d60655de09ae3bd'; // If this test is failing, then it is likely a change has been made that requires a DB version bump, // and the values above will need updating as confirmation