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.
Feat: ORV2-1865 Add Feature Flag DB Migration (#1111)
- Loading branch information
Showing
6 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
database/mssql/scripts/versions/revert/sample-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,30 @@ | ||
-- This is a typical revert script | ||
-- Each migration script in the versions folder should also include a revert script | ||
|
||
SET ANSI_NULLS ON | ||
GO | ||
SET QUOTED_IDENTIFIER ON | ||
GO | ||
SET NOCOUNT ON | ||
GO | ||
|
||
SET XACT_ABORT ON | ||
|
||
-- Sample of rolling back a Table creation wrapped in a TRANSACTION | ||
--BEGIN TRY | ||
-- BEGIN TRANSACTION | ||
-- DROP TABLE [dbo].[ORBC_NEW_TABLE] | ||
-- COMMIT | ||
--END TRY | ||
|
||
--BEGIN CATCH | ||
-- IF @@TRANCOUNT > 0 | ||
-- ROLLBACK; | ||
-- THROW | ||
--END CATCH | ||
|
||
-- Also remember to rollback the version number from your migration! | ||
DECLARE @VersionDescription VARCHAR(255) | ||
SET @VersionDescription = '*** Enter description of DB change here ***' | ||
|
||
INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (/*<<REPLACE VERSION NUMBER HERE>>*/, @VersionDescription, getutcdate()) |
25 changes: 25 additions & 0 deletions
25
database/mssql/scripts/versions/revert/v_14_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,25 @@ | ||
SET ANSI_NULLS ON | ||
GO | ||
SET QUOTED_IDENTIFIER ON | ||
GO | ||
SET NOCOUNT ON | ||
GO | ||
|
||
SET XACT_ABORT ON | ||
|
||
BEGIN TRY | ||
BEGIN TRANSACTION | ||
DROP TABLE [dbo].[ORBC_FEATURE_FLAG] | ||
COMMIT | ||
END TRY | ||
|
||
BEGIN CATCH | ||
IF @@TRANCOUNT > 0 | ||
ROLLBACK; | ||
THROW | ||
END CATCH | ||
|
||
DECLARE @VersionDescription VARCHAR(255) | ||
SET @VersionDescription = 'Reverting initial creation of entities for feature flags.' | ||
|
||
INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (13, @VersionDescription, getutcdate()) |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
SET ANSI_NULLS ON | ||
GO | ||
SET QUOTED_IDENTIFIER ON | ||
GO | ||
SET NOCOUNT ON | ||
GO | ||
|
||
CREATE TABLE [dbo].[ORBC_FEATURE_FLAG]( | ||
[FEATURE_ID] [int] IDENTITY(1,1) NOT NULL, | ||
[FEATURE_KEY] [nvarchar](50) NOT NULL, | ||
[FEATURE_VALUE] [nvarchar](50) NOT NULL CHECK (FEATURE_VALUE IN ('ENABLED','DISABLED')), | ||
[APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), | ||
[APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), | ||
[APP_CREATE_USER_GUID] [char](32) NULL, | ||
[APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), | ||
[APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), | ||
[APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), | ||
[APP_LAST_UPDATE_USER_GUID] [char](32) NULL, | ||
[APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), | ||
[CONCURRENCY_CONTROL_NUMBER] [int] NULL, | ||
[DB_CREATE_USERID] [varchar](63) NULL, | ||
[DB_CREATE_TIMESTAMP] [datetime2](7) NULL, | ||
[DB_LAST_UPDATE_USERID] [varchar](63) NULL, | ||
[DB_LAST_UPDATE_TIMESTAMP] [datetime2](7) NULL, | ||
CONSTRAINT [ORBC_FEATURE_FLAG_PK] PRIMARY KEY CLUSTERED | ||
( | ||
[FEATURE_ID] ASC | ||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | ||
) ON [PRIMARY] | ||
GO | ||
|
||
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Unique auto-generated surrogate primary key' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'ORBC_FEATURE_FLAG', @level2type=N'COLUMN',@level2name=N'FEATURE_ID' | ||
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The feature flag' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1Name=N'ORBC_FEATURE_FLAG', @level2type=N'COLUMN',@level2name=N'FEATURE_KEY' | ||
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The feature value - ENABLED/DISABLED.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1Name=N'ORBC_FEATURE_FLAG', @level2type=N'COLUMN',@level2name=N'FEATURE_VALUE' | ||
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Application code is responsible for retrieving the row and then incrementing the value of the CONCURRENCY_CONTROL_NUMBER column by one prior to issuing an update. If this is done then the update will succeed, provided that the row was not updated by any other transactions in the period between the read and the update operations.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1Name=N'ORBC_FEATURE_FLAG', @level2type=N'COLUMN',@level2name=N'CONCURRENCY_CONTROL_NUMBER' | ||
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The user or proxy account that created or last updated the record.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1Name=N'ORBC_FEATURE_FLAG', @level2type=N'COLUMN',@level2name=N'DB_LAST_UPDATE_USERID' | ||
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The date and time the record was created.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1Name=N'ORBC_FEATURE_FLAG', @level2type=N'COLUMN',@level2name=N'DB_CREATE_TIMESTAMP' | ||
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The user or proxy account that created the record.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1Name=N'ORBC_FEATURE_FLAG', @level2type=N'COLUMN',@level2name=N'DB_CREATE_USERID' | ||
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The date and time the record was created or last updated.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1Name=N'ORBC_FEATURE_FLAG', @level2type=N'COLUMN',@level2name=N'DB_LAST_UPDATE_TIMESTAMP' | ||
GO | ||
|
||
DECLARE @VersionDescription VARCHAR(255) | ||
SET @VersionDescription = 'Initial creation of entities for feature flag' | ||
|
||
INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (14, @VersionDescription, '$(UPDATE_SCRIPT)', '$(REVERT_SCRIPT)', getutcdate()) |
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,5 @@ | ||
SET NOCOUNT ON | ||
IF OBJECT_ID('[$(DB_NAME)].[dbo].[ORBC_FEATURE_FLAG]', 'U') IS NOT NULL | ||
SELECT 1 | ||
ELSE | ||
SELECT 0 |
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 14 are run from this shell script. | ||
# TESTS_DIR variable set by the calling test-runner script. | ||
|
||
# Test 14.1 - verify that the tps migration tables exist | ||
TEST_14_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_14_1_test.sql) | ||
|
||
if [[ $TEST_14_1_RESULT -eq 1 ]]; then | ||
echo "Test 14.1 passed: All feature flag tables exist" | ||
else | ||
echo "******** Test 14.1 failed: Missing one or more feature flag tables" | ||
fi |