generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
424 additions
and
46 deletions.
There are no files selected for viewing
46 changes: 44 additions & 2 deletions
46
database/mssql/scripts/sampledata/dbo.ORBC_POLICY_CONFIGURATION.Table.sql
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
database/mssql/scripts/versions/revert/v_51_ddl_revert.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
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 | ||
|
||
-- Remove the indexes on the new columns | ||
IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'IX_ORBC_POLICY_CONFIGURATION_UQ_IS_PRIMARY_DRAFT') | ||
DROP INDEX IX_ORBC_POLICY_CONFIGURATION_UQ_IS_PRIMARY_DRAFT ON ORBC_POLICY_CONFIGURATION; | ||
IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'IX_FK_ORBC_POLICY_CONFIGURATION_ORIGIN_ID') | ||
DROP INDEX IX_FK_ORBC_POLICY_CONFIGURATION_ORIGIN_ID ON ORBC_POLICY_CONFIGURATION; | ||
IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'IX_ORBC_POLICY_CONFIGURATION_IS_DRAFT') | ||
DROP INDEX IX_ORBC_POLICY_CONFIGURATION_IS_DRAFT ON ORBC_POLICY_CONFIGURATION; | ||
IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'IX_ORBC_POLICY_CONFIGURATION_EFFECTIVE_DATE') | ||
DROP INDEX IX_ORBC_POLICY_CONFIGURATION_EFFECTIVE_DATE ON ORBC_POLICY_CONFIGURATION; | ||
GO | ||
|
||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
-- Drop the columns from main and history tables | ||
ALTER TABLE [dbo].[ORBC_POLICY_CONFIGURATION] | ||
DROP CONSTRAINT FK_ORBC_POLICY_CONFIGURATION_ORIGIN_ID | ||
ALTER TABLE [dbo].[ORBC_POLICY_CONFIGURATION] | ||
DROP COLUMN ORIGIN_ID | ||
ALTER TABLE [dbo].[ORBC_POLICY_CONFIGURATION] | ||
DROP COLUMN IS_PRIMARY_DRAFT | ||
GO | ||
|
||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
-- Revert the trigger changes to remove the added columns | ||
ALTER TRIGGER [dbo].[ORBC_POLCFG_A_S_IUD_TR] ON [dbo].[ORBC_POLICY_CONFIGURATION] FOR INSERT, UPDATE, DELETE AS | ||
SET NOCOUNT ON | ||
BEGIN TRY | ||
DECLARE @curr_date datetime; | ||
SET @curr_date = getutcdate(); | ||
IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) | ||
RETURN; | ||
|
||
-- historical | ||
IF EXISTS(SELECT * FROM deleted) | ||
update [dbo].[ORBC_POLICY_CONFIGURATION_HIST] set END_DATE_HIST = @curr_date where POLICY_CONFIGURATION_ID in (select POLICY_CONFIGURATION_ID from deleted) and END_DATE_HIST is null; | ||
|
||
IF EXISTS(SELECT * FROM inserted) | ||
insert into [dbo].[ORBC_POLICY_CONFIGURATION_HIST] ([POLICY_CONFIGURATION_ID], [EFFECTIVE_DATE], [IS_DRAFT], [CHANGE_DESCRIPTION], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], _POLICY_CONFIGURATION_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST) | ||
select [POLICY_CONFIGURATION_ID], [EFFECTIVE_DATE], [IS_DRAFT], [CHANGE_DESCRIPTION], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], (next value for [dbo].[ORBC_POLICY_CONFIGURATION_H_ID_SEQ]) as [_POLICY_CONFIGURATION_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted; | ||
|
||
END TRY | ||
BEGIN CATCH | ||
IF @@trancount > 0 ROLLBACK TRANSACTION | ||
EXEC orbc_error_handling | ||
END CATCH; | ||
GO | ||
|
||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
-- Remove the added policy configuration | ||
DELETE FROM [dbo].[ORBC_POLICY_CONFIGURATION] | ||
WHERE POLICY_CONFIGURATION_ID = (SELECT MAX(POLICY_CONFIGURATION_ID) FROM [dbo].[ORBC_POLICY_CONFIGURATION]) | ||
GO | ||
|
||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
DECLARE @VersionDescription VARCHAR(255) | ||
SET @VersionDescription = 'Reverting updates to policy configuration table for config versioning' | ||
|
||
INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (50, @VersionDescription, getutcdate()) | ||
GO | ||
|
||
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- Test that the ORIGIN_ID column has been created successfully | ||
SET NOCOUNT ON | ||
|
||
select COL_LENGTH('$(DB_NAME).[dbo].[ORBC_POLICY_CONFIGURATION]', 'ORIGIN_ID') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- Test that the IS_PRIMARY_DRAFT column has been created | ||
SET NOCOUNT ON | ||
|
||
select COL_LENGTH('$(DB_NAME).[dbo].[ORBC_POLICY_CONFIGURATION]', 'IS_PRIMARY_DRAFT') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- Test that the initial policy configuration has been inserted correctly | ||
SET NOCOUNT ON | ||
|
||
SELECT COUNT(*) FROM $(DB_NAME).[dbo].[ORBC_POLICY_CONFIGURATION] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
# Retrieve arguments | ||
source ${SCRIPT_DIR}/utility/getopt.sh | ||
USAGE="-u USER -p PASS -s SERVER -d DATABASE" | ||
parse_options "${USAGE}" ${@} | ||
|
||
# All database tests for database version 51 are run from this shell script. | ||
# TESTS_DIR variable set by the calling test-runner script. | ||
|
||
TEST_51_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_51_1_test.sql | xargs) | ||
if [[ $TEST_51_1_RESULT -eq 4 ]]; then | ||
echo "Test 51.1 passed: ORIGIN_ID column created successfully." | ||
else | ||
echo "******** Test 51.1 failed: ORIGIN_ID column not created successfully." | ||
fi | ||
|
||
TEST_51_2_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_51_2_test.sql | xargs) | ||
if [[ $TEST_51_2_RESULT -eq 1 ]]; then | ||
echo "Test 51.2 passed: IS_PRIMARY_DRAFT column created successfully." | ||
else | ||
echo "******** Test 51.2 failed: IS_PRIMARY_DRAFT column not created successfully." | ||
fi | ||
|
||
TEST_51_3_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_51_3_test.sql | xargs) | ||
if [[ $TEST_51_2_RESULT -eq 1 ]]; then | ||
echo "Test 51.3 passed: Initial policy configuration inserted correctly." | ||
else | ||
echo "******** Test 51.3 failed: Initial policy configuration not inserted correctly." | ||
fi |
Oops, something went wrong.