mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
🏗 Updated "unsplash" setting handling to match updated format
refs https://github.com/TryGhost/Ghost/issues/10318 - JSON object format used in previous "unsplash" setting was considered an anti-pattern. Flat structure was extracted out of the "unsplash.isActive" JSON. - The naming convention uses `amp` as a precedent (https://github.com/TryGhost/Team/issues/331#issuecomment-658815017)
This commit is contained in:
parent
0097f2037c
commit
9cb069eb8e
@ -0,0 +1,29 @@
|
||||
const {createIrreversibleMigration} = require('../../utils');
|
||||
|
||||
module.exports = createIrreversibleMigration(async (knex) => {
|
||||
const unsplashSetting = await knex('settings')
|
||||
.select('value')
|
||||
.where({
|
||||
key: 'unsplash'
|
||||
})
|
||||
.first();
|
||||
|
||||
let isActive;
|
||||
try {
|
||||
const value = JSON.parse(unsplashSetting.value);
|
||||
isActive = typeof value.isActive === 'boolean' ? value.isActive : true;
|
||||
} catch (err) {
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
await knex('settings')
|
||||
.update({
|
||||
group: 'unsplash',
|
||||
type: 'boolean',
|
||||
flags: null,
|
||||
value: isActive.toString()
|
||||
})
|
||||
.where({
|
||||
key: 'unsplash'
|
||||
});
|
||||
});
|
@ -0,0 +1,33 @@
|
||||
const logging = require('../../../../../shared/logging');
|
||||
const {createIrreversibleMigration} = require('../../utils');
|
||||
|
||||
module.exports = createIrreversibleMigration(async (knex) => {
|
||||
const unsplashSetting = await knex('settings')
|
||||
.select('value')
|
||||
.where({
|
||||
key: 'unsplash'
|
||||
})
|
||||
.first();
|
||||
|
||||
let isActive;
|
||||
try {
|
||||
const value = JSON.parse(unsplashSetting.value);
|
||||
isActive = typeof value.isActive === 'boolean' ? value.isActive : true;
|
||||
} catch (err) {
|
||||
logging.warn(`Wasn't able to parse 'unsplash' setting: ${unsplashSetting.value}, falling back to: 'true'`);
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
logging.info(`Updating 'unsplash' setting to: ${isActive}`);
|
||||
|
||||
await knex('settings')
|
||||
.update({
|
||||
group: 'unsplash',
|
||||
type: 'boolean',
|
||||
flags: null,
|
||||
value: isActive.toString()
|
||||
})
|
||||
.where({
|
||||
key: 'unsplash'
|
||||
});
|
||||
});
|
@ -406,8 +406,12 @@
|
||||
},
|
||||
"unsplash": {
|
||||
"unsplash": {
|
||||
"defaultValue": "{\"isActive\": true}",
|
||||
"type": "object"
|
||||
"defaultValue": "true",
|
||||
"validations": {
|
||||
"isEmpty": false,
|
||||
"isIn": [["true", "false"]]
|
||||
},
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"views": {
|
||||
|
@ -34,7 +34,7 @@ describe('DB version integrity', function () {
|
||||
// Only these variables should need updating
|
||||
const currentSchemaHash = '5861ed57418a0195ea01e431b8b55335';
|
||||
const currentFixturesHash = '370d0da0ab7c45050b2ff30bce8896ba';
|
||||
const currentSettingsHash = '6db8d92f1b76b43946bf75fbac78599d';
|
||||
const currentSettingsHash = 'e1f85186a7c7ed76064b6026f68c6321';
|
||||
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
||||
|
||||
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
|
||||
|
Loading…
Reference in New Issue
Block a user