Skip to content

Commit

Permalink
Add GL type and GL code type tables (#1653)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-fletcher-aot authored Oct 25, 2024
1 parent eae1648 commit f8b808e
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
23 changes: 23 additions & 0 deletions database/mssql/scripts/versions/revert/v_46_ddl_revert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO

SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRANSACTION
GO

DROP TABLE [permit].[ORBC_GL_CODE_TYPE]
GO
DROP TABLE [permit].[ORBC_GL_TYPE]
GO
COMMIT

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Reverting addition of GL Type and GL Code Type tables'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (45, @VersionDescription, getutcdate())
111 changes: 111 additions & 0 deletions database/mssql/scripts/versions/v_46_ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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

CREATE TABLE [permit].[ORBC_GL_TYPE](
[GL_TYPE] [char] (6) NOT NULL,
[NAME] [varchar] (20) NOT NULL,
[DESCRIPTION] [varchar] (50) NULL,
[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_GL_TYPE_PK] PRIMARY KEY CLUSTERED
(
[GL_TYPE] 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
CREATE TABLE [permit].[ORBC_GL_CODE_TYPE](
[GL_CODE_TYPE] [int] IDENTITY(1,1) NOT NULL,
[GL_TYPE] [char] (6) NULL,
[PERMIT_TYPE] [varchar](10) NULL,
[PAYMENT_METHOD_TYPE] [varchar] (15) NULL,
[PAYMENT_CARD_TYPE] [varchar] (5) NULL,
[CLIENT] [char] (3) NOT NULL,
[RESPONSIBILITY] [char] (5) NOT NULL,
[SERVICE_LINE] [char] (5) NOT NULL,
[STOB] [char] (4) NOT NULL,
[PROJECT] [char] (7) NOT NULL,
[LOCATION] [char] (6) NOT NULL,
[FUTURE] [char] (4) NOT NULL,
[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_GL_CODE_TYPE_PK] PRIMARY KEY CLUSTERED
(
[GL_CODE_TYPE] 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
ALTER TABLE [permit].[ORBC_GL_CODE_TYPE] WITH CHECK ADD CONSTRAINT [FK_ORBC_GL_CODE_TYPE_GL_TYPE] FOREIGN KEY([GL_TYPE]) REFERENCES [permit].[ORBC_GL_TYPE] ([GL_TYPE])
GO
ALTER TABLE [permit].[ORBC_GL_CODE_TYPE] CHECK CONSTRAINT [FK_ORBC_GL_CODE_TYPE_GL_TYPE]
GO
ALTER TABLE [permit].[ORBC_GL_CODE_TYPE] WITH CHECK ADD CONSTRAINT [FK_ORBC_GL_CODE_TYPE_PERMIT_TYPE] FOREIGN KEY([PERMIT_TYPE])
REFERENCES [permit].[ORBC_PERMIT_TYPE] ([PERMIT_TYPE])
GO
ALTER TABLE [permit].[ORBC_GL_CODE_TYPE] CHECK CONSTRAINT [FK_ORBC_GL_CODE_TYPE_PERMIT_TYPE]
GO
ALTER TABLE [permit].[ORBC_GL_CODE_TYPE] WITH CHECK ADD CONSTRAINT [FK_ORBC_GL_CODE_TYPE_PAYMENT_METHOD_TYPE] FOREIGN KEY([PAYMENT_METHOD_TYPE]) REFERENCES [permit].[ORBC_PAYMENT_METHOD_TYPE] ([PAYMENT_METHOD_TYPE])
GO
ALTER TABLE [permit].[ORBC_GL_CODE_TYPE] CHECK CONSTRAINT [FK_ORBC_GL_CODE_TYPE_PAYMENT_METHOD_TYPE]
GO
ALTER TABLE [permit].[ORBC_GL_CODE_TYPE] WITH CHECK ADD CONSTRAINT [FK_ORBC_GL_CODE_TYPE_PAYMENT_CARD_TYPE] FOREIGN KEY([PAYMENT_CARD_TYPE]) REFERENCES [permit].[ORBC_PAYMENT_CARD_TYPE] ([PAYMENT_CARD_TYPE])
GO
ALTER TABLE [permit].[ORBC_GL_CODE_TYPE] CHECK CONSTRAINT [FK_ORBC_GL_CODE_TYPE_PAYMENT_CARD_TYPE]
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO

INSERT [permit].[ORBC_GL_TYPE] ([GL_TYPE], [NAME], [DESCRIPTION], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES (N'R_GL', N'Revenue GL', NULL, N'dbo', GETUTCDATE(), N'dbo', GETUTCDATE())
GO
INSERT [permit].[ORBC_GL_TYPE] ([GL_TYPE], [NAME], [DESCRIPTION], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES (N'BAL_GL', N'Balancing GL', NULL, N'dbo', GETUTCDATE(), N'dbo', GETUTCDATE())
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Add GL Type and GL Code Type tables'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (46, @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

6 changes: 6 additions & 0 deletions database/mssql/test/versions/v_46_1_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SET NOCOUNT ON
IF OBJECT_ID('[$(DB_NAME)].[permit].[ORBC_GL_TYPE]', 'U') IS NOT NULL
AND OBJECT_ID('[$(DB_NAME)].[permit].[ORBC_GL_CODE_TYPE]', 'U') IS NOT NULL
SELECT 1
ELSE
SELECT 0
16 changes: 16 additions & 0 deletions database/mssql/test/versions/v_46_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/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 46 are run from this shell script.
# TESTS_DIR variable set by the calling test-runner script.

TEST_46_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_46_1_test.sql | xargs)
if [[ $TEST_46_1_RESULT -eq 1 ]]; then
echo "Test 46.1 passed: GL type and GL code type tables exist."
else
echo "******** Test 46.1 failed: Missing either GL type or GL code type table."
fi

0 comments on commit f8b808e

Please sign in to comment.