diff --git a/source/database/mssql/scripts/dbscripts/PSP_PIMS_LATEST/Alter Down/002_PSP_PIMS_Alter_Down.sql b/source/database/mssql/scripts/dbscripts/PSP_PIMS_LATEST/Alter Down/002_PSP_PIMS_Alter_Down.sql index a968fbd14a..ff108f8cf7 100644 --- a/source/database/mssql/scripts/dbscripts/PSP_PIMS_LATEST/Alter Down/002_PSP_PIMS_Alter_Down.sql +++ b/source/database/mssql/scripts/dbscripts/PSP_PIMS_LATEST/Alter Down/002_PSP_PIMS_Alter_Down.sql @@ -470,6 +470,25 @@ ALTER TABLE [dbo].[PIMS_DOCUMENT_QUEUE] [DISPOSITION_FILE_DOCUMENT_ID] bigint NULL, [FILE_NAME] nvarchar(500) NOT NULL DEFAULT ' ' GO + +-- Drop dynamically-named default constraint +PRINT N'Drop dynamically-named default constraint' +GO +DECLARE @sqlQry VARCHAR(1000) +DECLARE @defName VARCHAR(100) +SET @defName = (SELECT obj.NAME + FROM SYSOBJECTS obj INNER JOIN + SYSCOLUMNS col on obj.ID = col.CDEFAULT INNER JOIN + SYSOBJECTS tbl on col.ID = tbl.ID + WHERE obj.XTYPE = 'D' + AND tbl.NAME = 'PIMS_DOCUMENT_QUEUE' + AND col.NAME = 'FILE_NAME') +SET @sqlQry = 'ALTER TABLE [dbo].[PIMS_DOCUMENT_QUEUE] DROP CONSTRAINT IF EXISTS [' + @defName + ']' +EXEC (@sqlQry) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'Foreign key to the PIMS_PROPERTY_ACTIVITY_DOCUMENT table.' , @level0type = N'Schema', @level0name = N'dbo', @@ -532,6 +551,24 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Drop dynamically-named default constraint +PRINT N'Drop dynamically-named default constraint' +GO +DECLARE @sqlQry VARCHAR(1000) +DECLARE @defName VARCHAR(100) +SET @defName = (SELECT obj.NAME + FROM SYSOBJECTS obj INNER JOIN + SYSCOLUMNS col on obj.ID = col.CDEFAULT INNER JOIN + SYSOBJECTS tbl on col.ID = tbl.ID + WHERE obj.XTYPE = 'D' + AND tbl.NAME = 'PIMS_DOCUMENT_QUEUE_HIST' + AND col.NAME = 'FILE_NAME') +SET @sqlQry = 'ALTER TABLE [dbo].[PIMS_DOCUMENT_QUEUE_HIST] DROP CONSTRAINT IF EXISTS [' + @defName + ']' +EXEC (@sqlQry) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Alter table dbo.PIMS_PROPERTY PRINT N'Alter table dbo.PIMS_PROPERTY' GO @@ -547,11 +584,41 @@ GO -- Alter table dbo.PIMS_PROJECT_PERSON PRINT N'Alter table dbo.PIMS_PROJECT_PERSON' GO +UPDATE [dbo].[PIMS_PROJECT_PERSON] +SET PROJECT_PERSON_ROLE_TYPE_CODE = N'PROJMGR' + , CONCURRENCY_CONTROL_NUMBER = CONCURRENCY_CONTROL_NUMBER + 1 +WHERE PROJECT_PERSON_ROLE_TYPE_CODE IS NULL +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO +ALTER TABLE [dbo].[PIMS_PROJECT_PERSON] + ADD DEFAULT 'PROJMGR' FOR PROJECT_PERSON_ROLE_TYPE_CODE +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO ALTER TABLE [dbo].[PIMS_PROJECT_PERSON] ALTER COLUMN [PROJECT_PERSON_ROLE_TYPE_CODE] nvarchar(20) NOT NULL GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Drop dynamically-named default constraint +PRINT N'Drop dynamically-named default constraint' +GO +DECLARE @sqlQry VARCHAR(1000) +DECLARE @defName VARCHAR(100) +SET @defName = (SELECT obj.NAME + FROM SYSOBJECTS obj INNER JOIN + SYSCOLUMNS col on obj.ID = col.CDEFAULT INNER JOIN + SYSOBJECTS tbl on col.ID = tbl.ID + WHERE obj.XTYPE = 'D' + AND tbl.NAME = 'PIMS_PROJECT_PERSON' + AND col.NAME = 'PROJECT_PERSON_ROLE_TYPE_CODE') +SET @sqlQry = 'ALTER TABLE [dbo].[PIMS_PROJECT_PERSON] DROP CONSTRAINT IF EXISTS [' + @defName + ']' +EXEC (@sqlQry) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Create unique constraint dbo.PRJPER_PROJECT_PERSON_TUC PRINT N'Create unique constraint dbo.PRJPER_PROJECT_PERSON_TUC' GO @@ -568,11 +635,36 @@ GO -- Alter table dbo.PIMS_PROJECT_PERSON_HIST PRINT N'Alter table dbo.PIMS_PROJECT_PERSON_HIST' GO +UPDATE [dbo].[PIMS_PROJECT_PERSON_HIST] +SET PROJECT_PERSON_ROLE_TYPE_CODE = N'PROJMGR' + , CONCURRENCY_CONTROL_NUMBER = CONCURRENCY_CONTROL_NUMBER + 1 +WHERE PROJECT_PERSON_ROLE_TYPE_CODE IS NULL +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO ALTER TABLE [dbo].[PIMS_PROJECT_PERSON_HIST] ALTER COLUMN [PROJECT_PERSON_ROLE_TYPE_CODE] nvarchar(20) NOT NULL GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Drop dynamically-named default constraint +PRINT N'Drop dynamically-named default constraint' +GO +DECLARE @sqlQry VARCHAR(1000) +DECLARE @defName VARCHAR(100) +SET @defName = (SELECT obj.NAME + FROM SYSOBJECTS obj INNER JOIN + SYSCOLUMNS col on obj.ID = col.CDEFAULT INNER JOIN + SYSOBJECTS tbl on col.ID = tbl.ID + WHERE obj.XTYPE = 'D' + AND tbl.NAME = 'PIMS_PROJECT_PERSON_HIST' + AND col.NAME = 'PROJECT_PERSON_ROLE_TYPE_CODE') +SET @sqlQry = 'ALTER TABLE [dbo].[PIMS_PROJECT_PERSON_HIST] DROP CONSTRAINT IF EXISTS [' + @defName + ']' +EXEC (@sqlQry) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Alter table dbo.PIMS_ACQ_CHKLST_SECTION_TYPE PRINT N'Alter table dbo.PIMS_ACQ_CHKLST_SECTION_TYPE' GO diff --git a/source/database/mssql/scripts/dbscripts/PSP_PIMS_S96_00/Alter Down/002_PSP_PIMS_Alter_Down.sql b/source/database/mssql/scripts/dbscripts/PSP_PIMS_S96_00/Alter Down/002_PSP_PIMS_Alter_Down.sql index a968fbd14a..ff108f8cf7 100644 --- a/source/database/mssql/scripts/dbscripts/PSP_PIMS_S96_00/Alter Down/002_PSP_PIMS_Alter_Down.sql +++ b/source/database/mssql/scripts/dbscripts/PSP_PIMS_S96_00/Alter Down/002_PSP_PIMS_Alter_Down.sql @@ -470,6 +470,25 @@ ALTER TABLE [dbo].[PIMS_DOCUMENT_QUEUE] [DISPOSITION_FILE_DOCUMENT_ID] bigint NULL, [FILE_NAME] nvarchar(500) NOT NULL DEFAULT ' ' GO + +-- Drop dynamically-named default constraint +PRINT N'Drop dynamically-named default constraint' +GO +DECLARE @sqlQry VARCHAR(1000) +DECLARE @defName VARCHAR(100) +SET @defName = (SELECT obj.NAME + FROM SYSOBJECTS obj INNER JOIN + SYSCOLUMNS col on obj.ID = col.CDEFAULT INNER JOIN + SYSOBJECTS tbl on col.ID = tbl.ID + WHERE obj.XTYPE = 'D' + AND tbl.NAME = 'PIMS_DOCUMENT_QUEUE' + AND col.NAME = 'FILE_NAME') +SET @sqlQry = 'ALTER TABLE [dbo].[PIMS_DOCUMENT_QUEUE] DROP CONSTRAINT IF EXISTS [' + @defName + ']' +EXEC (@sqlQry) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'Foreign key to the PIMS_PROPERTY_ACTIVITY_DOCUMENT table.' , @level0type = N'Schema', @level0name = N'dbo', @@ -532,6 +551,24 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Drop dynamically-named default constraint +PRINT N'Drop dynamically-named default constraint' +GO +DECLARE @sqlQry VARCHAR(1000) +DECLARE @defName VARCHAR(100) +SET @defName = (SELECT obj.NAME + FROM SYSOBJECTS obj INNER JOIN + SYSCOLUMNS col on obj.ID = col.CDEFAULT INNER JOIN + SYSOBJECTS tbl on col.ID = tbl.ID + WHERE obj.XTYPE = 'D' + AND tbl.NAME = 'PIMS_DOCUMENT_QUEUE_HIST' + AND col.NAME = 'FILE_NAME') +SET @sqlQry = 'ALTER TABLE [dbo].[PIMS_DOCUMENT_QUEUE_HIST] DROP CONSTRAINT IF EXISTS [' + @defName + ']' +EXEC (@sqlQry) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Alter table dbo.PIMS_PROPERTY PRINT N'Alter table dbo.PIMS_PROPERTY' GO @@ -547,11 +584,41 @@ GO -- Alter table dbo.PIMS_PROJECT_PERSON PRINT N'Alter table dbo.PIMS_PROJECT_PERSON' GO +UPDATE [dbo].[PIMS_PROJECT_PERSON] +SET PROJECT_PERSON_ROLE_TYPE_CODE = N'PROJMGR' + , CONCURRENCY_CONTROL_NUMBER = CONCURRENCY_CONTROL_NUMBER + 1 +WHERE PROJECT_PERSON_ROLE_TYPE_CODE IS NULL +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO +ALTER TABLE [dbo].[PIMS_PROJECT_PERSON] + ADD DEFAULT 'PROJMGR' FOR PROJECT_PERSON_ROLE_TYPE_CODE +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO ALTER TABLE [dbo].[PIMS_PROJECT_PERSON] ALTER COLUMN [PROJECT_PERSON_ROLE_TYPE_CODE] nvarchar(20) NOT NULL GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Drop dynamically-named default constraint +PRINT N'Drop dynamically-named default constraint' +GO +DECLARE @sqlQry VARCHAR(1000) +DECLARE @defName VARCHAR(100) +SET @defName = (SELECT obj.NAME + FROM SYSOBJECTS obj INNER JOIN + SYSCOLUMNS col on obj.ID = col.CDEFAULT INNER JOIN + SYSOBJECTS tbl on col.ID = tbl.ID + WHERE obj.XTYPE = 'D' + AND tbl.NAME = 'PIMS_PROJECT_PERSON' + AND col.NAME = 'PROJECT_PERSON_ROLE_TYPE_CODE') +SET @sqlQry = 'ALTER TABLE [dbo].[PIMS_PROJECT_PERSON] DROP CONSTRAINT IF EXISTS [' + @defName + ']' +EXEC (@sqlQry) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Create unique constraint dbo.PRJPER_PROJECT_PERSON_TUC PRINT N'Create unique constraint dbo.PRJPER_PROJECT_PERSON_TUC' GO @@ -568,11 +635,36 @@ GO -- Alter table dbo.PIMS_PROJECT_PERSON_HIST PRINT N'Alter table dbo.PIMS_PROJECT_PERSON_HIST' GO +UPDATE [dbo].[PIMS_PROJECT_PERSON_HIST] +SET PROJECT_PERSON_ROLE_TYPE_CODE = N'PROJMGR' + , CONCURRENCY_CONTROL_NUMBER = CONCURRENCY_CONTROL_NUMBER + 1 +WHERE PROJECT_PERSON_ROLE_TYPE_CODE IS NULL +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO ALTER TABLE [dbo].[PIMS_PROJECT_PERSON_HIST] ALTER COLUMN [PROJECT_PERSON_ROLE_TYPE_CODE] nvarchar(20) NOT NULL GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Drop dynamically-named default constraint +PRINT N'Drop dynamically-named default constraint' +GO +DECLARE @sqlQry VARCHAR(1000) +DECLARE @defName VARCHAR(100) +SET @defName = (SELECT obj.NAME + FROM SYSOBJECTS obj INNER JOIN + SYSCOLUMNS col on obj.ID = col.CDEFAULT INNER JOIN + SYSOBJECTS tbl on col.ID = tbl.ID + WHERE obj.XTYPE = 'D' + AND tbl.NAME = 'PIMS_PROJECT_PERSON_HIST' + AND col.NAME = 'PROJECT_PERSON_ROLE_TYPE_CODE') +SET @sqlQry = 'ALTER TABLE [dbo].[PIMS_PROJECT_PERSON_HIST] DROP CONSTRAINT IF EXISTS [' + @defName + ']' +EXEC (@sqlQry) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Alter table dbo.PIMS_ACQ_CHKLST_SECTION_TYPE PRINT N'Alter table dbo.PIMS_ACQ_CHKLST_SECTION_TYPE' GO