From 8fc86ddf56d617a55a0eb8c7d4c17460f65328e5 Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Mon, 30 Dec 2024 15:58:53 -0500 Subject: [PATCH 1/4] CNDE-2043: fix interview key tables, remove unnecessary select from postprocessing sproc --- .../023-sp_d_interview_postprocessing-001.sql | 2 -- .../022-create_nrt_interview_key-001.sql | 24 +++++++++-------- .../022-create_nrt_interview_note_key-001.sql | 26 ++++++++++--------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/liquibase-service/src/main/resources/db/rdb_modern/routines/023-sp_d_interview_postprocessing-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/routines/023-sp_d_interview_postprocessing-001.sql index 0919b9ce..8b6c576c 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/routines/023-sp_d_interview_postprocessing-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/routines/023-sp_d_interview_postprocessing-001.sql @@ -243,8 +243,6 @@ BEGIN ' WHERE ix.D_INTERVIEW_KEY IS NOT NULL;'; - SELECT @Update_sql; - exec sp_executesql @Update_sql; diff --git a/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_key-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_key-001.sql index b1b9fc24..e918382b 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_key-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_key-001.sql @@ -1,13 +1,15 @@ -DROP TABLE IF EXISTS dbo.nrt_interview_key; +IF NOT EXISTS (SELECT 1 FROM sysobjects WHERE name = 'nrt_interview_key' and xtype = 'U') + BEGIN -CREATE TABLE dbo.nrt_interview_key ( - d_interview_key bigint IDENTITY(1,1) NOT NULL, - interview_uid bigint NULL -); + CREATE TABLE dbo.nrt_interview_key ( + d_interview_key bigint IDENTITY (1,1) NOT NULL, + interview_uid bigint NULL + ); + declare @max bigint; + select @max=max(d_interview_key)+1 from dbo.D_INTERVIEW ; + select @max; + if @max IS NULL --check when max is returned as null + SET @max = 2; -- default to 2, as default record with key = 1 is not stored in D_INTERVIEW + DBCC CHECKIDENT ('dbo.nrt_interview_key', RESEED, @max); -declare @max bigint; -select @max=max(D_INTERVIEW_KEY)+1 from dbo.D_INTERVIEW; -select @max; -if @max IS NULL --check when max is returned as null - SET @max = 1; -DBCC CHECKIDENT ('dbo.nrt_interview_key', RESEED, @max); \ No newline at end of file + END diff --git a/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_note_key-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_note_key-001.sql index c3f865f7..29e3e132 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_note_key-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_note_key-001.sql @@ -1,14 +1,16 @@ -DROP TABLE IF EXISTS dbo.nrt_interview_note_key; +IF NOT EXISTS (SELECT 1 FROM sysobjects WHERE name = 'nrt_interview_note_key' and xtype = 'U') + BEGIN -CREATE TABLE dbo.nrt_interview_note_key ( - d_interview_note_key bigint IDENTITY(1,1) NOT NULL, - d_interview_key bigint NOT NULL, - nbs_answer_uid bigint NULL -); + CREATE TABLE dbo.nrt_interview_note_key ( + d_interview_note_key bigint IDENTITY(1,1) NOT NULL, + d_interview_key bigint NOT NULL, + nbs_answer_uid bigint NULL + ); + declare @max bigint; + select @max=max(d_interview_note_key)+1 from dbo.D_INTERVIEW_NOTE ; + select @max; + if @max IS NULL --check when max is returned as null + SET @max = 2; -- default to 2, as default record with key = 1 is not stored in D_INTERVIEW_NOTE + DBCC CHECKIDENT ('dbo.nrt_interview_note_key', RESEED, @max); -declare @max bigint; -select @max=max(D_INTERVIEW_NOTE_KEY)+1 from dbo.D_INTERVIEW_NOTE; -select @max; -if @max IS NULL --check when max is returned as null - SET @max = 1; -DBCC CHECKIDENT ('dbo.nrt_interview_note_key', RESEED, @max); \ No newline at end of file + END \ No newline at end of file From 43f0f30de379785e18cca32dccf8288992f06dcb Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Mon, 30 Dec 2024 16:09:20 -0500 Subject: [PATCH 2/4] CNDE-2043: add comments --- .../db/rdb_modern/tables/022-create_nrt_interview_key-001.sql | 2 ++ .../rdb_modern/tables/022-create_nrt_interview_note_key-001.sql | 2 ++ 2 files changed, 4 insertions(+) diff --git a/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_key-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_key-001.sql index e918382b..4b7e3a86 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_key-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_key-001.sql @@ -1,3 +1,5 @@ +-- table is not dropped and recreated, as D_INTERVIEW_KEY does not retain the key-uid relationship + IF NOT EXISTS (SELECT 1 FROM sysobjects WHERE name = 'nrt_interview_key' and xtype = 'U') BEGIN diff --git a/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_note_key-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_note_key-001.sql index 29e3e132..563a8b8e 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_note_key-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/tables/022-create_nrt_interview_note_key-001.sql @@ -1,3 +1,5 @@ +-- table is not dropped and recreated so as to stay consistent with the design of nrt_interview_key + IF NOT EXISTS (SELECT 1 FROM sysobjects WHERE name = 'nrt_interview_note_key' and xtype = 'U') BEGIN From 4f55cde0416ef662b54a6041235a0f125146ebdc Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Thu, 2 Jan 2025 16:37:16 -0500 Subject: [PATCH 3/4] CNDE-2043: update db/upgrade --- .../tables/022-create_nrt_interview_key.sql | 26 +++++++++-------- .../022-create_nrt_interview_note_key.sql | 28 +++++++++++-------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/db/upgrade/rdb_modern/tables/022-create_nrt_interview_key.sql b/db/upgrade/rdb_modern/tables/022-create_nrt_interview_key.sql index b1b9fc24..4b7e3a86 100644 --- a/db/upgrade/rdb_modern/tables/022-create_nrt_interview_key.sql +++ b/db/upgrade/rdb_modern/tables/022-create_nrt_interview_key.sql @@ -1,13 +1,17 @@ -DROP TABLE IF EXISTS dbo.nrt_interview_key; +-- table is not dropped and recreated, as D_INTERVIEW_KEY does not retain the key-uid relationship -CREATE TABLE dbo.nrt_interview_key ( - d_interview_key bigint IDENTITY(1,1) NOT NULL, - interview_uid bigint NULL -); +IF NOT EXISTS (SELECT 1 FROM sysobjects WHERE name = 'nrt_interview_key' and xtype = 'U') + BEGIN -declare @max bigint; -select @max=max(D_INTERVIEW_KEY)+1 from dbo.D_INTERVIEW; -select @max; -if @max IS NULL --check when max is returned as null - SET @max = 1; -DBCC CHECKIDENT ('dbo.nrt_interview_key', RESEED, @max); \ No newline at end of file + CREATE TABLE dbo.nrt_interview_key ( + d_interview_key bigint IDENTITY (1,1) NOT NULL, + interview_uid bigint NULL + ); + declare @max bigint; + select @max=max(d_interview_key)+1 from dbo.D_INTERVIEW ; + select @max; + if @max IS NULL --check when max is returned as null + SET @max = 2; -- default to 2, as default record with key = 1 is not stored in D_INTERVIEW + DBCC CHECKIDENT ('dbo.nrt_interview_key', RESEED, @max); + + END diff --git a/db/upgrade/rdb_modern/tables/022-create_nrt_interview_note_key.sql b/db/upgrade/rdb_modern/tables/022-create_nrt_interview_note_key.sql index c3f865f7..563a8b8e 100644 --- a/db/upgrade/rdb_modern/tables/022-create_nrt_interview_note_key.sql +++ b/db/upgrade/rdb_modern/tables/022-create_nrt_interview_note_key.sql @@ -1,14 +1,18 @@ -DROP TABLE IF EXISTS dbo.nrt_interview_note_key; +-- table is not dropped and recreated so as to stay consistent with the design of nrt_interview_key -CREATE TABLE dbo.nrt_interview_note_key ( - d_interview_note_key bigint IDENTITY(1,1) NOT NULL, - d_interview_key bigint NOT NULL, - nbs_answer_uid bigint NULL -); +IF NOT EXISTS (SELECT 1 FROM sysobjects WHERE name = 'nrt_interview_note_key' and xtype = 'U') + BEGIN -declare @max bigint; -select @max=max(D_INTERVIEW_NOTE_KEY)+1 from dbo.D_INTERVIEW_NOTE; -select @max; -if @max IS NULL --check when max is returned as null - SET @max = 1; -DBCC CHECKIDENT ('dbo.nrt_interview_note_key', RESEED, @max); \ No newline at end of file + CREATE TABLE dbo.nrt_interview_note_key ( + d_interview_note_key bigint IDENTITY(1,1) NOT NULL, + d_interview_key bigint NOT NULL, + nbs_answer_uid bigint NULL + ); + declare @max bigint; + select @max=max(d_interview_note_key)+1 from dbo.D_INTERVIEW_NOTE ; + select @max; + if @max IS NULL --check when max is returned as null + SET @max = 2; -- default to 2, as default record with key = 1 is not stored in D_INTERVIEW_NOTE + DBCC CHECKIDENT ('dbo.nrt_interview_note_key', RESEED, @max); + + END \ No newline at end of file From 66648001733ee9b3108962d34f3dcac483705e11 Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Thu, 2 Jan 2025 16:38:52 -0500 Subject: [PATCH 4/4] CNDE-2043: db/upgrade update for routines --- .../rdb_modern/routines/022-sp_d_interview_postprocessing.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/db/upgrade/rdb_modern/routines/022-sp_d_interview_postprocessing.sql b/db/upgrade/rdb_modern/routines/022-sp_d_interview_postprocessing.sql index 0919b9ce..8b6c576c 100644 --- a/db/upgrade/rdb_modern/routines/022-sp_d_interview_postprocessing.sql +++ b/db/upgrade/rdb_modern/routines/022-sp_d_interview_postprocessing.sql @@ -243,8 +243,6 @@ BEGIN ' WHERE ix.D_INTERVIEW_KEY IS NOT NULL;'; - SELECT @Update_sql; - exec sp_executesql @Update_sql;