mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
🏗 Updated "slack" setting into "slack_{url,username}"
refs https://github.com/TryGhost/Ghost/issues/10318 - Object format used in previous "slack" setting was considered an anti-pattern. Flag structure of separate slack_url and slack_username values was extracted out of the "slack" JSON.
This commit is contained in:
parent
aae2e68a1d
commit
12c28fe66e
3 changed files with 72 additions and 4 deletions
|
@ -0,0 +1,64 @@
|
|||
const ObjectId = require('bson-objectid').default;
|
||||
const {createIrreversibleMigration} = require('../../utils');
|
||||
|
||||
module.exports = createIrreversibleMigration(async (knex) => {
|
||||
const slackSetting = await knex('settings')
|
||||
.select('value')
|
||||
.where({
|
||||
key: 'slack'
|
||||
})
|
||||
.first();
|
||||
|
||||
let slackUrl = '';
|
||||
let slackUsername = '';
|
||||
try {
|
||||
// example value that used to be stored in here:
|
||||
// value: [{
|
||||
// "url":"https://hooks.slack.com/services/TC_REDACTED/B01_REDACTED/mk_REDACTED",
|
||||
// "username":"Ghost"
|
||||
// }]
|
||||
const value = JSON.parse(slackSetting.value)[0];
|
||||
|
||||
slackUrl = value.url;
|
||||
slackUsername = value.username;
|
||||
} catch (err) {
|
||||
slackUrl = '';
|
||||
slackUsername = 'Ghost';
|
||||
}
|
||||
|
||||
const now = knex.raw('CURRENT_TIMESTAMP');
|
||||
|
||||
await knex('settings')
|
||||
.insert({
|
||||
id: ObjectId.generate(),
|
||||
key: 'slack_url',
|
||||
group: 'slack',
|
||||
type: 'string',
|
||||
flags: null,
|
||||
value: slackUrl,
|
||||
created_by: 1,
|
||||
created_at: now,
|
||||
updated_by: 1,
|
||||
updated_at: now
|
||||
});
|
||||
|
||||
await knex('settings')
|
||||
.insert({
|
||||
id: ObjectId.generate(),
|
||||
key: 'slack_username',
|
||||
group: 'slack',
|
||||
type: 'string',
|
||||
flags: null,
|
||||
value: slackUsername,
|
||||
created_by: 1,
|
||||
created_at: now,
|
||||
updated_by: 1,
|
||||
updated_at: now
|
||||
});
|
||||
|
||||
await knex('settings')
|
||||
.where({
|
||||
key: 'slack'
|
||||
})
|
||||
.del();
|
||||
});
|
|
@ -401,9 +401,13 @@
|
|||
}
|
||||
},
|
||||
"slack": {
|
||||
"slack": {
|
||||
"defaultValue": "[{\"url\":\"\", \"username\":\"Ghost\"}]",
|
||||
"type": "array"
|
||||
"slack_url": {
|
||||
"defaultValue": "",
|
||||
"type": "string"
|
||||
},
|
||||
"slack_username": {
|
||||
"defaultValue": "Ghost",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"unsplash": {
|
||||
|
|
|
@ -34,7 +34,7 @@ describe('DB version integrity', function () {
|
|||
// Only these variables should need updating
|
||||
const currentSchemaHash = '3f88f2c34001cc34d74d945dbf4f0bb5';
|
||||
const currentFixturesHash = '370d0da0ab7c45050b2ff30bce8896ba';
|
||||
const currentSettingsHash = '162f9294cc427eb32bc0577006c385ce';
|
||||
const currentSettingsHash = '24453dc02be9df7284acf1748862a545';
|
||||
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
||||
|
||||
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
|
||||
|
|
Loading…
Add table
Reference in a new issue