From d6c7bf0f2835e006116ff24b7b3634cb434a2faf Mon Sep 17 00:00:00 2001 From: Matt Bishop Date: Thu, 3 Apr 2025 16:44:19 -0400 Subject: [PATCH] Use check --- .../2025-04-03_00_OrganizationIntegrationCUD.sql | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/util/Migrator/DbScripts/2025-04-03_00_OrganizationIntegrationCUD.sql b/util/Migrator/DbScripts/2025-04-03_00_OrganizationIntegrationCUD.sql index dc2336730a..bbdbf0f138 100644 --- a/util/Migrator/DbScripts/2025-04-03_00_OrganizationIntegrationCUD.sql +++ b/util/Migrator/DbScripts/2025-04-03_00_OrganizationIntegrationCUD.sql @@ -1,6 +1,12 @@ -- Configure FK to cascade on delete -ALTER TABLE [dbo].[OrganizationIntegrationConfiguration] DROP FK_OrganizationIntegrationConfiguration_OrganizationIntegration; -ALTER TABLE [dbo].[OrganizationIntegrationConfiguration] ADD CONSTRAINT [FK_OrganizationIntegrationConfiguration_OrganizationIntegration] FOREIGN KEY ([OrganizationIntegrationId]) REFERENCES [dbo].[OrganizationIntegration] ([Id]) ON DELETE CASCADE; +IF EXISTS(SELECT * +FROM information_schema.table_constraints +WHERE table_name='OrganizationIntegrationConfiguration' + AND constraint_name='FK_OrganizationIntegrationConfiguration_OrganizationIntegration') +BEGIN + ALTER TABLE [dbo].[OrganizationIntegrationConfiguration] DROP FK_OrganizationIntegrationConfiguration_OrganizationIntegration; + ALTER TABLE [dbo].[OrganizationIntegrationConfiguration] ADD CONSTRAINT [FK_OrganizationIntegrationConfiguration_OrganizationIntegration] FOREIGN KEY ([OrganizationIntegrationId]) REFERENCES [dbo].[OrganizationIntegration] ([Id]) ON DELETE CASCADE; +END GO CREATE OR ALTER PROCEDURE [dbo].[OrganizationIntegration_Create]