Skip to content

Commit

Permalink
TPS migration database support (#702)
Browse files Browse the repository at this point in the history
Signed-off-by: Praveen Raju <[email protected]>
Co-authored-by: Praveen Raju <[email protected]>
  • Loading branch information
john-fletcher-aot and praju-aot authored Oct 31, 2023
1 parent 0e671ab commit 2e4bda1
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 21 deletions.
5 changes: 4 additions & 1 deletion database/mssql/scripts/versions/revert/v_9_ddl_revert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ SET XACT_ABORT ON
BEGIN TRY
BEGIN TRANSACTION
DROP TABLE [tps].[ORBC_TPS_MIGRATED_PERMITS]
DROP TABLE [tps].[LEGACY_TPS_CLIENT_DATA]
DROP TABLE [tps].[ORBC_TPS_MIGRATED_CLIENTS]
DROP TABLE [tps].[ETL_PROCESS_ERROR]
DROP TABLE [tps].[ETL_PROCESSES]
DROP TABLE [tps].[ETL_PROCESS_TYPE]
DROP SCHEMA [tps]
COMMIT
END TRY
Expand Down
177 changes: 158 additions & 19 deletions database/mssql/scripts/versions/v_9_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,181 @@ GO
SET NOCOUNT ON
GO

CREATE TABLE [tps].[LEGACY_TPS_CLIENT_DATA](
[ID] [int] IDENTITY(1,1) NOT NULL,
[COMPANY_ID] [int] NULL,
[TPS_ID] [bigint] NULL,
[COMPANY_NAME] [varchar](50) NULL,
[COMPANY_SUB_NAME] [varchar](50) NULL,
[FIRST_NAME] [varchar](15) NULL,
[MIDDLE_NAME] [varchar](15) NULL,
[LAST_NAME] [varchar](44) NULL
CREATE TABLE [tps].[ETL_PROCESS_TYPE](
[PROCESS_TYPE] [char](3) NOT NULL,
[DESCRIPTION] [nvarchar](50) NULL,
CONSTRAINT [PK_ETL_PROCESS_TYPE] PRIMARY KEY CLUSTERED
(
[PROCESS_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 [tps].[LEGACY_TPS_CLIENT_DATA] WITH CHECK ADD CONSTRAINT [FK_LEGACY_TPS_CLIENT_DATA_COMPANY] FOREIGN KEY([COMPANY_ID])
REFERENCES [dbo].[ORBC_COMPANY] ([COMPANY_ID])
ALTER TABLE [tps].[LEGACY_TPS_CLIENT_DATA] CHECK CONSTRAINT [FK_LEGACY_TPS_CLIENT_DATA_COMPANY]
INSERT [tps].[ETL_PROCESS_TYPE] ([PROCESS_TYPE], [DESCRIPTION]) VALUES (N'CLI', N'Client Data')
GO
INSERT [tps].[ETL_PROCESS_TYPE] ([PROCESS_TYPE], [DESCRIPTION]) VALUES (N'PER', N'Permits')
GO

CREATE TABLE [tps].[ETL_PROCESS_ERROR](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[ETL_PROCESS_ID] [varchar](38) NULL,
[ERROR_DATE] [datetime2](7) NULL,
[ERROR_MESSAGE] [nvarchar](1000) NULL,
[CONCURRENCY_CONTROL_NUMBER] [int] NULL,
[DB_CREATE_USERID] [varchar](63) NOT NULL,
[DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL,
[DB_LAST_UPDATE_USERID] [varchar](63) NOT NULL,
[DB_LAST_UPDATE_TIMESTAMP] [datetime2](7) NOT NULL,
CONSTRAINT [PK_ETL_PROCESS_ERROR] PRIMARY KEY CLUSTERED
(
[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

ALTER TABLE [tps].[ETL_PROCESS_ERROR] ADD CONSTRAINT [DF_ETL_PROCESS_ERROR_DB_CREATE_USERID] DEFAULT (user_name()) FOR [DB_CREATE_USERID]
GO

ALTER TABLE [tps].[ETL_PROCESS_ERROR] ADD CONSTRAINT [DF_ETL_PROCESS_ERROR_DB_CREATE_TIMESTAMP] DEFAULT (getutcdate()) FOR [DB_CREATE_TIMESTAMP]
GO

ALTER TABLE [tps].[ETL_PROCESS_ERROR] ADD CONSTRAINT [DF_ETL_PROCESS_ERROR_DB_LAST_UPDATE_USERID] DEFAULT (user_name()) FOR [DB_LAST_UPDATE_USERID]
GO

ALTER TABLE [tps].[ETL_PROCESS_ERROR] ADD CONSTRAINT [DF_ETL_PROCESS_ERROR_DB_LAST_UPDATE_TIMESTAMP] DEFAULT (getutcdate()) FOR [DB_LAST_UPDATE_TIMESTAMP]
GO

CREATE TABLE [tps].[ETL_PROCESSES](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[ETL_PROCESS_ID] [varchar](38) NULL,
[PROCESS_TYPE] [char](3) NOT NULL,
[START_DATE] [datetime2](7) NULL,
[END_DATE] [datetime2](7) NULL,
[FILTER_FROM] [datetime2](7) NULL,
[FILTER_TO] [datetime2](7) NULL,
[ERROR_STATUS] [bit] NULL,
[ORBC_PROCESSED] [bit] NULL,
[CONCURRENCY_CONTROL_NUMBER] [int] NULL,
[DB_CREATE_USERID] [varchar](63) NOT NULL,
[DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL,
[DB_LAST_UPDATE_USERID] [varchar](63) NOT NULL,
[DB_LAST_UPDATE_TIMESTAMP] [datetime2](7) NOT NULL,
CONSTRAINT [PK_ETL_PROCESSES] PRIMARY KEY CLUSTERED
(
[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

ALTER TABLE [tps].[ETL_PROCESSES] ADD CONSTRAINT [DF_ETL_PROCESSES_ORBC_PROCESSED] DEFAULT ((0)) FOR [ORBC_PROCESSED]
GO

ALTER TABLE [tps].[ETL_PROCESSES] ADD CONSTRAINT [DF_ETL_PROCESSES_DB_CREATE_USERID] DEFAULT (user_name()) FOR [DB_CREATE_USERID]
GO

ALTER TABLE [tps].[ETL_PROCESSES] ADD CONSTRAINT [DF_ETL_PROCESSES_DB_CREATE_TIMESTAMP] DEFAULT (getutcdate()) FOR [DB_CREATE_TIMESTAMP]
GO

ALTER TABLE [tps].[ETL_PROCESSES] ADD CONSTRAINT [DF_ETL_PROCESSES_DB_LAST_UPDATE_USERID] DEFAULT (user_name()) FOR [DB_LAST_UPDATE_USERID]
GO

ALTER TABLE [tps].[ETL_PROCESSES] ADD CONSTRAINT [DF_ETL_PROCESSES_DB_LAST_UPDATE_TIMESTAMP] DEFAULT (getutcdate()) FOR [DB_LAST_UPDATE_TIMESTAMP]
GO

ALTER TABLE [tps].[ETL_PROCESSES] WITH CHECK ADD CONSTRAINT [FK_ETL_PROCESSES_ETL_PROCESS_TYPE] FOREIGN KEY([PROCESS_TYPE])
REFERENCES [tps].[ETL_PROCESS_TYPE] ([PROCESS_TYPE])
GO

ALTER TABLE [tps].[ETL_PROCESSES] CHECK CONSTRAINT [FK_ETL_PROCESSES_ETL_PROCESS_TYPE]
GO

CREATE TABLE [tps].[ORBC_TPS_MIGRATED_CLIENTS](
[MIGRATION_ID] [bigint] IDENTITY(1,1) NOT NULL,
[ID] [bigint] NULL,
[CLIENT_HASH] [nvarchar](64) NULL,
[LEGAL_NAME] [nvarchar](101) NULL,
[EMAIL] [nvarchar](320) NULL,
[PHONE] [nvarchar](30) NULL,
[FAX] [nvarchar](30) NULL,
[ADDR_LINE1] [nvarchar](44) NULL,
[ADDR_LINE2] [nvarchar](44) NULL,
[CITY] [nvarchar](44) NULL,
[PROVINCE_ID] [nvarchar](5) NULL,
[POSTAL_CODE] [nvarchar](7) NULL,
[GUID] [nvarchar](64) NULL,
[REGION] [nchar](1) NULL,
[NEW_CLIENT_NUMBER] [char](13) NULL,
[LCV] [nvarchar](10) NULL,
[NOFEE] [nvarchar](10) NULL,
[ETL_PROCESS_ID] [varchar](38) NULL,
[PROCESSED] [bit] NULL,
[PROCESSED_DATE] [datetime2](7) NULL,
[CONCURRENCY_CONTROL_NUMBER] [int] NULL,
[DB_CREATE_USERID] [varchar](63) NOT NULL,
[DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL,
[DB_LAST_UPDATE_USERID] [varchar](63) NOT NULL,
[DB_LAST_UPDATE_TIMESTAMP] [datetime2](7) NOT NULL,
CONSTRAINT [PK_ORBC_TPS_MIGRATED_CLIENTS] PRIMARY KEY CLUSTERED
(
[MIGRATION_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

ALTER TABLE [tps].[ORBC_TPS_MIGRATED_CLIENTS] ADD CONSTRAINT [DF_ORBC_TPS_MIGRATED_CLIENTS_DB_CREATE_USERID] DEFAULT (user_name()) FOR [DB_CREATE_USERID]
GO

ALTER TABLE [tps].[ORBC_TPS_MIGRATED_CLIENTS] ADD CONSTRAINT [DF_ORBC_TPS_MIGRATED_CLIENTS_DB_CREATE_TIMESTAMP] DEFAULT (getutcdate()) FOR [DB_CREATE_TIMESTAMP]
GO

ALTER TABLE [tps].[ORBC_TPS_MIGRATED_CLIENTS] ADD CONSTRAINT [DF_ORBC_TPS_MIGRATED_CLIENTS_DB_LAST_UPDATE_USERID] DEFAULT (user_name()) FOR [DB_LAST_UPDATE_USERID]
GO

ALTER TABLE [tps].[ORBC_TPS_MIGRATED_CLIENTS] ADD CONSTRAINT [DF_ORBC_TPS_MIGRATED_CLIENTS_DB_LAST_UPDATE_TIMESTAMP] DEFAULT (getutcdate()) FOR [DB_LAST_UPDATE_TIMESTAMP]
GO

CREATE TABLE [tps].[ORBC_TPS_MIGRATED_PERMITS](
[MIGRATION_ID] [bigint] IDENTITY(1,1) NOT NULL,
[PERMIT_TYPE] [varchar](10) NULL,
[PERMIT_TYPE] [nvarchar](50) NULL,
[START_DATE] [date] NULL,
[END_DATE] [date] NULL,
[VOID_DATE] [datetime2](7) NULL,
[ISSUED_DATE] [datetime2](7) NULL,
[CLIENT_ID] int NULL,
[PLATE] [varchar](8) NULL,
[PERMIT_NUMBER] [varchar](11) NULL,
[CLIENT_HASH] [nvarchar](64) NULL,
[PLATE] [nvarchar](50) NULL,
[PERMIT_NUMBER] [nvarchar](50) NULL,
[PERMIT_GENERATION] [smallint] NULL,
[PERMIT_DOCUMENT_NAME] [varchar](60) NULL,
[SERVICE] [varchar](8) NULL,
[PERMIT_DOCUMENT_NAME] [nvarchar](60) NULL,
[SERVICE] [nvarchar](50) NULL,
[PERMIT_LAST_MODIFIED_DATE] [datetime2](7) NULL,
[PDF] [varbinary](max) NULL,
[SYNC_DATETIME] [datetime2](7) NOT NULL
[ETL_PROCESS_ID] [varchar](38) NULL,
[PROCESSED] [bit] NULL,
[PROCESSED_DATE] [datetime2](7) NULL,
[CONCURRENCY_CONTROL_NUMBER] [int] NULL,
[DB_CREATE_USERID] [varchar](63) NOT NULL,
[DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL,
[DB_LAST_UPDATE_USERID] [varchar](63) NOT NULL,
[DB_LAST_UPDATE_TIMESTAMP] [datetime2](7) NOT NULL,
CONSTRAINT [PK_ORBC_TPS_MIGRATED_PERMITS] PRIMARY KEY CLUSTERED
(
[MIGRATION_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] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [tps].[ORBC_TPS_MIGRATED_PERMITS] ADD CONSTRAINT [DF_ORBC_TPS_MIGRATED_PERMITS_DB_CREATE_USERID] DEFAULT (user_name()) FOR [DB_CREATE_USERID]
GO

ALTER TABLE [tps].[ORBC_TPS_MIGRATED_PERMITS] ADD CONSTRAINT [DF_ORBC_TPS_MIGRATED_PERMITS_DB_CREATE_TIMESTAMP] DEFAULT (getutcdate()) FOR [DB_CREATE_TIMESTAMP]
GO

ALTER TABLE [tps].[ORBC_TPS_MIGRATED_PERMITS] ADD CONSTRAINT [DF_ORBC_TPS_MIGRATED_PERMITS_DB_LAST_UPDATE_USERID] DEFAULT (user_name()) FOR [DB_LAST_UPDATE_USERID]
GO

ALTER TABLE [tps].[ORBC_TPS_MIGRATED_PERMITS] ADD CONSTRAINT [DF_ORBC_TPS_MIGRATED_PERMITS_DB_LAST_UPDATE_TIMESTAMP] DEFAULT (getutcdate()) FOR [DB_LAST_UPDATE_TIMESTAMP]
GO

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Creation of tables to store TPS migration staging data.'

Expand Down
4 changes: 3 additions & 1 deletion database/mssql/test/versions/v_9_1_test.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
SET NOCOUNT ON
IF OBJECT_ID('[$(DB_NAME)].[tps].[LEGACY_TPS_CLIENT_DATA]', 'U') IS NOT NULL
IF OBJECT_ID('[$(DB_NAME)].[tps].[ORBC_TPS_MIGRATED_CLIENTS]', 'U') IS NOT NULL
AND OBJECT_ID('[$(DB_NAME)].[tps].[ORBC_TPS_MIGRATED_PERMITS]', 'U') IS NOT NULL
AND OBJECT_ID('[$(DB_NAME)].[tps].[ETL_PROCESS_ERROR]', 'U') IS NOT NULL
AND OBJECT_ID('[$(DB_NAME)].[tps].[ETL_PROCESSES]', 'U') IS NOT NULL
SELECT 1
ELSE
SELECT 0

0 comments on commit 2e4bda1

Please sign in to comment.