From 4d1a513f327ef842d6fb5a78d63ff96df8482152 Mon Sep 17 00:00:00 2001 From: OluwatobiAwe Date: Mon, 29 Sep 2025 11:02:31 +0100 Subject: [PATCH 1/5] TD-6159 update --- .../LearningHub.Nhs.Database.sqlproj | 45 ++++++ .../LearningHub.Nhs.Database/Schemas/elfh.sql | 3 + .../Elfh/LinkEmploymentRecordToUser.sql | 36 +++++ .../UserDetailForAuthenticationByUserName.sql | 46 ++++++ .../Elfh/UserHistoryAttributeSave.sql | 89 +++++++++++ .../Elfh/UserHistoryInsert.sql | 143 ++++++++++++++++++ .../UserHistoryLoadForLearningHubUser.sql | 50 ++++++ .../Elfh/UserHistoryLoadForUser.sql | 55 +++++++ .../Tables/Elfh/AttributeTBL.sql | 31 ++++ .../Tables/Elfh/AttributeTypeTBL.sql | 18 +++ .../Tables/Elfh/CountryTBL.sql | 24 +++ .../Tables/Elfh/DeaneryTBL.sql | 13 ++ .../Tables/Elfh/EmailTemplateTBL.sql | 30 ++++ .../Tables/Elfh/EmailTemplateTypeTBL.sql | 19 +++ .../Tables/Elfh/ExternalSystemTBL.sql | 31 ++++ .../Tables/Elfh/GdcRegister.sql | 36 +++++ .../Tables/Elfh/GmcLrmp.sql | 16 ++ .../Tables/Elfh/GradeTBL.sql | 20 +++ .../Tables/Elfh/IpCountryLookupTBL.sql | 8 + .../Tables/Elfh/JobRoleTBL.sql | 35 +++++ .../Tables/Elfh/Location.sql | 117 ++++++++++++++ .../Tables/Elfh/LoginWizardRuleTBL.sql | 25 +++ .../Elfh/LoginWizardStageActivityTBL.sql | 25 +++ .../Tables/Elfh/MedicalCouncilTBL.sql | 24 +++ .../Tables/Elfh/RegionTBL.sql | 16 ++ .../Tables/Elfh/SchoolTBL.sql | 29 ++++ .../Tables/Elfh/SpecialtyTBL.sql | 19 +++ .../Tables/Elfh/StaffGroupTBL.sql | 17 +++ .../Tables/Elfh/SystemSettingTBL.sql | 24 +++ .../Tables/Elfh/TenantSmtpTBL.sql | 16 ++ .../Tables/Elfh/TenantTBL.sql | 43 ++++++ .../Tables/Elfh/TenantUrlTBL.sql | 24 +++ .../Tables/Elfh/TermsAndConditionsTBL.sql | 27 ++++ .../Tables/Elfh/UserAttributeTBL.sql | 37 +++++ .../Tables/Elfh/UserEmploymentTBL.sql | 85 +++++++++++ .../Elfh/UserGroupTypeInputValidationTBL.sql | 39 +++++ .../Tables/Elfh/UserHistoryAttributeTBL.sql | 39 +++++ .../Tables/Elfh/UserHistoryTBL.sql | 25 +++ .../Elfh/UserPasswordValidationTokenTBL.sql | 33 ++++ .../Tables/Elfh/UserRoleUpgradeTBL.sql | 35 +++++ .../Tables/Elfh/UserTermsAndConditionsTBL.sql | 28 ++++ .../Tables/Elfh/locationTypeTBL.sql | 34 +++++ .../Tables/Elfh/loginWizardStageTBL.sql | 13 ++ .../Tables/Elfh/userHistoryTypeTBL.sql | 9 ++ .../Tables/Hub/User.sql | 49 ++++++ 45 files changed, 1580 insertions(+) create mode 100644 WebAPI/LearningHub.Nhs.Database/Schemas/elfh.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/LinkEmploymentRecordToUser.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserDetailForAuthenticationByUserName.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryAttributeSave.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryInsert.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryLoadForLearningHubUser.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryLoadForUser.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/AttributeTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/AttributeTypeTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/CountryTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/DeaneryTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmailTemplateTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmailTemplateTypeTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/ExternalSystemTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GdcRegister.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GmcLrmp.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GradeTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/IpCountryLookupTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/JobRoleTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/Location.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/LoginWizardRuleTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/LoginWizardStageActivityTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/MedicalCouncilTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/RegionTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SchoolTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SpecialtyTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/StaffGroupTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SystemSettingTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantSmtpTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantUrlTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TermsAndConditionsTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserAttributeTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserGroupTypeInputValidationTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserHistoryAttributeTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserHistoryTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserPasswordValidationTokenTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserRoleUpgradeTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserTermsAndConditionsTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/locationTypeTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/loginWizardStageTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/userHistoryTypeTBL.sql diff --git a/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj b/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj index 0e779391c..81bab93c7 100644 --- a/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj +++ b/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj @@ -101,6 +101,8 @@ + + @@ -546,6 +548,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WebAPI/LearningHub.Nhs.Database/Schemas/elfh.sql b/WebAPI/LearningHub.Nhs.Database/Schemas/elfh.sql new file mode 100644 index 000000000..09637bd31 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Schemas/elfh.sql @@ -0,0 +1,3 @@ +CREATE SCHEMA [elfh] + AUTHORIZATION [dbo]; +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/LinkEmploymentRecordToUser.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/LinkEmploymentRecordToUser.sql new file mode 100644 index 000000000..0f4f670ba --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/LinkEmploymentRecordToUser.sql @@ -0,0 +1,36 @@ +----------------------------------------------------------------------------------------------- +-- Mark Avey 11/06/2020 - Initial Version. +-- Update the UserTBL record with the primaryUserEmploymentId from userEmploymentTBL +------------------------------------------------------------------------------------------------ +CREATE PROCEDURE [elfh].[proc_LinkEmploymentRecordToUser] +( + @userId int +) +AS +BEGIN + BEGIN TRANSACTION + BEGIN TRY + SET NOCOUNT OFF + + UPDATE [hub].[User] + SET primaryUserEmploymentId = (SELECT userEmploymentId FROM [elfh].[userEmploymentTBL] WHERE userId = @userId) + WHERE Id = @userId + + END TRY + + BEGIN CATCH + SELECT + ERROR_NUMBER() AS ErrorNumber + ,ERROR_SEVERITY() AS ErrorSeverity + ,ERROR_STATE() AS ErrorState + ,ERROR_PROCEDURE() AS ErrorProcedure + ,ERROR_LINE() AS ErrorLine + ,ERROR_MESSAGE() AS ErrorMessage; + + IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION + END CATCH + + IF @@TRANCOUNT > 0 COMMIT TRANSACTION + + RETURN @@ERROR + END \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserDetailForAuthenticationByUserName.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserDetailForAuthenticationByUserName.sql new file mode 100644 index 000000000..75896ca8d --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserDetailForAuthenticationByUserName.sql @@ -0,0 +1,46 @@ +------------------------------------------------------------------------- +-- Jignesh Jethwani 27 Sept 2023 - Initial version +-- Tobi Awe 24 Sept 2025 - swapped elfh user table to hub user table +-------------------------------------------------------------------------- +CREATE PROCEDURE [elfh].[proc_UserDetailForAuthenticationByUserName] +( + @userName varchar(100) +) +AS +BEGIN + SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED + SET NOCOUNT ON + DECLARE @Err int + DECLARE @false bit + SET @false = 0 + SELECT elfhuser.Id as Id, + elfhuser.userName, + ISNULL(elfhuser.passwordHash, '') AS 'passwordHash', + elfhuser.RestrictToSSO, + up.Active, + elfhuser.activeFromDate, + elfhuser.activeToDate, + elfhuser.passwordLifeCounter, + userAttribData.userAttributeId as OpenAthensUserAttributeId + FROM + [hub].[User] elfhuser + INNER JOIN hub.UserProfile up + ON elfhuser.Id = up.Id + OUTER APPLY + ( + SELECT + TOP 1 userAttrib.userAttributeId + FROM + elfh.userAttributeTBL userAttrib + INNER Join + elfh.attributeTBL attrib ON userAttrib.attributeId = attrib.attributeId AND lower(attrib.attributeName) = 'openathens_userid' AND userAttrib.deleted = 0 + WHERE + userAttrib.userId = elfhuser.Id + ) userAttribData + WHERE + elfhuser.userName = @userName + AND + elfhuser.deleted = 0 + SET @Err = @@Error + RETURN @Err +END \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryAttributeSave.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryAttributeSave.sql new file mode 100644 index 000000000..7ecb39048 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryAttributeSave.sql @@ -0,0 +1,89 @@ + +-------------------------------------------------------------------------- +-- Jignesh Jethwani 02-03-2018 Initial version +-- Jignesh Jethwani 02-10-2023 TD-2913, performance improvement, added no lock to select statement +-- Tobi Awe 24-09-2025 Updated table schema +-------------------------------------------------------------------------- +CREATE PROCEDURE [elfh].[proc_UserHistoryAttributeSave] +( + @userHistoryAttributeId int OUTPUT, + @userHistoryId int, + @attributeId int, + @intValue int, + @textValue nvarchar(255), + @booleanValue bit, + @dateValue datetimeoffset, + @deleted bit, + @amendUserId int, + @amendDate datetimeoffset +) +AS +BEGIN + DECLARE @currentIntValue int + DECLARE @currentTextValue nvarchar(255) + DECLARE @currentBooleanValue bit + DECLARE @currentDateValue datetimeoffset + SELECT + @userHistoryAttributeId = userHistoryAttributeId, + @currentIntValue = intValue, + @currentTextValue = textValue, + @currentBooleanValue = booleanValue, + @currentDateValue = dateValue + FROM + elfh.userHistoryAttributeTBL WITH (NOLOCK) + WHERE + userHistoryId = @userHistoryId + AND + attributeId = @attributeId + IF @userHistoryAttributeId IS NULL + BEGIN + IF @intValue IS NOT NULL + OR ISNULL(@textValue, '') != '' + OR @booleanValue IS NOT NULL + OR @dateValue IS NOT NULL + BEGIN + INSERT INTO elfh.userHistoryAttributeTBL(userHistoryId, + attributeId, + intValue, + textValue, + booleanValue, + dateValue, + deleted, + amendUserId, + amendDate) + SELECT + userHistoryId = @userHistoryId, + attributeId = @attributeId, + intValue = @intValue, + textValue = @textValue, + booleanValue = @booleanValue, + dateValue = @dateValue, + deleted = @deleted, + amendUserId = @amendUserId, + @amendDate + SELECT @userHistoryAttributeId = SCOPE_IDENTITY() + END + END + ELSE + BEGIN + -- Only update when an Attribute Value has changed + IF (@intValue != @currentIntValue + OR ISNULL(@textValue, '') != ISNULL(@currentTextValue,'') + OR @booleanValue != @currentBooleanValue + OR @dateValue != @currentDateValue) + BEGIN + UPDATE + elfh.userHistoryAttributeTBL + SET + intValue = @intValue, + textValue = @textValue, + booleanValue = @booleanValue, + dateValue = @dateValue, + deleted = @deleted, + amendUserId = @amendUserId, + amendDate = @amendDate + WHERE + userHistoryAttributeId = @userHistoryAttributeId + END + END +END diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryInsert.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryInsert.sql new file mode 100644 index 000000000..f972aa05b --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryInsert.sql @@ -0,0 +1,143 @@ + +-------------------------------------------------------------------------- +-- Chris Bain 08 Aug 2014 - Initial Build +-- Killian Davies 12 Aug 2015 - Added userAgent info (for Login history event) +-- Chris Bain 18 Nov 2016 - Added tenant Id +-- Jignesh Jethwani 02 Mar 2018 - Save details to User History Attribute, add url referer +-------------------------------------------------------------------------- +CREATE PROCEDURE [elfh].[proc_UserHistoryInsert] + @userId int = 0, + @historyTypeId int, + @detailedInfo NVARCHAR(1000) = NULL, + @userAgent NVARCHAR(1000) = NULL, + @browserName NVARCHAR(1000) = NULL, + @browserVersion NVARCHAR(1000) = NULL, + @urlReferer NVARCHAR(1000) = NULL, + @loginIP NVARCHAR(50) = NULL, + @loginSuccessFul bit = NULL, + @tenantId INT, + @amendUserId INT, + @amendDate DATETIMEOFFSET = NULL +AS +BEGIN + + DECLARE @UserHistoryId int + DECLARE @detailInfoAttributeId int, @userAgentAttributeId int, @browserNameAttributeId int, @browserVersionAttributeId int, @urlRefererAttributeId int, @loginSuccessFulAttributeId int + SET @amendDate = CoalEsce(@amendDate,SysDateTimeOffset()) + + INSERT INTO userHistoryTBL (userId, userHistoryTypeId, tenantId,createdDate) + VALUES (@userId, @historyTypeId, @tenantId, @amendDate) + + + SET @UserHistoryId = CAST(SCOPE_IDENTITY() AS int) + + SELECT @detailInfoAttributeId = attributeId FROM [elfh].[attributeTBL] WHERE [attributeName] = 'UserHistory_DetailedInfo' AND deleted = 0 + SELECT @userAgentAttributeId = attributeId FROM [elfh].[attributeTBL] WHERE [attributeName] = 'UserHistory_UserAgent' AND deleted = 0 + SELECT @browserNameAttributeId = attributeId FROM [elfh].[attributeTBL] WHERE [attributeName] = 'UserHistory_BrowserName' AND deleted = 0 + SELECT @browserVersionAttributeId = attributeId FROM [elfh].[attributeTBL] WHERE [attributeName] = 'UserHistory_BrowserVersion' AND deleted = 0 + SELECT @urlRefererAttributeId = attributeId FROM [elfh].[attributeTBL] WHERE [attributeName] = 'UserHistory_UrlReferer' AND deleted = 0 + SELECT @loginSuccessFulAttributeId = attributeId FROM [elfh].[attributeTBL] WHERE [attributeName] = 'UserHistory_LoginSuccessful' AND deleted = 0 + + -- DetailedInfo + IF @detailInfoAttributeId > 0 AND @detailedInfo IS NOT NULL + BEGIN + EXECUTE [elfh].[proc_UserHistoryAttributeSave] null, + @UserHistoryId, + @detailInfoAttributeId, + NULL, + @detailedInfo, -- textValue, + NULL, -- booleanValue, + NULL, -- dateValue, + 0, -- deleted + @amendUserId, + @amendDate + END + + -- User Agent + IF @userAgentAttributeId > 0 AND @userAgent IS NOT NULL + BEGIN + + EXECUTE [elfh].[proc_UserHistoryAttributeSave] null, + @UserHistoryId, + @userAgentAttributeId, + NULL, -- intValue + @userAgent, -- textValue, + NULL, -- booleanValue, + NULL, -- dateValue, + 0, -- deleted + @amendUserId, + @amendDate + END + + -- Browser Name + IF @browserNameAttributeId > 0 AND @browserName IS NOT NULL + BEGIN + + EXECUTE [elfh].[proc_UserHistoryAttributeSave] null, + @UserHistoryId, + @browserNameAttributeId, + NULL, -- intValue + @browserName, -- textValue, + NULL, -- booleanValue, + NULL, -- dateValue, + 0, -- deleted + @amendUserId, + @amendDate + + END + + -- Browser Version + IF @browserVersionAttributeId > 0 AND @browserVersion IS NOT NULL + BEGIN + + + EXECUTE [elfh].[proc_UserHistoryAttributeSave] null, + @UserHistoryId, + @browserVersionAttributeId, + NULL, -- intValue + @browserVersion, + NULL, -- booleanValue, + NULL, -- dateValue, + 0, -- deleted + @amendUserId, + @amendDate + END + + + -- Url Referer + IF @urlRefererAttributeId > 0 AND @urlReferer IS NOT NULL + BEGIN + + EXECUTE [elfh].[proc_UserHistoryAttributeSave] null, + @UserHistoryId, + @urlRefererAttributeId, + NULL, -- intValue + @urlReferer, -- textValue, + NULL, -- booleanValue, + NULL, -- dateValue, + 0, -- deleted + @amendUserId, + @amendDate + + END + + + -- Login SuccessFul + IF @loginSuccessFulAttributeId > 0 AND @loginSuccessFul IS NOT NULL + BEGIN + + EXECUTE [elfh].[proc_UserHistoryAttributeSave] null, + @UserHistoryId, + @loginSuccessFulAttributeId, + NULL, -- intValue + @loginIP, -- textValue, + @loginSuccessFul, -- booleanValue, + NULL, -- dateValue, + 0, -- deleted + @amendUserId, + @amendDate + + END + + +END \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryLoadForLearningHubUser.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryLoadForLearningHubUser.sql new file mode 100644 index 000000000..7889a609b --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryLoadForLearningHubUser.sql @@ -0,0 +1,50 @@ +-------------------------------------------------------------------------------- +-- Killian Davies 08-February-2021 Initial Revision - services LH user history +-------------------------------------------------------------------------------- +CREATE PROCEDURE [elfh].[proc_UserHistoryLoadForLearningHubUser] + @userId int, + @startPage int=1, + @PageSize float=10.0, + @TotalResults int output +AS + DECLARE @History Table(RowNumber int, userHistoryId int) + + DECLARE @ItemsReturned INT + DECLARE @StartRow INT + DECLARE @EndRow INT + SET @StartRow = ((@startPage - 1) * @PageSize) + SET @EndRow = (@startPage * @PageSize) + 1 + + INSERT INTO @History + SELECT + ROW_NUMBER() OVER( ORDER BY [userHistoryId] DESC) as RowNumber, + userHistoryId + FROM + userHistoryTBL + WHERE + userId = @userId + ORDER BY + createdDate DESC + + -- Determine the number of items in the search result set + SELECT + @TotalResults = Count(userHistoryId) + FROM + @History + + SELECT + uh.*, + uht.[Description], + ISNULL(t.tenantName,'Unknown') as tenantName + FROM userHistoryVW uh + INNER JOIN @History h ON h.userHistoryId = uh.userHistoryId + INNER JOIN userHistoryTypeTBL uht ON uht.UserHistoryTypeId = uh.userHistoryTypeId + LEFT JOIN tenantTBL t ON t.tenantId = uh.tenantId + WHERE + h.RowNumber > @StartRow + AND + h.RowNumber < @EndRow + ORDER BY + h.RowNumber ASC + +RETURN 0 diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryLoadForUser.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryLoadForUser.sql new file mode 100644 index 000000000..69e061a00 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Elfh/UserHistoryLoadForUser.sql @@ -0,0 +1,55 @@ +-------------------------------------------------------------------------------- +-- Jignesh Jethwani 05 Mar 2018 - Updated, moved userHistory to Attribute Table +-- Killian Davies 30 Oct 2019 - Perf improvement - modified to use table rather than view +-------------------------------------------------------------------------------- + +CREATE PROCEDURE [elfh].[proc_UserHistoryLoadForUser] + @userId int, + @startPage int=1, + @PageSize float=10.0, + @PagesReturned int output +AS + DECLARE @History Table(RowNumber int, userHistoryId int) + + DECLARE @ItemsReturned INT + DECLARE @StartRow INT + DECLARE @EndRow INT + SET @StartRow = ((@startPage - 1) * @PageSize) + SET @EndRow = (@startPage * @PageSize) + 1 + + INSERT INTO @History + SELECT + ROW_NUMBER() OVER( ORDER BY [userHistoryId] DESC) as RowNumber, + userHistoryId + FROM + userHistoryTBL + WHERE + userId = @userId + ORDER BY + createdDate DESC + + -- Determine the number of items in the search result set + SELECT + @ItemsReturned = Count(userHistoryId) + FROM + @History + + SET @PagesReturned = CEILING(@ItemsReturned / @PageSize); + + + SELECT + uh.*, + uht.[Description], + ISNULL(t.tenantName,'Unknown') as tenantName + FROM userHistoryVW uh + INNER JOIN @History h ON h.userHistoryId = uh.userHistoryId + INNER JOIN userHistoryTypeTBL uht ON uht.UserHistoryTypeId = uh.userHistoryTypeId + LEFT JOIN tenantTBL t ON t.tenantId = uh.tenantId + WHERE + h.RowNumber > @StartRow + AND + h.RowNumber < @EndRow + ORDER BY + h.RowNumber ASC + +RETURN 0 diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/AttributeTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/AttributeTBL.sql new file mode 100644 index 000000000..69fffa30b --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/AttributeTBL.sql @@ -0,0 +1,31 @@ +CREATE TABLE [elfh].[attributeTBL]( + [attributeId] [int] IDENTITY(1,1) NOT NULL, + [attributeTypeId] [int] NOT NULL, + [attributeName] [nvarchar](50) NOT NULL, + [attributeAccess] [tinyint] NOT NULL, + [attributeDescription] [nvarchar](400) NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_attributeTBL] PRIMARY KEY CLUSTERED +( + [attributeId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[attributeTBL] ADD DEFAULT ((0)) FOR [attributeAccess] +GO + +ALTER TABLE [elfh].[attributeTBL] ADD DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[attributeTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO + +ALTER TABLE [elfh].[attributeTBL] WITH CHECK ADD CONSTRAINT [FK_attributeTBL_attributeTypeId] FOREIGN KEY([attributeTypeId]) +REFERENCES [elfh].[attributeTypeTBL] ([attributeTypeId]) +GO + +ALTER TABLE [elfh].[attributeTBL] CHECK CONSTRAINT [FK_attributeTBL_attributeTypeId] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/AttributeTypeTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/AttributeTypeTBL.sql new file mode 100644 index 000000000..39a87b055 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/AttributeTypeTBL.sql @@ -0,0 +1,18 @@ +CREATE TABLE [elfh].[attributeTypeTBL]( + [attributeTypeId] [int] NOT NULL, + [attributeTypeName] [nvarchar](50) NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_attributeTypeTBL] PRIMARY KEY CLUSTERED +( + [attributeTypeId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[attributeTypeTBL] ADD DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[attributeTypeTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/CountryTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/CountryTBL.sql new file mode 100644 index 000000000..2adf7cc35 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/CountryTBL.sql @@ -0,0 +1,24 @@ +CREATE TABLE [elfh].[countryTBL]( + [countryId] [int] IDENTITY(1,1) NOT NULL, + [countryName] [nvarchar](50) NULL, + [alpha2] [nvarchar](2) NULL, + [alpha3] [nvarchar](3) NULL, + [numeric] [nvarchar](3) NULL, + [EUVatRate] [float] NOT NULL, + [displayOrder] [int] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_countryTBL] PRIMARY KEY CLUSTERED +( + [countryId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[countryTBL] ADD DEFAULT ((0)) FOR [EUVatRate] +GO + +ALTER TABLE [elfh].[countryTBL] ADD CONSTRAINT [DF_countryTBL_displayOrder] DEFAULT ((0)) FOR [displayOrder] +GO + diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/DeaneryTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/DeaneryTBL.sql new file mode 100644 index 000000000..bc2f91bef --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/DeaneryTBL.sql @@ -0,0 +1,13 @@ +CREATE TABLE [elfh].[deaneryTBL]( + [deaneryId] [int] IDENTITY(1,1) NOT NULL, + [deaneryName] [nvarchar](50) NOT NULL, + [displayOrder] [int] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_deaneryTBL] PRIMARY KEY CLUSTERED +( + [deaneryId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmailTemplateTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmailTemplateTBL.sql new file mode 100644 index 000000000..18210ed54 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmailTemplateTBL.sql @@ -0,0 +1,30 @@ +CREATE TABLE [elfh].[emailTemplateTBL]( + [emailTemplateId] [int] IDENTITY(1,1) NOT NULL, + [emailTemplateTypeId] [int] NOT NULL, + [programmeComponentId] [int] NOT NULL, + [title] [nvarchar](256) NULL, + [subject] [nvarchar](256) NOT NULL, + [body] [ntext] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + [tenantId] [int] NULL, + CONSTRAINT [PK_EmailTemplateTBL] PRIMARY KEY CLUSTERED +( + [emailTemplateId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] +GO + +ALTER TABLE [elfh].[emailTemplateTBL] ADD CONSTRAINT [DF_emailTemplateTBL_Deleted] DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[emailTemplateTBL] ADD CONSTRAINT [DF_EmailTemplate_AmendDate] DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO + +ALTER TABLE [elfh].[emailTemplateTBL] WITH CHECK ADD CONSTRAINT [FK_emailTemplateTBL_emailTemplateTypeTBL] FOREIGN KEY([emailTemplateTypeId]) +REFERENCES [elfh].[emailTemplateTypeTBL] ([emailTemplateTypeId]) +GO + +ALTER TABLE [elfh].[emailTemplateTBL] CHECK CONSTRAINT [FK_emailTemplateTBL_emailTemplateTypeTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmailTemplateTypeTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmailTemplateTypeTBL.sql new file mode 100644 index 000000000..d3b4764b8 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmailTemplateTypeTBL.sql @@ -0,0 +1,19 @@ +CREATE TABLE [elfh].[emailTemplateTypeTBL]( + [emailTemplateTypeId] [int] NOT NULL, + [emailTemplateTypeName] [nvarchar](50) NOT NULL, + [availableTags] [nvarchar](255) NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_emailTemplateTypeTBL] PRIMARY KEY CLUSTERED +( + [emailTemplateTypeId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[emailTemplateTypeTBL] ADD CONSTRAINT [DF_emailTemplateTypeTBL_Deleted] DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[emailTemplateTypeTBL] ADD CONSTRAINT [DF_emailTemplateTypeTBL_AmendDate] DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/ExternalSystemTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/ExternalSystemTBL.sql new file mode 100644 index 000000000..0a565aaa7 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/ExternalSystemTBL.sql @@ -0,0 +1,31 @@ +CREATE TABLE [elfh].[externalSystemTBL]( + [externalSystemId] [int] IDENTITY(1,1) NOT NULL, + [externalSystemName] [nvarchar](50) NOT NULL, + [url] [nvarchar](256) NULL, + [tsAndCs] [nvarchar](max) NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendUserDate] [datetimeoffset](7) NOT NULL, + [securityGuid] [uniqueidentifier] NULL, + [restrictToSSO] [bit] NOT NULL, + [defaultUserGroupId] [int] NULL, + [defaultStaffGroupId] [int] NULL, + [defaultJobRoleId] [int] NULL, + [defaultGradingId] [int] NULL, + [defaultSpecialtyId] [int] NULL, + [defaultLocationId] [int] NULL, + [reportUserId] [int] NULL, + [code] [nvarchar](50) NOT NULL, + CONSTRAINT [PK_externalSystem] PRIMARY KEY CLUSTERED +( + [externalSystemId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] +GO + +ALTER TABLE [elfh].[externalSystemTBL] ADD CONSTRAINT [DF_externalSystemTBL_RestrictToSSO] DEFAULT ((0)) FOR [restrictToSSO] +GO + +ALTER TABLE [elfh].[externalSystemTBL] ADD DEFAULT ('') FOR [code] +GO + diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GdcRegister.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GdcRegister.sql new file mode 100644 index 000000000..560d58995 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GdcRegister.sql @@ -0,0 +1,36 @@ +CREATE TABLE [elfh].[gdcRegisterTBL]( + [reg_number] [nvarchar](50) NOT NULL, + [Dentist] [bit] NOT NULL, + [Title] [nvarchar](50) NULL, + [Surname] [nvarchar](255) NULL, + [Forenames] [nvarchar](255) NULL, + [honorifics] [nvarchar](50) NULL, + [house_name] [nvarchar](255) NULL, + [address_line1] [nvarchar](255) NULL, + [address_line2] [nvarchar](255) NULL, + [address_line3] [nvarchar](255) NULL, + [address_line4] [nvarchar](255) NULL, + [Town] [nvarchar](50) NULL, + [County] [nvarchar](50) NULL, + [PostCode] [nvarchar](50) NULL, + [Country] [nvarchar](50) NULL, + [regdate] [nvarchar](50) NULL, + [qualifications] [nvarchar](1000) NULL, + [dcp_titles] [nvarchar](100) NULL, + [specialties] [nvarchar](100) NULL, + [condition] [nvarchar](50) NULL, + [suspension] [nvarchar](50) NULL, + [dateProcessed] [datetimeoffset](7) NOT NULL, + [action] [nvarchar](1) NULL, + CONSTRAINT [PK_gdcRegisterTBL] PRIMARY KEY CLUSTERED +( + [reg_number] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[gdcRegisterTBL] ADD DEFAULT ((0)) FOR [Dentist] +GO + +ALTER TABLE [elfh].[gdcRegisterTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [dateProcessed] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GmcLrmp.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GmcLrmp.sql new file mode 100644 index 000000000..7d66d14c4 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GmcLrmp.sql @@ -0,0 +1,16 @@ +CREATE TABLE [elfh].[gmclrmpTBL]( + [GMC_Ref_No] [nvarchar](50) NOT NULL, + [Surname] [nvarchar](255) NULL, + [Given_Name] [nvarchar](255) NULL, + [Year_Of_Qualification] [float] NULL, + [GP_Register_Date] [nvarchar](255) NULL, + [Registration_Status] [nvarchar](255) NULL, + [Other_Names] [nvarchar](255) NULL, + [dateProcessed] [datetime] NULL, + [action] [nchar](1) NULL, + CONSTRAINT [PK_gmclrmpTBL] PRIMARY KEY CLUSTERED +( + [GMC_Ref_No] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GradeTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GradeTBL.sql new file mode 100644 index 000000000..c9f7c47df --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/GradeTBL.sql @@ -0,0 +1,20 @@ +CREATE TABLE [elfh].[gradeTBL]( + [gradeId] [int] IDENTITY(1,1) NOT NULL, + [gradeName] [nvarchar](50) NOT NULL, + [displayOrder] [int] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_gradeTBL] PRIMARY KEY CLUSTERED +( + [gradeId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[gradeTBL] ADD CONSTRAINT [DF_gradeTBL_deleted] DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[gradeTBL] ADD CONSTRAINT [DF_gradeTBL_amendDate] DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO + diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/IpCountryLookupTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/IpCountryLookupTBL.sql new file mode 100644 index 000000000..d5bc7f13b --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/IpCountryLookupTBL.sql @@ -0,0 +1,8 @@ +CREATE TABLE [elfh].[ipCountryLookupTBL]( + [fromIP] [varchar](20) NOT NULL, + [toIP] [varchar](20) NOT NULL, + [country] [varchar](10) NOT NULL, + [fromInt] [bigint] NULL, + [toInt] [bigint] NULL +) ON [PRIMARY] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/JobRoleTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/JobRoleTBL.sql new file mode 100644 index 000000000..7bb035683 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/JobRoleTBL.sql @@ -0,0 +1,35 @@ +CREATE TABLE [elfh].[jobRoleTBL]( + [jobRoleId] [int] IDENTITY(1,1) NOT NULL, + [staffGroupId] [int] NULL, + [jobRoleName] [nvarchar](100) NOT NULL, + [medicalCouncilId] [int] NULL, + [displayOrder] [int] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_jobRoleTBL] PRIMARY KEY CLUSTERED +( + [jobRoleId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[jobRoleTBL] ADD CONSTRAINT [DF_jobRoleTBL_deleted] DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[jobRoleTBL] ADD CONSTRAINT [DF_jobRoleTBL_amendDate] DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO + +ALTER TABLE [elfh].[jobRoleTBL] WITH CHECK ADD CONSTRAINT [FK_jobRoleTBL_medicalCouncilTBL] FOREIGN KEY([medicalCouncilId]) +REFERENCES [elfh].[medicalCouncilTBL] ([medicalCouncilId]) +GO + +ALTER TABLE [elfh].[jobRoleTBL] CHECK CONSTRAINT [FK_jobRoleTBL_medicalCouncilTBL] +GO + +ALTER TABLE [elfh].[jobRoleTBL] WITH CHECK ADD CONSTRAINT [FK_jobRoleTBL_staffGroupTBL] FOREIGN KEY([staffGroupId]) +REFERENCES [elfh].[staffGroupTBL] ([staffGroupId]) +GO + +ALTER TABLE [elfh].[jobRoleTBL] CHECK CONSTRAINT [FK_jobRoleTBL_staffGroupTBL] +GO diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/Location.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/Location.sql new file mode 100644 index 000000000..54a0bac86 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/Location.sql @@ -0,0 +1,117 @@ + +CREATE TABLE [elfh].[locationTBL]( + [locationId] [int] NOT NULL, + [locationCode] [nvarchar](50) NOT NULL, + [locationName] [nvarchar](200) NOT NULL, + [locationSubName] [nvarchar](200) NULL, + [locationTypeId] [int] NOT NULL, + [address1] [nvarchar](100) NULL, + [address2] [nvarchar](100) NULL, + [address3] [nvarchar](100) NULL, + [address4] [nvarchar](100) NULL, + [town] [nvarchar](100) NULL, + [county] [nvarchar](100) NULL, + [postCode] [nvarchar](8) NULL, + [telephone] [nvarchar](50) NULL, + [acute] [bit] NOT NULL, + [ambulance] [bit] NOT NULL, + [mental] [bit] NOT NULL, + [care] [bit] NOT NULL, + [mainHosp] [bit] NOT NULL, + [nhsCode] [nvarchar](50) NULL, + [parentId] [int] NOT NULL, + [dataSource] [nvarchar](50) NOT NULL, + [active] [bit] NOT NULL, + [importExclusion] [bit] NOT NULL, + [depth] [int] NULL, + [lineage] [nvarchar](max) NULL, + [created] [datetimeoffset](7) NOT NULL, + [updated] [datetimeoffset](7) NOT NULL, + [archivedDate] [datetimeoffset](7) NULL, + [countryId] [int] NULL, + [iguId] [int] NOT NULL, + [letbId] [int] NOT NULL, + [ccgId] [int] NOT NULL, + [healthServiceId] [int] NOT NULL, + [healthBoardId] [int] NOT NULL, + [primaryTrustId] [int] NOT NULL, + [secondaryTrustId] [int] NOT NULL, + [islandId] [int] NOT NULL, + [otherNHSOrganisationId] [int] NOT NULL, + CONSTRAINT [PK_locationTBL] PRIMARY KEY CLUSTERED +( + [locationId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] +GO + +ALTER TABLE [elfh].[locationTBL] ADD DEFAULT ((0)) FOR [locationTypeId] +GO + +ALTER TABLE [elfh].[locationTBL] ADD CONSTRAINT [DF_locationTBL_Acute] DEFAULT ((0)) FOR [acute] +GO + +ALTER TABLE [elfh].[locationTBL] ADD CONSTRAINT [DF_locationTBL_Ambulance] DEFAULT ((0)) FOR [ambulance] +GO + +ALTER TABLE [elfh].[locationTBL] ADD CONSTRAINT [DF_locationTBL_Mental] DEFAULT ((0)) FOR [mental] +GO + +ALTER TABLE [elfh].[locationTBL] ADD CONSTRAINT [DF_locationTBL_Care] DEFAULT ((0)) FOR [care] +GO + +ALTER TABLE [elfh].[locationTBL] ADD CONSTRAINT [DF_locationTBL_MainHosp] DEFAULT ((0)) FOR [mainHosp] +GO + +ALTER TABLE [elfh].[locationTBL] ADD CONSTRAINT [DF_locationTBL_Active] DEFAULT ((1)) FOR [active] +GO + +ALTER TABLE [elfh].[locationTBL] ADD CONSTRAINT [DF_locationTBL_ImportExclusion] DEFAULT ((0)) FOR [importExclusion] +GO + +ALTER TABLE [elfh].[locationTBL] ADD CONSTRAINT [DF_locationTBL_created] DEFAULT (sysdatetimeoffset()) FOR [created] +GO + +ALTER TABLE [elfh].[locationTBL] ADD CONSTRAINT [DF_locationTBL_updated] DEFAULT (sysdatetimeoffset()) FOR [updated] +GO + +ALTER TABLE [elfh].[locationTBL] ADD DEFAULT ((0)) FOR [iguId] +GO + +ALTER TABLE [elfh].[locationTBL] ADD DEFAULT ((0)) FOR [letbId] +GO + +ALTER TABLE [elfh].[locationTBL] ADD DEFAULT ((0)) FOR [ccgId] +GO + +ALTER TABLE [elfh].[locationTBL] ADD DEFAULT ((0)) FOR [healthServiceId] +GO + +ALTER TABLE [elfh].[locationTBL] ADD DEFAULT ((0)) FOR [healthBoardId] +GO + +ALTER TABLE [elfh].[locationTBL] ADD DEFAULT ((0)) FOR [primaryTrustId] +GO + +ALTER TABLE [elfh].[locationTBL] ADD DEFAULT ((0)) FOR [secondaryTrustId] +GO + +ALTER TABLE [elfh].[locationTBL] ADD DEFAULT ((0)) FOR [islandId] +GO + +ALTER TABLE [elfh].[locationTBL] ADD DEFAULT ((0)) FOR [otherNHSOrganisationId] +GO + +ALTER TABLE [elfh].[locationTBL] WITH CHECK ADD CONSTRAINT [FK_locationTBL_countryTBL] FOREIGN KEY([countryId]) +REFERENCES [elfh].[countryTBL] ([countryId]) +GO + +ALTER TABLE [elfh].[locationTBL] CHECK CONSTRAINT [FK_locationTBL_countryTBL] +GO + +ALTER TABLE [elfh].[locationTBL] WITH CHECK ADD CONSTRAINT [FK_locationTBL_locationTypeTBL] FOREIGN KEY([locationTypeId]) +REFERENCES [elfh].[locationTypeTBL] ([locationTypeID]) +GO + +ALTER TABLE [elfh].[locationTBL] CHECK CONSTRAINT [FK_locationTBL_locationTypeTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/LoginWizardRuleTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/LoginWizardRuleTBL.sql new file mode 100644 index 000000000..536df2f89 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/LoginWizardRuleTBL.sql @@ -0,0 +1,25 @@ +CREATE TABLE [elfh].[loginWizardRuleTBL]( + [loginWizardRuleId] [int] NOT NULL, + [loginWizardStageId] [int] NOT NULL, + [loginWizardRuleCategoryId] [int] NOT NULL, + [description] [nvarchar](128) NOT NULL, + [reasonDisplayText] [nvarchar](1024) NOT NULL, + [activationPeriod] [int] NULL, + [required] [bit] NOT NULL, + [active] [bit] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_loginWizardRule] PRIMARY KEY CLUSTERED +( + [loginWizardRuleId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[loginWizardRuleTBL] WITH CHECK ADD CONSTRAINT [FK_loginWizardRuleTBL_loginWizardStageTBL] FOREIGN KEY([loginWizardStageId]) +REFERENCES [elfh].[loginWizardStageTBL] ([loginWizardStageId]) +GO + +ALTER TABLE [elfh].[loginWizardRuleTBL] CHECK CONSTRAINT [FK_loginWizardRuleTBL_loginWizardStageTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/LoginWizardStageActivityTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/LoginWizardStageActivityTBL.sql new file mode 100644 index 000000000..5c8a60fc2 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/LoginWizardStageActivityTBL.sql @@ -0,0 +1,25 @@ +CREATE TABLE [elfh].[loginWizardStageActivityTBL]( + [loginWizardStageActivityId] [int] IDENTITY(1,1) NOT NULL, + [loginWizardStageId] [int] NOT NULL, + [userId] [int] NOT NULL, + [activityDatetime] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_loginWizardStageActivityTBL] PRIMARY KEY CLUSTERED +( + [loginWizardStageActivityId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[loginWizardStageActivityTBL] WITH CHECK ADD CONSTRAINT [FK_loginWizardStageActivityTBL_loginWizardStageTBL] FOREIGN KEY([loginWizardStageId]) +REFERENCES [elfh].[loginWizardStageTBL] ([loginWizardStageId]) +GO + +ALTER TABLE [elfh].[loginWizardStageActivityTBL] CHECK CONSTRAINT [FK_loginWizardStageActivityTBL_loginWizardStageTBL] +GO + +ALTER TABLE [elfh].[loginWizardStageActivityTBL] WITH CHECK ADD CONSTRAINT [FK_loginWizardStageActivityTBL_userTBL] FOREIGN KEY([userId]) +REFERENCES [hub].[User] ([Id]) +GO + +ALTER TABLE [elfh].[loginWizardStageActivityTBL] CHECK CONSTRAINT [FK_loginWizardStageActivityTBL_userTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/MedicalCouncilTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/MedicalCouncilTBL.sql new file mode 100644 index 000000000..1eee676b8 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/MedicalCouncilTBL.sql @@ -0,0 +1,24 @@ +CREATE TABLE [elfh].[medicalCouncilTBL]( + [medicalCouncilId] [int] NOT NULL, + [medicalCouncilName] [nvarchar](50) NOT NULL, + [medicalCouncilCode] [nvarchar](50) NOT NULL, + [uploadPrefix] [nvarchar](3) NOT NULL, + [includeOnCerts] [bit] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_medicalCouncilTBL] PRIMARY KEY CLUSTERED +( + [medicalCouncilId] 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 [elfh].[medicalCouncilTBL] ADD CONSTRAINT [DF_medicalCouncilTBL_includeOnCerts] DEFAULT ((0)) FOR [includeOnCerts] +GO + +ALTER TABLE [elfh].[medicalCouncilTBL] ADD CONSTRAINT [DF_medicalCouncilTBL_deleted] DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[medicalCouncilTBL] ADD CONSTRAINT [DF_medicalCouncilTBL_amendDate] DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/RegionTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/RegionTBL.sql new file mode 100644 index 000000000..e3de79cde --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/RegionTBL.sql @@ -0,0 +1,16 @@ +CREATE TABLE [elfh].[regionTBL]( + [regionId] [int] NOT NULL, + [regionName] [nvarchar](100) NOT NULL, + [displayOrder] [int] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_regionTbl] PRIMARY KEY CLUSTERED +( + [regionId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[regionTBL] ADD CONSTRAINT [DF_regionTbl_deleted] DEFAULT ((0)) FOR [deleted] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SchoolTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SchoolTBL.sql new file mode 100644 index 000000000..b0ef70ea2 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SchoolTBL.sql @@ -0,0 +1,29 @@ +CREATE TABLE [elfh].[schoolTBL]( + [schoolId] [int] IDENTITY(1,1) NOT NULL, + [deaneryId] [int] NOT NULL, + [specialtyId] [int] NOT NULL, + [schoolName] [nvarchar](50) NOT NULL, + [displayOrder] [int] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_schoolTBL] PRIMARY KEY CLUSTERED +( + [schoolId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[schoolTBL] WITH CHECK ADD CONSTRAINT [FK_schoolTBL_deaneryTBL] FOREIGN KEY([deaneryId]) +REFERENCES [elfh].[deaneryTBL] ([deaneryId]) +GO + +ALTER TABLE [elfh].[schoolTBL] CHECK CONSTRAINT [FK_schoolTBL_deaneryTBL] +GO + +ALTER TABLE [elfh].[schoolTBL] WITH CHECK ADD CONSTRAINT [FK_schoolTBL_specialtyTBL] FOREIGN KEY([specialtyId]) +REFERENCES [elfh].[specialtyTBL] ([specialtyId]) +GO + +ALTER TABLE [elfh].[schoolTBL] CHECK CONSTRAINT [FK_schoolTBL_specialtyTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SpecialtyTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SpecialtyTBL.sql new file mode 100644 index 000000000..dd2fcf677 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SpecialtyTBL.sql @@ -0,0 +1,19 @@ +CREATE TABLE [elfh].[specialtyTBL]( + [specialtyId] [int] IDENTITY(1,1) NOT NULL, + [specialtyName] [nvarchar](50) NOT NULL, + [displayOrder] [int] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_specialtyTBL] PRIMARY KEY CLUSTERED +( + [specialtyId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[specialtyTBL] ADD CONSTRAINT [DF_specialty_deleted] DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[specialtyTBL] ADD CONSTRAINT [DF_specialtyTBL_amendDate] DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/StaffGroupTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/StaffGroupTBL.sql new file mode 100644 index 000000000..e2ffb9bf0 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/StaffGroupTBL.sql @@ -0,0 +1,17 @@ +CREATE TABLE [elfh].[staffGroupTBL]( + [staffGroupId] [int] IDENTITY(1,1) NOT NULL, + [staffGroupName] [nvarchar](50) NOT NULL, + [displayOrder] [int] NOT NULL, + [internalUsersOnly] [bit] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_staffGroupTBL] PRIMARY KEY CLUSTERED +( + [staffGroupId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[staffGroupTBL] ADD CONSTRAINT [DF_staffGroupTBL_internalUsersOnly] DEFAULT ((0)) FOR [internalUsersOnly] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SystemSettingTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SystemSettingTBL.sql new file mode 100644 index 000000000..8ead0a47c --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/SystemSettingTBL.sql @@ -0,0 +1,24 @@ +CREATE TABLE [elfh].[systemSettingTBL]( + [systemSettingId] [int] NOT NULL, + [systemSettingName] [nvarchar](50) NOT NULL, + [intValue] [int] NULL, + [textValue] [nvarchar](255) NULL, + [booleanValue] [bit] NULL, + [dateValue] [datetimeoffset](7) NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_systemSettingsTBL] PRIMARY KEY CLUSTERED +( + [systemSettingId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[systemSettingTBL] ADD DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[systemSettingTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO + + diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantSmtpTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantSmtpTBL.sql new file mode 100644 index 000000000..390c1a123 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantSmtpTBL.sql @@ -0,0 +1,16 @@ +CREATE TABLE [elfh].[tenantSmtpTBL]( + [tenantId] [int] NOT NULL, + [deliveryMethod] [nvarchar](128) NOT NULL, + [pickupDirectoryLocation] [nvarchar](256) NULL, + [from] [nvarchar](256) NULL, + [userName] [nvarchar](256) NULL, + [password] [nvarchar](256) NULL, + [enableSsl] [bit] NULL, + [host] [nvarchar](256) NULL, + [port] [int] NULL, + [active] [bit] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL +) ON [PRIMARY] +GO diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantTBL.sql new file mode 100644 index 000000000..47fb44f17 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantTBL.sql @@ -0,0 +1,43 @@ +CREATE TABLE [elfh].[tenantTBL]( + [tenantId] [int] NOT NULL, + [tenantCode] [nvarchar](20) NOT NULL, + [tenantName] [nvarchar](64) NOT NULL, + [tenantDescription] [nvarchar](1024) NOT NULL, + [showFullCatalogInfoMessageInd] [bit] NOT NULL, + [catalogUrl] [nvarchar](256) NOT NULL, + [quickStartGuideUrl] [nvarchar](1024) NULL, + [supportFormUrl] [nvarchar](1024) NULL, + [liveChatStatus] [int] NOT NULL, + [liveChatSnippet] [nvarchar](2048) NULL, + [myElearningDefaultView] [int] NOT NULL, + [preLoginCatalogueDefaultView] [int] NOT NULL, + [postLoginCatalogueDefaultView] [int] NOT NULL, + [authSignInUrlRelative] [nvarchar](1024) NULL, + [authSignOutUrlRelative] [nvarchar](1024) NULL, + [authSecret] [uniqueidentifier] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_tenantTBL] PRIMARY KEY CLUSTERED +( + [tenantId] 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 [elfh].[tenantTBL] ADD DEFAULT ((0)) FOR [liveChatStatus] +GO + +ALTER TABLE [elfh].[tenantTBL] ADD DEFAULT ((0)) FOR [myElearningDefaultView] +GO + +ALTER TABLE [elfh].[tenantTBL] ADD DEFAULT ((0)) FOR [preLoginCatalogueDefaultView] +GO + +ALTER TABLE [elfh].[tenantTBL] ADD DEFAULT ((0)) FOR [postLoginCatalogueDefaultView] +GO + +ALTER TABLE [elfh].[tenantTBL] ADD DEFAULT (newid()) FOR [authSecret] +GO + + diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantUrlTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantUrlTBL.sql new file mode 100644 index 000000000..f1698eafa --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TenantUrlTBL.sql @@ -0,0 +1,24 @@ +CREATE TABLE [elfh].[tenantUrlTBL]( + [tenantUrlId] [int] IDENTITY(1,1) NOT NULL, + [tenantId] [int] NOT NULL, + [urlHostName] [nvarchar](128) NOT NULL, + [useHostForAuth] [bit] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_tenantUrlTBL] PRIMARY KEY CLUSTERED +( + [tenantUrlId] 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 [elfh].[tenantUrlTBL] ADD DEFAULT ((0)) FOR [useHostForAuth] +GO + +ALTER TABLE [elfh].[tenantUrlTBL] WITH CHECK ADD CONSTRAINT [FK_tenantUrlTBL_tenantTBL] FOREIGN KEY([tenantId]) +REFERENCES [elfh].[tenantTBL] ([tenantId]) +GO + +ALTER TABLE [elfh].[tenantUrlTBL] CHECK CONSTRAINT [FK_tenantUrlTBL_tenantTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TermsAndConditionsTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TermsAndConditionsTBL.sql new file mode 100644 index 000000000..c2e581994 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/TermsAndConditionsTBL.sql @@ -0,0 +1,27 @@ +CREATE TABLE [elfh].[termsAndConditionsTBL]( + [termsAndConditionsId] [int] IDENTITY(1,1) NOT NULL, + [createdDate] [datetimeoffset](7) NOT NULL, + [description] [nvarchar](512) NOT NULL, + [details] [ntext] NOT NULL, + [tenantId] [int] NOT NULL, + [active] [bit] NOT NULL, + [reportable] [bit] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_termsAndConditions] PRIMARY KEY CLUSTERED +( + [termsAndConditionsId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] +GO + +ALTER TABLE [elfh].[termsAndConditionsTBL] ADD DEFAULT ((1)) FOR [reportable] +GO + +ALTER TABLE [elfh].[termsAndConditionsTBL] WITH CHECK ADD CONSTRAINT [FK_termsAndConditionsTBL_tenantTBL] FOREIGN KEY([tenantId]) +REFERENCES [elfh].[tenantTBL] ([tenantId]) +GO + +ALTER TABLE [elfh].[termsAndConditionsTBL] CHECK CONSTRAINT [FK_termsAndConditionsTBL_tenantTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserAttributeTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserAttributeTBL.sql new file mode 100644 index 000000000..bf9969af6 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserAttributeTBL.sql @@ -0,0 +1,37 @@ +CREATE TABLE [elfh].[userAttributeTBL]( + [userAttributeId] [int] IDENTITY(1,1) NOT NULL, + [userId] [int] NOT NULL, + [attributeId] [int] NOT NULL, + [intValue] [int] NULL, + [textValue] [nvarchar](255) NULL, + [booleanValue] [bit] NULL, + [dateValue] [datetimeoffset](7) NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_userAttributeTBL] PRIMARY KEY CLUSTERED +( + [userAttributeId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[userAttributeTBL] ADD DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[userAttributeTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO + +ALTER TABLE [elfh].[userAttributeTBL] WITH CHECK ADD CONSTRAINT [FK_userAttributeTBL_attributeId] FOREIGN KEY([attributeId]) +REFERENCES [elfh].[attributeTBL] ([attributeId]) +GO + +ALTER TABLE [elfh].[userAttributeTBL] CHECK CONSTRAINT [FK_userAttributeTBL_attributeId] +GO + +ALTER TABLE [elfh].[userAttributeTBL] WITH CHECK ADD CONSTRAINT [FK_userAttributeTBL_userId] FOREIGN KEY([userId]) +REFERENCES [hub].[User] ([Id]) +GO + +ALTER TABLE [elfh].[userAttributeTBL] CHECK CONSTRAINT [FK_userAttributeTBL_userId] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentTBL.sql new file mode 100644 index 000000000..f43db0eec --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentTBL.sql @@ -0,0 +1,85 @@ + +CREATE TABLE [elfh].[userEmploymentTBL]( + [userEmploymentId] [int] IDENTITY(1,1) NOT NULL, + [userId] [int] NOT NULL, + [jobRoleId] [int] NULL, + [specialtyId] [int] NULL, + [gradeId] [int] NULL, + [schoolId] [int] NULL, + [locationId] [int] NOT NULL, + [medicalCouncilId] [int] NULL, + [medicalCouncilNo] [nvarchar](50) NULL, + [startDate] [datetimeoffset](7) NULL, + [endDate] [datetimeoffset](7) NULL, + [deleted] [bit] NOT NULL, + [archived] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_userEmploymentTBL] PRIMARY KEY CLUSTERED +( + [userEmploymentId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[userEmploymentTBL] ADD CONSTRAINT [DF_userEmploymentTBL_deleted] DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[userEmploymentTBL] ADD CONSTRAINT [DF_userEmploymentTBL_archived] DEFAULT ((0)) FOR [archived] +GO + +ALTER TABLE [elfh].[userEmploymentTBL] WITH CHECK ADD CONSTRAINT [FK_userEmploymentTBL_gradeTBL] FOREIGN KEY([gradeId]) +REFERENCES [elfh].[gradeTBL] ([gradeId]) +GO + +ALTER TABLE [elfh].[userEmploymentTBL] CHECK CONSTRAINT [FK_userEmploymentTBL_gradeTBL] +GO + +ALTER TABLE [elfh].[userEmploymentTBL] WITH CHECK ADD CONSTRAINT [FK_userEmploymentTBL_jobRoleTBL] FOREIGN KEY([jobRoleId]) +REFERENCES [elfh].[jobRoleTBL] ([jobRoleId]) +GO + +ALTER TABLE [elfh].[userEmploymentTBL] CHECK CONSTRAINT [FK_userEmploymentTBL_jobRoleTBL] +GO + +ALTER TABLE [elfh].[userEmploymentTBL] WITH CHECK ADD CONSTRAINT [FK_userEmploymentTBL_locationTBL] FOREIGN KEY([locationId]) +REFERENCES [elfh].[locationTBL] ([locationId]) +GO + +ALTER TABLE [elfh].[userEmploymentTBL] CHECK CONSTRAINT [FK_userEmploymentTBL_locationTBL] +GO + +ALTER TABLE [elfh].[userEmploymentTBL] WITH CHECK ADD CONSTRAINT [FK_userEmploymentTBL_medicalCouncilTBL] FOREIGN KEY([medicalCouncilId]) +REFERENCES [elfh].[medicalCouncilTBL] ([medicalCouncilId]) +GO + +ALTER TABLE [elfh].[userEmploymentTBL] CHECK CONSTRAINT [FK_userEmploymentTBL_medicalCouncilTBL] +GO + +ALTER TABLE [elfh].[userEmploymentTBL] WITH CHECK ADD CONSTRAINT [FK_userEmploymentTBL_schoolTBL] FOREIGN KEY([schoolId]) +REFERENCES [elfh].[schoolTBL] ([schoolId]) +GO + +ALTER TABLE [elfh].[userEmploymentTBL] CHECK CONSTRAINT [FK_userEmploymentTBL_schoolTBL] +GO + +ALTER TABLE [elfh].[userEmploymentTBL] WITH CHECK ADD CONSTRAINT [FK_userEmploymentTBL_specialtyTBL] FOREIGN KEY([specialtyId]) +REFERENCES [elfh].[specialtyTBL] ([specialtyId]) +GO + +ALTER TABLE [elfh].[userEmploymentTBL] CHECK CONSTRAINT [FK_userEmploymentTBL_specialtyTBL] +GO + +ALTER TABLE [elfh].[userEmploymentTBL] WITH CHECK ADD CONSTRAINT [FK_userEmploymentTBL_userTBL] FOREIGN KEY([userId]) +REFERENCES [hub].[User] ([Id]) +GO + +ALTER TABLE [elfh].[userEmploymentTBL] CHECK CONSTRAINT [FK_userEmploymentTBL_userTBL] +GO + +ALTER TABLE [elfh].[userEmploymentTBL] WITH CHECK ADD CONSTRAINT [FK_userEmploymentTBL_userTBL_AmendUser] FOREIGN KEY([amendUserId]) +REFERENCES [hub].[User] ([Id]) +GO + +ALTER TABLE [elfh].[userEmploymentTBL] CHECK CONSTRAINT [FK_userEmploymentTBL_userTBL_AmendUser] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserGroupTypeInputValidationTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserGroupTypeInputValidationTBL.sql new file mode 100644 index 000000000..dc2fd76dd --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserGroupTypeInputValidationTBL.sql @@ -0,0 +1,39 @@ +CREATE TABLE [elfh].[userGroupTypeInputValidationTBL]( + [userGroupTypeInputValidationId] [int] IDENTITY(1,1) NOT NULL, + [userGroupId] [int] NOT NULL, + [userGroupTypePrefix] [nvarchar](10) NOT NULL, + [userGroupTypeId] [int] NOT NULL, + [validationTextValue] [nvarchar](1000) NOT NULL, + [validationMethod] [int] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + [createdUserId] [int] NOT NULL, + [createdDate] [datetimeoffset](7) NOT NULL, +PRIMARY KEY CLUSTERED +( + [userGroupTypeInputValidationId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY], + CONSTRAINT [UQ_userGroupTypeInputValidationTBL_userGroupId_validationTextValue] UNIQUE NONCLUSTERED +( + [userGroupId] ASC, + [validationTextValue] 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 [elfh].[userGroupTypeInputValidationTBL] ADD DEFAULT (N'USR TYP:') FOR [userGroupTypePrefix] +GO + +ALTER TABLE [elfh].[userGroupTypeInputValidationTBL] ADD DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[userGroupTypeInputValidationTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO + +ALTER TABLE [elfh].[userGroupTypeInputValidationTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [createdDate] +GO + +ALTER TABLE [elfh].[userGroupTypeInputValidationTBL] WITH CHECK ADD CONSTRAINT [FK_userGroupTypeInputValidationTBL_amendUserTBL] FOREIGN KEY([amendUserId]) +REFERENCES [hub].[User] ([Id]) +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserHistoryAttributeTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserHistoryAttributeTBL.sql new file mode 100644 index 000000000..0ab661329 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserHistoryAttributeTBL.sql @@ -0,0 +1,39 @@ +CREATE TABLE [elfh].[userHistoryAttributeTBL]( + [userHistoryAttributeId] [int] IDENTITY(1,1) NOT NULL, + [userHistoryId] [int] NOT NULL, + [attributeId] [int] NOT NULL, + [intValue] [int] NULL, + [textValue] [nvarchar](1000) NULL, + [booleanValue] [bit] NULL, + [dateValue] [datetimeoffset](7) NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_userHistoryAttributeTBL] PRIMARY KEY CLUSTERED +( + [userHistoryAttributeId] 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 [elfh].[userHistoryAttributeTBL] ADD CONSTRAINT [DF_userHistoryAttributeTBL_deleted] DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[userHistoryAttributeTBL] ADD CONSTRAINT [DF_userHistoryAttributeTBL_amendDate] DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO + +ALTER TABLE [elfh].[userHistoryAttributeTBL] WITH CHECK ADD CONSTRAINT [FK_userHistoryAttributeTBL_attributeId] FOREIGN KEY([attributeId]) +REFERENCES [elfh].[attributeTBL] ([attributeId]) +GO + +ALTER TABLE [elfh].[userHistoryAttributeTBL] CHECK CONSTRAINT [FK_userHistoryAttributeTBL_attributeId] +GO + +ALTER TABLE [elfh].[userHistoryAttributeTBL] WITH CHECK ADD CONSTRAINT [FK_userHistoryAttributeTBL_userHistoryId] FOREIGN KEY([userHistoryId]) +REFERENCES [elfh].[userHistoryTBL] ([userHistoryId]) +GO + +ALTER TABLE [elfh].[userHistoryAttributeTBL] CHECK CONSTRAINT [FK_userHistoryAttributeTBL_userHistoryId] +GO + + diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserHistoryTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserHistoryTBL.sql new file mode 100644 index 000000000..12a25fc81 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserHistoryTBL.sql @@ -0,0 +1,25 @@ +CREATE TABLE [elfh].[userHistoryTBL]( + [userHistoryId] [int] IDENTITY(1,1) NOT NULL, + [userHistoryTypeId] [int] NOT NULL, + [userId] [int] NOT NULL, + [createdDate] [datetimeoffset](7) NOT NULL, + [tenantId] [int] NOT NULL, +PRIMARY KEY CLUSTERED +( + [userHistoryId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[userHistoryTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [createdDate] +GO + +ALTER TABLE [elfh].[userHistoryTBL] ADD DEFAULT ((0)) FOR [tenantId] +GO + +ALTER TABLE [elfh].[userHistoryTBL] WITH CHECK ADD CONSTRAINT [FK_userHistoryTBL_userHistoryTypeTBL] FOREIGN KEY([userHistoryTypeId]) +REFERENCES [elfh].[userHistoryTypeTBL] ([UserHistoryTypeId]) +GO + +ALTER TABLE [elfh].[userHistoryTBL] CHECK CONSTRAINT [FK_userHistoryTBL_userHistoryTypeTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserPasswordValidationTokenTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserPasswordValidationTokenTBL.sql new file mode 100644 index 000000000..7beed21ce --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserPasswordValidationTokenTBL.sql @@ -0,0 +1,33 @@ +CREATE TABLE [elfh].[userPasswordValidationTokenTBL]( + [userPasswordValidationTokenId] [int] IDENTITY(1,1) NOT NULL, + [hashedToken] [nvarchar](128) NOT NULL, + [salt] [nvarchar](128) NOT NULL, + [lookup] [nvarchar](128) NOT NULL, + [expiry] [datetimeoffset](7) NOT NULL, + [tenantId] [int] NOT NULL, + [userId] [int] NOT NULL, + [createdUserId] [int] NOT NULL, + [createdDate] [datetimeoffset](7) NOT NULL, +PRIMARY KEY CLUSTERED +( + [userPasswordValidationTokenId] 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 [elfh].[userPasswordValidationTokenTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [createdDate] +GO + +ALTER TABLE [elfh].[userPasswordValidationTokenTBL] WITH CHECK ADD CONSTRAINT [FK_userPasswordValidationTokenTBL_tenantTBL] FOREIGN KEY([tenantId]) +REFERENCES [elfh].[tenantTBL] ([tenantId]) +GO + +ALTER TABLE [elfh].[userPasswordValidationTokenTBL] CHECK CONSTRAINT [FK_userPasswordValidationTokenTBL_tenantTBL] +GO + +ALTER TABLE [elfh].[userPasswordValidationTokenTBL] WITH CHECK ADD CONSTRAINT [FK_userPasswordValidationTokenTBL_userTBL] FOREIGN KEY([userId]) +REFERENCES [hub].[User] ([Id]) +GO + +ALTER TABLE [elfh].[userPasswordValidationTokenTBL] CHECK CONSTRAINT [FK_userPasswordValidationTokenTBL_userTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserRoleUpgradeTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserRoleUpgradeTBL.sql new file mode 100644 index 000000000..c5f00d25d --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserRoleUpgradeTBL.sql @@ -0,0 +1,35 @@ +CREATE TABLE [elfh].[userRoleUpgradeTBL]( + [userRoleUpgradeId] [int] IDENTITY(1,1) NOT NULL, + [userId] [int] NOT NULL, + [emailAddress] [nvarchar](100) NOT NULL, + [upgradeDate] [datetimeoffset](7) NULL, + [deleted] [bit] NOT NULL, + [createUserId] [int] NOT NULL, + [createDate] [datetimeoffset](7) NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + [userHistoryTypeId] [int] NOT NULL, + CONSTRAINT [PK_userRoleUpgrade] PRIMARY KEY CLUSTERED +( + [userRoleUpgradeId] 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 [elfh].[userRoleUpgradeTBL] ADD DEFAULT ((12)) FOR [userHistoryTypeId] +GO + +ALTER TABLE [elfh].[userRoleUpgradeTBL] WITH CHECK ADD CONSTRAINT [FK_userRoleUpgradeTBL_userHistoryTypeTBL] FOREIGN KEY([userHistoryTypeId]) +REFERENCES [elfh].[userHistoryTypeTBL] ([UserHistoryTypeId]) +GO + +ALTER TABLE [elfh].[userRoleUpgradeTBL] CHECK CONSTRAINT [FK_userRoleUpgradeTBL_userHistoryTypeTBL] +GO + +ALTER TABLE [elfh].[userRoleUpgradeTBL] WITH CHECK ADD CONSTRAINT [FK_userRoleUpgradeTbl_userTbl] FOREIGN KEY([userId]) +REFERENCES [hub].[User] ([Id]) +GO + +ALTER TABLE [elfh].[userRoleUpgradeTBL] CHECK CONSTRAINT [FK_userRoleUpgradeTbl_userTbl] +GO + diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserTermsAndConditionsTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserTermsAndConditionsTBL.sql new file mode 100644 index 000000000..66e86902d --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserTermsAndConditionsTBL.sql @@ -0,0 +1,28 @@ +CREATE TABLE [elfh].[userTermsAndConditionsTBL]( + [userTermsAndConditionsId] [int] IDENTITY(1,1) NOT NULL, + [termsAndConditionsId] [int] NOT NULL, + [userId] [int] NOT NULL, + [acceptanceDate] [datetimeoffset](7) NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserID] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_userTermsAndConditions] PRIMARY KEY CLUSTERED +( + [userTermsAndConditionsId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[userTermsAndConditionsTBL] WITH CHECK ADD CONSTRAINT [FK_userTermsAndConditionsTBL_portalUserTBL] FOREIGN KEY([userId]) +REFERENCES [hub].[User] ([Id]) +GO + +ALTER TABLE [elfh].[userTermsAndConditionsTBL] CHECK CONSTRAINT [FK_userTermsAndConditionsTBL_portalUserTBL] +GO + +ALTER TABLE [elfh].[userTermsAndConditionsTBL] WITH CHECK ADD CONSTRAINT [FK_userTermsAndConditionsTBL_termsAndConditionsTBL] FOREIGN KEY([termsAndConditionsId]) +REFERENCES [elfh].[termsAndConditionsTBL] ([termsAndConditionsId]) +GO + +ALTER TABLE [elfh].[userTermsAndConditionsTBL] CHECK CONSTRAINT [FK_userTermsAndConditionsTBL_termsAndConditionsTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/locationTypeTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/locationTypeTBL.sql new file mode 100644 index 000000000..cf10e09b5 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/locationTypeTBL.sql @@ -0,0 +1,34 @@ +CREATE TABLE [elfh].[locationTypeTBL]( + [locationTypeID] [int] IDENTITY(1,1) NOT NULL, + [locationType] [nvarchar](50) NOT NULL, + [countryId] [int] NULL, + [healthService] [bit] NOT NULL, + [healthBoard] [bit] NOT NULL, + [primaryTrust] [bit] NOT NULL, + [secondaryTrust] [bit] NOT NULL, + CONSTRAINT [PK_locationType] PRIMARY KEY CLUSTERED +( + [locationTypeID] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[locationTypeTBL] ADD DEFAULT ((0)) FOR [healthService] +GO + +ALTER TABLE [elfh].[locationTypeTBL] ADD DEFAULT ((0)) FOR [healthBoard] +GO + +ALTER TABLE [elfh].[locationTypeTBL] ADD DEFAULT ((0)) FOR [primaryTrust] +GO + +ALTER TABLE [elfh].[locationTypeTBL] ADD DEFAULT ((0)) FOR [secondaryTrust] +GO + +ALTER TABLE [elfh].[locationTypeTBL] WITH CHECK ADD CONSTRAINT [FK_locationTypeTBL_countryTBL] FOREIGN KEY([countryId]) +REFERENCES [elfh].[countryTBL] ([countryId]) +GO + +ALTER TABLE [elfh].[locationTypeTBL] CHECK CONSTRAINT [FK_locationTypeTBL_countryTBL] +GO + diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/loginWizardStageTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/loginWizardStageTBL.sql new file mode 100644 index 000000000..ae704a35d --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/loginWizardStageTBL.sql @@ -0,0 +1,13 @@ +CREATE TABLE [elfh].[loginWizardStageTBL]( + [loginWizardStageId] [int] NOT NULL, + [description] [nvarchar](128) NOT NULL, + [reasonDisplayText] [nvarchar](1024) NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_loginWizardStageTBL] PRIMARY KEY CLUSTERED +( + [loginWizardStageId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] +) ON [PRIMARY] +GO diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/userHistoryTypeTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/userHistoryTypeTBL.sql new file mode 100644 index 000000000..95e58af92 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/userHistoryTypeTBL.sql @@ -0,0 +1,9 @@ +CREATE TABLE [elfh].[userHistoryTypeTBL]( + [UserHistoryTypeId] [int] NOT NULL, + [Description] [nvarchar](100) NOT NULL, +PRIMARY KEY CLUSTERED +( + [UserHistoryTypeId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Hub/User.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Hub/User.sql index 20abd7d3c..eb2d34132 100644 --- a/WebAPI/LearningHub.Nhs.Database/Tables/Hub/User.sql +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Hub/User.sql @@ -1,6 +1,24 @@ CREATE TABLE [hub].[User]( [Id] [int] NOT NULL, [UserName] [nvarchar](50) NOT NULL, + [countryId] [int] NULL, + [registrationCode] [nvarchar](50) NULL, + [activeFromDate] [datetimeoffset](7) NULL, + [activeToDate] [datetimeoffset](7) NULL, + [passwordHash] [nvarchar](255) NULL, + [mustChangeNextLogin] [bit] NULL, + [passwordLifeCounter] [int] NULL, + [securityLifeCounter] [int] NULL, + [RemoteLoginKey] [nvarchar](50) NULL, + [RemoteLoginGuid] [uniqueidentifier] NULL, + [RemoteLoginStart] [datetimeoffset](7) NULL, + [RestrictToSSO] [bit] NULL, + [loginTimes] [int] NULL, + [loginWizardInProgress] [bit] NULL, + [lastLoginWizardCompleted] [datetimeoffset](7) NULL, + [primaryUserEmploymentId] [int] NULL, + [regionId] [int] NULL, + [preferredTenantId] [int] NULL, [CreateUserId] [int] NOT NULL, [CreateDate] [datetimeoffset](7) NOT NULL, [AmendUserId] [int] NOT NULL, @@ -26,6 +44,37 @@ GO ALTER TABLE [hub].[User] ADD DEFAULT (CONVERT([datetime2],'9999-12-31 23:59:59.9999999')) FOR [VersionEndTime] GO + +ALTER TABLE [hub].[User] ADD CONSTRAINT [DF_userTBL_passwordLifeCounter] DEFAULT ((0)) FOR [passwordLifeCounter] +GO + +ALTER TABLE [hub].[User] ADD CONSTRAINT [DF_userTBL_securityLifeCounter] DEFAULT ((0)) FOR [securityLifeCounter] +GO + +ALTER TABLE [hub].[User] ADD CONSTRAINT [DF_userTBL_RestrictToSSO] DEFAULT ((0)) FOR [RestrictToSSO] +GO + +ALTER TABLE [hub].[User] WITH CHECK ADD CONSTRAINT [FK_userTBL_countryTBL] FOREIGN KEY([countryId]) +REFERENCES [elfh].[countryTBL] ([countryId]) +GO + +ALTER TABLE [hub].[User] CHECK CONSTRAINT [FK_userTBL_countryTBL] +GO + +ALTER TABLE [hub].[User] WITH CHECK ADD CONSTRAINT [FK_userTBL_regionTBL] FOREIGN KEY([regionId]) +REFERENCES [elfh].[regionTBL] ([regionId]) +GO + +ALTER TABLE [hub].[User] CHECK CONSTRAINT [FK_userTBL_regionTBL] +GO + +ALTER TABLE [hub].[User] WITH CHECK ADD CONSTRAINT [FK_userTBL_userEmploymentTBL] FOREIGN KEY([primaryUserEmploymentId]) +REFERENCES [elfh].[userEmploymentTBL] ([userEmploymentId]) +GO + +ALTER TABLE [hub].[User] CHECK CONSTRAINT [FK_userTBL_userEmploymentTBL] +GO + CREATE INDEX idx_User_Deleted ON hub.[User] (Deleted) include (UserName) WITH (FILLFACTOR = 95); GO From ebead60914e9306aa517a8473febe5805c887ac2 Mon Sep 17 00:00:00 2001 From: OluwatobiAwe Date: Wed, 1 Oct 2025 07:08:08 +0100 Subject: [PATCH 2/5] updated user profile table --- WebAPI/LearningHub.Nhs.Database/Tables/Hub/UserProfile.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Hub/UserProfile.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Hub/UserProfile.sql index 890cabfb7..aa7032ef9 100644 --- a/WebAPI/LearningHub.Nhs.Database/Tables/Hub/UserProfile.sql +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Hub/UserProfile.sql @@ -2,8 +2,10 @@ [Id] [int] NOT NULL, [UserName] [nvarchar](50) NOT NULL, [EmailAddress] [nvarchar](100) NOT NULL, + [AltEmailAddress] [nvarchar](100) NULL, [FirstName] [nvarchar](50) NOT NULL, [LastName] [nvarchar](50) NOT NULL, + [PreferredName] [nvarchar](50) NULL, [Active] [bit] NOT NULL, [CreateUserId] [int] NOT NULL, [CreateDate] [datetimeoffset](7) NOT NULL, From 6f7910f2a9bfa42eb3b4870e74dd7c05a865a566 Mon Sep 17 00:00:00 2001 From: OluwatobiAwe Date: Tue, 7 Oct 2025 11:58:45 +0100 Subject: [PATCH 3/5] TD-6159 removed elfh.externalsystem --- .../LearningHub.Nhs.Database.sqlproj | 5 ++- .../Tables/Elfh/ExternalSystemTBL.sql | 31 ------------------- 2 files changed, 2 insertions(+), 34 deletions(-) delete mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/ExternalSystemTBL.sql diff --git a/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj b/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj index 81bab93c7..63e1f952a 100644 --- a/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj +++ b/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj @@ -555,7 +555,6 @@ - @@ -573,8 +572,6 @@ - - @@ -591,6 +588,8 @@ + + diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/ExternalSystemTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/ExternalSystemTBL.sql deleted file mode 100644 index 0a565aaa7..000000000 --- a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/ExternalSystemTBL.sql +++ /dev/null @@ -1,31 +0,0 @@ -CREATE TABLE [elfh].[externalSystemTBL]( - [externalSystemId] [int] IDENTITY(1,1) NOT NULL, - [externalSystemName] [nvarchar](50) NOT NULL, - [url] [nvarchar](256) NULL, - [tsAndCs] [nvarchar](max) NULL, - [deleted] [bit] NOT NULL, - [amendUserId] [int] NOT NULL, - [amendUserDate] [datetimeoffset](7) NOT NULL, - [securityGuid] [uniqueidentifier] NULL, - [restrictToSSO] [bit] NOT NULL, - [defaultUserGroupId] [int] NULL, - [defaultStaffGroupId] [int] NULL, - [defaultJobRoleId] [int] NULL, - [defaultGradingId] [int] NULL, - [defaultSpecialtyId] [int] NULL, - [defaultLocationId] [int] NULL, - [reportUserId] [int] NULL, - [code] [nvarchar](50) NOT NULL, - CONSTRAINT [PK_externalSystem] PRIMARY KEY CLUSTERED -( - [externalSystemId] ASC -)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY] -) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] -GO - -ALTER TABLE [elfh].[externalSystemTBL] ADD CONSTRAINT [DF_externalSystemTBL_RestrictToSSO] DEFAULT ((0)) FOR [restrictToSSO] -GO - -ALTER TABLE [elfh].[externalSystemTBL] ADD DEFAULT ('') FOR [code] -GO - From 8631f429394746452fc4ad18a1bdfc389aeb6b7d Mon Sep 17 00:00:00 2001 From: OluwatobiAwe Date: Fri, 10 Oct 2025 14:37:09 +0100 Subject: [PATCH 4/5] TD-6159 database update --- .../LearningHub.Nhs.Database.sqlproj | 8 ++++ .../Scripts/TD-6159-turn-on-cdc.sql | 28 +++++++++++++ .../Scripts/TD-6159-turn-off-cdc.sql | 26 ++++++++++++ .../Elfh/EmploymentReferenceTypeTBL.sql | 13 ++++++ .../Tables/Elfh/MergeUserTBL.sql | 12 ++++++ .../Tables/Elfh/UserAdminLocationTBL.sql | 42 +++++++++++++++++++ .../Elfh/UserEmploymentReferenceTBL.sql | 31 ++++++++++++++ .../Elfh/UserEmploymentResponsibilityTBL.sql | 15 +++++++ .../Tables/Elfh/UserReportingUserTBL.sql | 31 ++++++++++++++ .../Tables/Hub/User.sql | 4 -- .../Tables/Hub/UserProfile.sql | 4 -- 11 files changed, 206 insertions(+), 8 deletions(-) create mode 100644 WebAPI/LearningHub.Nhs.Database/Scripts/Post-Deploy/Scripts/TD-6159-turn-on-cdc.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Scripts/Pre-Deploy/Scripts/TD-6159-turn-off-cdc.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmploymentReferenceTypeTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/MergeUserTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserAdminLocationTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentReferenceTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentResponsibilityTBL.sql create mode 100644 WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserReportingUserTBL.sql diff --git a/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj b/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj index 63e1f952a..dc61f3d9e 100644 --- a/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj +++ b/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj @@ -205,6 +205,10 @@ + + + + @@ -590,6 +594,10 @@ + + + + diff --git a/WebAPI/LearningHub.Nhs.Database/Scripts/Post-Deploy/Scripts/TD-6159-turn-on-cdc.sql b/WebAPI/LearningHub.Nhs.Database/Scripts/Post-Deploy/Scripts/TD-6159-turn-on-cdc.sql new file mode 100644 index 000000000..4128b97a8 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Scripts/Post-Deploy/Scripts/TD-6159-turn-on-cdc.sql @@ -0,0 +1,28 @@ +-- Re-enable CDC +IF NOT EXISTS ( + SELECT 1 + FROM sys.change_data_capture_tables + WHERE source_object_id = OBJECT_ID(N'hub.User') +) +BEGIN + EXEC sys.sp_cdc_enable_table + @source_schema = N'hub', + @source_name = N'User', + @role_name = NULL, + @supports_net_changes = 1; +END +GO + +IF NOT EXISTS ( + SELECT 1 + FROM sys.change_data_capture_tables + WHERE source_object_id = OBJECT_ID(N'hub.UserProfile') +) +BEGIN + EXEC sys.sp_cdc_enable_table + @source_schema = N'hub', + @source_name = N'UserProfile', + @role_name = NULL, + @supports_net_changes = 1; +END +GO diff --git a/WebAPI/LearningHub.Nhs.Database/Scripts/Pre-Deploy/Scripts/TD-6159-turn-off-cdc.sql b/WebAPI/LearningHub.Nhs.Database/Scripts/Pre-Deploy/Scripts/TD-6159-turn-off-cdc.sql new file mode 100644 index 000000000..57ee663c5 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Scripts/Pre-Deploy/Scripts/TD-6159-turn-off-cdc.sql @@ -0,0 +1,26 @@ +-- Disable CDC +IF EXISTS ( + SELECT 1 + FROM sys.change_data_capture_tables + WHERE source_object_id = OBJECT_ID(N'hub.User') +) +BEGIN + EXEC sys.sp_cdc_disable_table + @source_schema = N'hub', + @source_name = N'User', + @capture_instance = N'hub_User'; +END +GO + +IF EXISTS ( + SELECT 1 + FROM sys.change_data_capture_tables + WHERE source_object_id = OBJECT_ID(N'hub.UserProfile') +) +BEGIN + EXEC sys.sp_cdc_disable_table + @source_schema = N'hub', + @source_name = N'UserProfile', + @capture_instance = N'hub_UserProfile'; +END +GO diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmploymentReferenceTypeTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmploymentReferenceTypeTBL.sql new file mode 100644 index 000000000..be4a54abb --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/EmploymentReferenceTypeTBL.sql @@ -0,0 +1,13 @@ +CREATE TABLE [elfh].[employmentReferenceTypeTBL]( + [EmploymentReferenceTypeId] [int] NOT NULL, + [Title] [nvarchar](50) NOT NULL, + [RefAccess] [int] NOT NULL, + CONSTRAINT [PK_EmploymentReferenceType] PRIMARY KEY CLUSTERED +( + [EmploymentReferenceTypeId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[employmentReferenceTypeTBL] ADD CONSTRAINT [DF_employmentReferenceTypeTBL_RefAccess] DEFAULT ((0)) FOR [RefAccess] +GO diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/MergeUserTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/MergeUserTBL.sql new file mode 100644 index 000000000..510244acb --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/MergeUserTBL.sql @@ -0,0 +1,12 @@ +CREATE TABLE [elfh].[mergeUserTBL]( + [mergeUserId] [int] IDENTITY(1,1) NOT NULL, + [fromUserId] [int] NOT NULL, + [intoUserId] [int] NOT NULL, + [amendUserId] [int] NOT NULL, + [createdDatetime] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_mergeUserTBL] PRIMARY KEY CLUSTERED +( + [mergeUserId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserAdminLocationTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserAdminLocationTBL.sql new file mode 100644 index 000000000..4c88913e6 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserAdminLocationTBL.sql @@ -0,0 +1,42 @@ + +CREATE TABLE [elfh].[userAdminLocationTBL]( + [userId] [int] NOT NULL, + [adminLocationId] [int] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + [createdUserId] [int] NOT NULL, + [createdDate] [datetimeoffset](7) NOT NULL, +PRIMARY KEY CLUSTERED +( + [adminLocationId] ASC, + [userId] ASC, + [deleted] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[userAdminLocationTBL] ADD DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[userAdminLocationTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [amendDate] +GO + +ALTER TABLE [elfh].[userAdminLocationTBL] ADD DEFAULT (sysdatetimeoffset()) FOR [createdDate] +GO + +ALTER TABLE [elfh].[userAdminLocationTBL] WITH CHECK ADD CONSTRAINT [FK_userAdminLocationTBL_locationTBL] FOREIGN KEY([adminLocationId]) +REFERENCES [elfh].[locationTBL] ([locationId]) +GO + +ALTER TABLE [elfh].[userAdminLocationTBL] CHECK CONSTRAINT [FK_userAdminLocationTBL_locationTBL] +GO + +ALTER TABLE [elfh].[userAdminLocationTBL] WITH CHECK ADD CONSTRAINT [FK_userAdminLocationTBL_userTBL] FOREIGN KEY([userId]) +REFERENCES [hub].[user] ([Id]) +GO + +ALTER TABLE [elfh].[userAdminLocationTBL] CHECK CONSTRAINT [FK_userAdminLocationTBL_userTBL] +GO + + diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentReferenceTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentReferenceTBL.sql new file mode 100644 index 000000000..66bc74d7f --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentReferenceTBL.sql @@ -0,0 +1,31 @@ +CREATE TABLE [elfh].[userEmploymentReferenceTBL]( + [userEmploymentReferenceId] [int] IDENTITY(1,1) NOT NULL, + [employmentReferenceTypeId] [int] NOT NULL, + [userEmploymentId] [int] NOT NULL, + [referenceValue] [nvarchar](100) NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, + [amendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_userEmploymentReferenceTBL] PRIMARY KEY CLUSTERED +( + [userEmploymentReferenceId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[userEmploymentReferenceTBL] ADD CONSTRAINT [DF_userEmploymentReferenceTBL_deleted] DEFAULT ((0)) FOR [deleted] +GO + +ALTER TABLE [elfh].[userEmploymentReferenceTBL] WITH CHECK ADD CONSTRAINT [FK_userEmploymentReferenceTBL_employmentReferenceTypeTBL] FOREIGN KEY([employmentReferenceTypeId]) +REFERENCES [elfh].[employmentReferenceTypeTBL] ([EmploymentReferenceTypeId]) +GO + +ALTER TABLE [elfh].[userEmploymentReferenceTBL] CHECK CONSTRAINT [FK_userEmploymentReferenceTBL_employmentReferenceTypeTBL] +GO + +ALTER TABLE [elfh].[userEmploymentReferenceTBL] WITH CHECK ADD CONSTRAINT [FK_userEmploymentReferenceTBL_userEmploymentTBL] FOREIGN KEY([userEmploymentId]) +REFERENCES [elfh].[userEmploymentTBL] ([userEmploymentId]) +GO + +ALTER TABLE [elfh].[userEmploymentReferenceTBL] CHECK CONSTRAINT [FK_userEmploymentReferenceTBL_userEmploymentTBL] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentResponsibilityTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentResponsibilityTBL.sql new file mode 100644 index 000000000..546aead55 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserEmploymentResponsibilityTBL.sql @@ -0,0 +1,15 @@ +CREATE TABLE [elfh].[userEmploymentResponsibilityTBL]( + [userEmploymentResponsibilityId] [int] IDENTITY(1,1) NOT NULL, + [userEmploymentId] [int] NOT NULL, + [additionalResponsibilityId] [int] NOT NULL, + [deleted] [bit] NOT NULL, + [amendUserId] [int] NOT NULL, +PRIMARY KEY CLUSTERED +( + [userEmploymentResponsibilityId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[userEmploymentResponsibilityTBL] ADD DEFAULT ((0)) FOR [deleted] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserReportingUserTBL.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserReportingUserTBL.sql new file mode 100644 index 000000000..a96df3713 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Elfh/UserReportingUserTBL.sql @@ -0,0 +1,31 @@ +CREATE TABLE [elfh].[userReportingUserTBL]( + [userReportingUserId] [int] IDENTITY(1,1) NOT NULL, + [userId] [int] NOT NULL, + [reportingUserId] [int] NOT NULL, + [reportable] [bit] NOT NULL, + [Deleted] [bit] NOT NULL, + [AmendUserID] [int] NOT NULL, + [AmendDate] [datetimeoffset](7) NOT NULL, + CONSTRAINT [PK_userReportingUser] PRIMARY KEY CLUSTERED +( + [userReportingUserId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] +GO + +ALTER TABLE [elfh].[userReportingUserTBL] ADD DEFAULT ((1)) FOR [reportable] +GO + +ALTER TABLE [elfh].[userReportingUserTBL] WITH CHECK ADD CONSTRAINT [FK_userReportingUser_reportingUser] FOREIGN KEY([reportingUserId]) +REFERENCES [hub].[user] ([Id]) +GO + +ALTER TABLE [elfh].[userReportingUserTBL] CHECK CONSTRAINT [FK_userReportingUser_reportingUser] +GO + +ALTER TABLE [elfh].[userReportingUserTBL] WITH CHECK ADD CONSTRAINT [FK_userReportingUser_user] FOREIGN KEY([userId]) +REFERENCES [hub].[user] ([Id]) +GO + +ALTER TABLE [elfh].[userReportingUserTBL] CHECK CONSTRAINT [FK_userReportingUser_user] +GO \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Hub/User.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Hub/User.sql index eb2d34132..3af869df7 100644 --- a/WebAPI/LearningHub.Nhs.Database/Tables/Hub/User.sql +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Hub/User.sql @@ -32,10 +32,6 @@ ), PERIOD FOR SYSTEM_TIME ([VersionStartTime], [VersionEndTime]) ) ON [PRIMARY] -WITH -( -SYSTEM_VERSIONING = ON ( HISTORY_TABLE = [hub].[UserHistory] ) -) GO ALTER TABLE [hub].[User] ADD DEFAULT (getutcdate()) FOR [VersionStartTime] diff --git a/WebAPI/LearningHub.Nhs.Database/Tables/Hub/UserProfile.sql b/WebAPI/LearningHub.Nhs.Database/Tables/Hub/UserProfile.sql index aa7032ef9..61c95a2f5 100644 --- a/WebAPI/LearningHub.Nhs.Database/Tables/Hub/UserProfile.sql +++ b/WebAPI/LearningHub.Nhs.Database/Tables/Hub/UserProfile.sql @@ -20,10 +20,6 @@ )WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY], PERIOD FOR SYSTEM_TIME ([VersionStartTime], [VersionEndTime]) ) ON [PRIMARY] -WITH -( -SYSTEM_VERSIONING = ON ( HISTORY_TABLE = [hub].[UserProfileHistory] ) -) GO ALTER TABLE hub.[UserProfile] ADD DEFAULT (getutcdate()) FOR [VersionStartTime] From 12360a65faf34df3c1875f05a5a409cc0697532c Mon Sep 17 00:00:00 2001 From: OluwatobiAwe Date: Tue, 14 Oct 2025 09:07:37 +0100 Subject: [PATCH 5/5] . --- .../LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj b/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj index efb97f7fa..475459df5 100644 --- a/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj +++ b/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj @@ -547,7 +547,6 @@ - @@ -642,6 +641,7 @@ +