diff --git a/core/server/data/migrations/versions/4.0/28-add-webhook-intergrations-foreign-key.js b/core/server/data/migrations/versions/4.0/28-add-webhook-intergrations-foreign-key.js new file mode 100644 index 0000000000..7eb6f1c5fb --- /dev/null +++ b/core/server/data/migrations/versions/4.0/28-add-webhook-intergrations-foreign-key.js @@ -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 + }); +}); diff --git a/core/server/data/schema/schema.js b/core/server/data/schema/schema.js index d146fcbf42..ed5a9384b5 100644 --- a/core/server/data/schema/schema.js +++ b/core/server/data/schema/schema.js @@ -258,25 +258,6 @@ module.exports = { lifetime: {type: 'bigInteger'}, 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: { id: {type: 'string', maxlength: 24, nullable: false, primary: true}, session_id: {type: 'string', maxlength: 32, nullable: false, unique: true}, @@ -303,6 +284,25 @@ module.exports = { updated_at: {type: 'dateTime', 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: { id: {type: 'string', maxlength: 24, nullable: false, primary: true}, type: { diff --git a/test/unit/data/schema/integrity_spec.js b/test/unit/data/schema/integrity_spec.js index a9d3c82796..41dafd6aa8 100644 --- a/test/unit/data/schema/integrity_spec.js +++ b/test/unit/data/schema/integrity_spec.js @@ -32,7 +32,7 @@ const defaultSettings = require('../../../../core/server/data/schema/default-set */ describe('DB version integrity', function () { // Only these variables should need updating - const currentSchemaHash = 'd44979f33e39fafd9e1e25dd48e0d5d2'; + const currentSchemaHash = '559cdbb49a7eeb5758caf0c6e3bf790d'; const currentFixturesHash = '370d0da0ab7c45050b2ff30bce8896ba'; const currentSettingsHash = 'e1f85186a7c7ed76064b6026f68c6321'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; diff --git a/test/unit/data/validation/index_spec.js b/test/unit/data/validation/index_spec.js index 553e6ee9b0..6c7de56c39 100644 --- a/test/unit/data/validation/index_spec.js +++ b/test/unit/data/validation/index_spec.js @@ -114,8 +114,9 @@ describe('Validation', function () { throw err; } - err.length.should.eql(1); + err.length.should.eql(2); err[0].errorType.should.eql('ValidationError'); + err[1].errorType.should.eql('ValidationError'); }); }); });