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; 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 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..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,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/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..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,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