mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added a foreign key from webhooks to integrations
issue https://github.com/TryGhost/Team/issues/477
This commit is contained in:
parent
2d47ddb400
commit
e52dc87b7c
4 changed files with 38 additions and 21 deletions
|
@ -0,0 +1,16 @@
|
||||||
|
const logging = require('../../../../../shared/logging');
|
||||||
|
const {createIrreversibleMigration} = require('../../utils');
|
||||||
|
const {addForeign} = require('../../../schema/commands');
|
||||||
|
|
||||||
|
module.exports = createIrreversibleMigration(async (knex) => {
|
||||||
|
logging.info('Adding the webhooks to integrations foreign key');
|
||||||
|
|
||||||
|
await addForeign({
|
||||||
|
fromTable: 'webhooks',
|
||||||
|
fromColumn: 'integration_id',
|
||||||
|
toTable: 'integrations',
|
||||||
|
toColumn: 'id',
|
||||||
|
cascadeDelete: true,
|
||||||
|
transaction: knex
|
||||||
|
});
|
||||||
|
});
|
|
@ -258,25 +258,6 @@ module.exports = {
|
||||||
lifetime: {type: 'bigInteger'},
|
lifetime: {type: 'bigInteger'},
|
||||||
count: {type: 'integer'}
|
count: {type: 'integer'}
|
||||||
},
|
},
|
||||||
webhooks: {
|
|
||||||
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
|
||||||
event: {type: 'string', maxlength: 50, nullable: false, validations: {isLowercase: true}},
|
|
||||||
target_url: {type: 'string', maxlength: 2000, nullable: false},
|
|
||||||
name: {type: 'string', maxlength: 191, nullable: true},
|
|
||||||
secret: {type: 'string', maxlength: 191, nullable: true},
|
|
||||||
// NOTE: the defaultTo does not make sense to set on DB layer as it leads to unnecessary maintenance every major release
|
|
||||||
// it might make sense to introduce "isIn" validation checking if it's a valid version e.g: 'v3', 'v4', 'canary'
|
|
||||||
api_version: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'v2'},
|
|
||||||
integration_id: {type: 'string', maxlength: 24, nullable: true},
|
|
||||||
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'available'},
|
|
||||||
last_triggered_at: {type: 'dateTime', nullable: true},
|
|
||||||
last_triggered_status: {type: 'string', maxlength: 50, nullable: true},
|
|
||||||
last_triggered_error: {type: 'string', maxlength: 50, nullable: true},
|
|
||||||
created_at: {type: 'dateTime', nullable: false},
|
|
||||||
created_by: {type: 'string', maxlength: 24, nullable: false},
|
|
||||||
updated_at: {type: 'dateTime', nullable: true},
|
|
||||||
updated_by: {type: 'string', maxlength: 24, nullable: true}
|
|
||||||
},
|
|
||||||
sessions: {
|
sessions: {
|
||||||
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
||||||
session_id: {type: 'string', maxlength: 32, nullable: false, unique: true},
|
session_id: {type: 'string', maxlength: 32, nullable: false, unique: true},
|
||||||
|
@ -303,6 +284,25 @@ module.exports = {
|
||||||
updated_at: {type: 'dateTime', nullable: true},
|
updated_at: {type: 'dateTime', nullable: true},
|
||||||
updated_by: {type: 'string', maxlength: 24, nullable: true}
|
updated_by: {type: 'string', maxlength: 24, nullable: true}
|
||||||
},
|
},
|
||||||
|
webhooks: {
|
||||||
|
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
||||||
|
event: {type: 'string', maxlength: 50, nullable: false, validations: {isLowercase: true}},
|
||||||
|
target_url: {type: 'string', maxlength: 2000, nullable: false},
|
||||||
|
name: {type: 'string', maxlength: 191, nullable: true},
|
||||||
|
secret: {type: 'string', maxlength: 191, nullable: true},
|
||||||
|
// NOTE: the defaultTo does not make sense to set on DB layer as it leads to unnecessary maintenance every major release
|
||||||
|
// it might make sense to introduce "isIn" validation checking if it's a valid version e.g: 'v3', 'v4', 'canary'
|
||||||
|
api_version: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'v2'},
|
||||||
|
integration_id: {type: 'string', maxlength: 24, nullable: false, references: 'integrations.id', cascadeDelete: true},
|
||||||
|
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'available'},
|
||||||
|
last_triggered_at: {type: 'dateTime', nullable: true},
|
||||||
|
last_triggered_status: {type: 'string', maxlength: 50, nullable: true},
|
||||||
|
last_triggered_error: {type: 'string', maxlength: 50, nullable: true},
|
||||||
|
created_at: {type: 'dateTime', nullable: false},
|
||||||
|
created_by: {type: 'string', maxlength: 24, nullable: false},
|
||||||
|
updated_at: {type: 'dateTime', nullable: true},
|
||||||
|
updated_by: {type: 'string', maxlength: 24, nullable: true}
|
||||||
|
},
|
||||||
api_keys: {
|
api_keys: {
|
||||||
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
||||||
type: {
|
type: {
|
||||||
|
|
|
@ -32,7 +32,7 @@ const defaultSettings = require('../../../../core/server/data/schema/default-set
|
||||||
*/
|
*/
|
||||||
describe('DB version integrity', function () {
|
describe('DB version integrity', function () {
|
||||||
// Only these variables should need updating
|
// Only these variables should need updating
|
||||||
const currentSchemaHash = 'd44979f33e39fafd9e1e25dd48e0d5d2';
|
const currentSchemaHash = '559cdbb49a7eeb5758caf0c6e3bf790d';
|
||||||
const currentFixturesHash = '370d0da0ab7c45050b2ff30bce8896ba';
|
const currentFixturesHash = '370d0da0ab7c45050b2ff30bce8896ba';
|
||||||
const currentSettingsHash = 'e1f85186a7c7ed76064b6026f68c6321';
|
const currentSettingsHash = 'e1f85186a7c7ed76064b6026f68c6321';
|
||||||
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
||||||
|
|
|
@ -114,8 +114,9 @@ describe('Validation', function () {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err.length.should.eql(1);
|
err.length.should.eql(2);
|
||||||
err[0].errorType.should.eql('ValidationError');
|
err[0].errorType.should.eql('ValidationError');
|
||||||
|
err[1].errorType.should.eql('ValidationError');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue