generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Updated credit account sequence to avoid duplication (#1526)
1 parent
9bdecd4
commit b4f7db9
Showing
16 changed files
with
220 additions
and
141 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
database/mssql/scripts/sampledata/permit.ORBC_CREDIT_ACCOUNT_NUMBER_SEQ.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,12 @@ | ||
SET NOCOUNT ON | ||
GO | ||
DECLARE @TimestampCurrent int; | ||
DECLARE @s nvarchar(1000); | ||
|
||
SELECT @TimestampCurrent = DATEDIFF(SECOND, '19700101', sysutcdatetime()); | ||
|
||
SET @s = N' | ||
ALTER SEQUENCE [permit].[ORBC_CREDIT_ACCOUNT_NUMBER_SEQ] | ||
RESTART WITH ' + CAST(@TimestampCurrent AS nvarchar(10)) | ||
|
||
EXEC(@s) |
46 changes: 0 additions & 46 deletions
46
database/mssql/scripts/utility/legacy/revert-db-complete.sh
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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
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
62 changes: 62 additions & 0 deletions
62
database/mssql/scripts/versions/revert/v_38_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,62 @@ | ||
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 | ||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
-- Note that we are intentionally not going to reset the max value of the | ||
-- credit account sequence back to 9999 - if it ever does come into play | ||
-- it will be better to not have the 9999 limit there to avoid duplicates | ||
-- in the database. | ||
-- We will also maintain the column length at 15 characters in the event | ||
-- that credit accounts were created that exceed that, and we would not | ||
-- want to delete or modify those records once in place. | ||
-- So, this should be considered a non-revertable change - if necessary it | ||
-- must be reverted manually and very carefully. | ||
-- Including commented-out SQL for the revert below for reference, if we | ||
-- were to choose to do it. | ||
|
||
--ALTER SEQUENCE [permit].[ORBC_CREDIT_ACCOUNT_NUMBER_SEQ] | ||
-- MAXVALUE 9999 | ||
--IF @@ERROR <> 0 SET NOEXEC ON | ||
--GO | ||
|
||
--ALTER TABLE [permit].[ORBC_CREDIT_ACCOUNT] | ||
-- ALTER COLUMN CREDIT_ACCOUNT_NUMBER nvarchar(6) NOT NULL | ||
--IF @@ERROR <> 0 SET NOEXEC ON | ||
--GO | ||
--ALTER TABLE [permit].[ORBC_CREDIT_ACCOUNT_HIST] | ||
-- ALTER COLUMN CREDIT_ACCOUNT_NUMBER nvarchar(6) | ||
--IF @@ERROR <> 0 SET NOEXEC ON | ||
--GO | ||
|
||
DECLARE @VersionDescription VARCHAR(255) | ||
SET @VersionDescription = 'Reverting credit account sequence updates' | ||
|
||
INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (37, @VersionDescription, getutcdate()) | ||
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 update succeeded' | ||
ELSE BEGIN | ||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION | ||
PRINT 'The database update failed' | ||
END | ||
GO |
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,56 @@ | ||
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 | ||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
-- Increase size of credit account number column because it will be using | ||
-- a 10-digit suffix instead of 4 when we are in dev/test to avoid duplicates | ||
-- in CFS when we refresh the dev/test databases | ||
ALTER TABLE [permit].[ORBC_CREDIT_ACCOUNT] | ||
ALTER COLUMN CREDIT_ACCOUNT_NUMBER nvarchar(12) NOT NULL | ||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
ALTER TABLE [permit].[ORBC_CREDIT_ACCOUNT_HIST] | ||
ALTER COLUMN CREDIT_ACCOUNT_NUMBER nvarchar(12) | ||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
-- Set the sequence to have no max value (big int) so longer credit | ||
-- account numbers may be created in dev/test | ||
ALTER SEQUENCE [permit].[ORBC_CREDIT_ACCOUNT_NUMBER_SEQ] | ||
NO MAXVALUE | ||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
DECLARE @VersionDescription VARCHAR(255) | ||
SET @VersionDescription = 'Update credit account sequence to avoid duplicates in dev and test' | ||
|
||
INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (38, @VersionDescription, '$(UPDATE_SCRIPT)', '$(REVERT_SCRIPT)', getutcdate()) | ||
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 update succeeded' | ||
ELSE BEGIN | ||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION | ||
PRINT 'The database update failed' | ||
END | ||
GO |
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
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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
-- Test that the role types have been inserted correctly | ||
SET NOCOUNT ON | ||
|
||
SELECT COUNT(*) FROM $(DB_NAME).[access].[ORBC_ROLE_TYPE] | ||
SELECT COUNT(*) FROM $(DB_NAME).[access].[ORBC_GROUP_ROLE] | ||
WHERE ROLE_TYPE ='ORBC-READ-CREDIT-ACCOUNT' AND USER_AUTH_GROUP_TYPE IN ('PPCCLERK', 'CTPO', 'HQADMIN') |
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 APP_LAST_UPDATE_USERID column has been added correctly | ||
SET NOCOUNT ON | ||
|
||
select COL_LENGTH('$(DB_NAME).[permit].[ORBC_CREDIT_ACCOUNT]', 'CREDIT_ACCOUNT_NUMBER') |
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,18 @@ | ||
#!/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 32 are run from this shell script. | ||
# TESTS_DIR variable set by the calling test-runner script. | ||
|
||
TEST_38_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_38_1_test.sql | xargs) | ||
# Returns 30 for an nvarchar(15) data type due to larger nvarchar storage | ||
if [[ $TEST_38_1_RESULT -eq 30 ]]; then | ||
echo "Test 38.1 passed: CREDIT_ACCOUNT_NUMBER column length updated correctly" | ||
else | ||
echo "******** Test 38.1 failed: CREDIT_ACCOUNT_NUMBER column length not updated correctly: " | ||
echo $TEST_38_1_RESULT | ||
fi |
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