Skip to content

Commit

Permalink
Amended Alter Down (#4572)
Browse files Browse the repository at this point in the history
* Amended Alter Down

* Rebuilt Alter Down
  • Loading branch information
dfilteau authored Jan 9, 2025
1 parent 4b3ba08 commit 497df80
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 497df80

Please sign in to comment.