Skip to content

Commit

Permalink
Merge branch 'main' into ORV2-3201
Browse files Browse the repository at this point in the history
  • Loading branch information
glen-aot authored Dec 16, 2024
2 parents 77c9988 + 2f55b2b commit 7268d30
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 46 deletions.

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions database/mssql/scripts/utility/refresh-sample-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ USAGE="-u ORBC_USER -p ORBC_PASS -s ORBC_SERVER -d ORBC_DATABASE"
parse_options "${USAGE}" ${@}

echo "Deleting existing sample data"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_FEATURE_FLAG"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_TRAILER"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_POWER_UNIT"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_COMPANY_USER"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_USER"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_COMPANY"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_CONTACT"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_ADDRESS"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET NOCOUNT ON; DELETE FROM dbo.ORBC_POLICY_CONFIGURATION"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET QUOTED_IDENTIFIER ON; SET NOCOUNT ON; DELETE FROM dbo.ORBC_FEATURE_FLAG"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET QUOTED_IDENTIFIER ON; SET NOCOUNT ON; DELETE FROM dbo.ORBC_TRAILER"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET QUOTED_IDENTIFIER ON; SET NOCOUNT ON; DELETE FROM dbo.ORBC_POWER_UNIT"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET QUOTED_IDENTIFIER ON; SET NOCOUNT ON; DELETE FROM dbo.ORBC_COMPANY_USER"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET QUOTED_IDENTIFIER ON; SET NOCOUNT ON; DELETE FROM dbo.ORBC_USER"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET QUOTED_IDENTIFIER ON; SET NOCOUNT ON; DELETE FROM dbo.ORBC_COMPANY"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET QUOTED_IDENTIFIER ON; SET NOCOUNT ON; DELETE FROM dbo.ORBC_CONTACT"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET QUOTED_IDENTIFIER ON; SET NOCOUNT ON; DELETE FROM dbo.ORBC_ADDRESS"
sqlcmd -C -U ${ORBC_USER} -P "${ORBC_PASS}" -S ${ORBC_SERVER} -d ${ORBC_DATABASE} -Q "SET QUOTED_IDENTIFIER ON; SET NOCOUNT ON; DELETE FROM dbo.ORBC_POLICY_CONFIGURATION"
echo "Finished deleting existing sample data"

echo "Loading sample data...please wait"
Expand Down
97 changes: 97 additions & 0 deletions database/mssql/scripts/versions/revert/v_51_ddl_revert.sql
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
118 changes: 118 additions & 0 deletions database/mssql/scripts/versions/v_51_ddl.sql

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions database/mssql/test/versions/v_51_1_test.sql
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')
4 changes: 4 additions & 0 deletions database/mssql/test/versions/v_51_2_test.sql
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')
4 changes: 4 additions & 0 deletions database/mssql/test/versions/v_51_3_test.sql
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]
30 changes: 30 additions & 0 deletions database/mssql/test/versions/v_51_test.sh
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
Loading

0 comments on commit 7268d30

Please sign in to comment.