Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@
<None Include="Scripts\Pre-Deploy\Scripts\TD-2902 Add resource types to Content Server.sql" />
<None Include="Scripts\Post-Deploy\Scripts\TD-6109_Enable_CDC.sql" />
<None Include="Scripts\LH Database Scripts\Move CC resource to a custom catalogue.sql" />
<None Include="Tables\Elfh\UserReportingUserTBL.sql" />
<None Include="Tables\Elfh\MergeUserTBL.sql" />
<None Include="Scripts\Pre-Deploy\Scripts\TD-6159-turn-off-cdc.sql" />
<None Include="Scripts\Post-Deploy\Scripts\TD-6159-turn-on-cdc.sql" />
</ItemGroup>
<ItemGroup>
<RefactorLog Include="LearningHub.Nhs.Database.refactorlog" />
Expand Down Expand Up @@ -592,7 +596,52 @@
<Build Include="Stored Procedures\Activity\GetUsersLearningHistory_Search.sql" />
<Build Include="Stored Procedures\Resources\GetUsercertificateDetails.sql" />
<Build Include="Stored Procedures\Activity\GetUserInProgressLearningActivities.sql" />
<Build Include="Stored Procedures\Hub\GetActiveNotificationCount.sql" />
<Build Include="Schemas\elfh.sql" />
<Build Include="Tables\Elfh\AttributeTBL.sql" />
<Build Include="Tables\Elfh\AttributeTypeTBL.sql" />
<Build Include="Tables\Elfh\CountryTBL.sql" />
<Build Include="Tables\Elfh\DeaneryTBL.sql" />
<Build Include="Tables\Elfh\EmailTemplateTBL.sql" />
<Build Include="Tables\Elfh\EmailTemplateTypeTBL.sql" />
<Build Include="Tables\Elfh\GdcRegister.sql" />
<Build Include="Tables\Elfh\GmcLrmp.sql" />
<Build Include="Tables\Elfh\GradeTBL.sql" />
<Build Include="Tables\Elfh\IpCountryLookupTBL.sql" />
<Build Include="Tables\Elfh\JobRoleTBL.sql" />
<Build Include="Tables\Elfh\Location.sql" />
<Build Include="Tables\Elfh\locationTypeTBL.sql" />
<Build Include="Tables\Elfh\LoginWizardRuleTBL.sql" />
<Build Include="Tables\Elfh\LoginWizardStageActivityTBL.sql" />
<Build Include="Tables\Elfh\loginWizardStageTBL.sql" />
<Build Include="Tables\Elfh\MedicalCouncilTBL.sql" />
<Build Include="Tables\Elfh\RegionTBL.sql" />
<Build Include="Tables\Elfh\SchoolTBL.sql" />
<Build Include="Tables\Elfh\SpecialtyTBL.sql" />
<Build Include="Tables\Elfh\StaffGroupTBL.sql" />
<Build Include="Tables\Elfh\SystemSettingTBL.sql" />
<Build Include="Tables\Elfh\TenantSmtpTBL.sql" />
<Build Include="Tables\Elfh\TermsAndConditionsTBL.sql" />
<Build Include="Tables\Elfh\UserAttributeTBL.sql" />
<Build Include="Tables\Elfh\UserEmploymentTBL.sql" />
<Build Include="Tables\Elfh\UserGroupTypeInputValidationTBL.sql" />
<Build Include="Tables\Elfh\UserHistoryAttributeTBL.sql" />
<Build Include="Tables\Elfh\UserHistoryTBL.sql" />
<Build Include="Tables\Elfh\userHistoryTypeTBL.sql" />
<Build Include="Tables\Elfh\UserPasswordValidationTokenTBL.sql" />
<Build Include="Tables\Elfh\UserRoleUpgradeTBL.sql" />
<Build Include="Tables\Elfh\UserTermsAndConditionsTBL.sql" />
<Build Include="Stored Procedures\Elfh\LinkEmploymentRecordToUser.sql" />
<Build Include="Stored Procedures\Elfh\UserDetailForAuthenticationByUserName.sql" />
<Build Include="Stored Procedures\Elfh\UserHistoryAttributeSave.sql" />
<Build Include="Stored Procedures\Elfh\UserHistoryInsert.sql" />
<Build Include="Stored Procedures\Elfh\UserHistoryLoadForLearningHubUser.sql" />
<Build Include="Stored Procedures\Elfh\UserHistoryLoadForUser.sql" />
<Build Include="Tables\Elfh\TenantTBL.sql" />
<Build Include="Tables\Elfh\TenantUrlTBL.sql" />
<Build Include="Tables\Elfh\EmploymentReferenceTypeTBL.sql" />
<Build Include="Tables\Elfh\UserEmploymentReferenceTBL.sql" />
<Build Include="Tables\Elfh\UserEmploymentResponsibilityTBL.sql" />
<Build Include="Tables\Elfh\UserAdminLocationTBL.sql" />
</ItemGroup>
<ItemGroup>
<None Include="Scripts\Pre-Deploy\Scripts\Card5766_AuthorTableChanges.PreDeployment.sql" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions WebAPI/LearningHub.Nhs.Database/Tables/Elfh/MergeUserTBL.sql
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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


Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions WebAPI/LearningHub.Nhs.Database/Tables/Hub/User.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 0 additions & 4 deletions WebAPI/LearningHub.Nhs.Database/Tables/Hub/UserProfile.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading