From ee792305881d2757bf951c2e597f0124ed6a994e Mon Sep 17 00:00:00 2001 From: John Fletcher <113134542+john-fletcher-aot@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:23:53 -0800 Subject: [PATCH] fix: Add index on permit history table (#1670) --- .../versions/revert/v_49_ddl_revert.sql | 41 +++++++++++++++++ database/mssql/scripts/versions/v_49_ddl.sql | 45 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 database/mssql/scripts/versions/revert/v_49_ddl_revert.sql create mode 100644 database/mssql/scripts/versions/v_49_ddl.sql diff --git a/database/mssql/scripts/versions/revert/v_49_ddl_revert.sql b/database/mssql/scripts/versions/revert/v_49_ddl_revert.sql new file mode 100644 index 000000000..d5f61086c --- /dev/null +++ b/database/mssql/scripts/versions/revert/v_49_ddl_revert.sql @@ -0,0 +1,41 @@ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +SET NOCOUNT ON +GO + +SET XACT_ABORT ON +GO +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE +GO +BEGIN TRANSACTION +GO + +DROP INDEX [permit].[ORBC_PERMIT_HIST].[ORBC_PERMIT_H_ID_ENDDATE_IX] + + +IF @@ERROR <> 0 SET NOEXEC ON +GO + +DECLARE @VersionDescription VARCHAR(255) +SET @VersionDescription = 'Reverting adding index to permit history table' + +INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (48, @VersionDescription, getutcdate()) + +IF @@ERROR <> 0 SET NOEXEC ON +GO + +COMMIT TRANSACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO +DECLARE @Success AS BIT +SET @Success = 1 +SET NOEXEC OFF +IF (@Success = 1) PRINT 'The database revert succeeded' +ELSE BEGIN + IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION + PRINT 'The database revert failed' +END +GO \ No newline at end of file diff --git a/database/mssql/scripts/versions/v_49_ddl.sql b/database/mssql/scripts/versions/v_49_ddl.sql new file mode 100644 index 000000000..9c6b849ad --- /dev/null +++ b/database/mssql/scripts/versions/v_49_ddl.sql @@ -0,0 +1,45 @@ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +SET NOCOUNT ON +GO + +SET XACT_ABORT ON +GO +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE +GO +BEGIN TRANSACTION +GO + +CREATE NONCLUSTERED INDEX [ORBC_PERMIT_H_ID_ENDDATE_IX] ON [permit].[ORBC_PERMIT_HIST] +( + [END_DATE_HIST] ASC, + [ID] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +GO + + +IF @@ERROR <> 0 SET NOEXEC ON +GO + +DECLARE @VersionDescription VARCHAR(255) +SET @VersionDescription = 'Add index to permit history table to resolve deadlocks' + +INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (49, @VersionDescription, '$(UPDATE_SCRIPT)', '$(REVERT_SCRIPT)', getutcdate()) +IF @@ERROR <> 0 SET NOEXEC ON +GO + +COMMIT TRANSACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO +DECLARE @Success AS BIT +SET @Success = 1 +SET NOEXEC OFF +IF (@Success = 1) PRINT 'The database update succeeded' +ELSE BEGIN + IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION + PRINT 'The database update failed' +END +GO