From 5c6a57d013f58400046c8784722f955163796942 Mon Sep 17 00:00:00 2001 From: chrisfoster76 Date: Mon, 8 Oct 2018 12:52:57 +0100 Subject: [PATCH 1/2] Adds script to create relationship --- .../Support/RelationshipCreationScript.sql | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/SFA.DAS.Commitments.Database/AdhocScripts/Support/RelationshipCreationScript.sql diff --git a/src/SFA.DAS.Commitments.Database/AdhocScripts/Support/RelationshipCreationScript.sql b/src/SFA.DAS.Commitments.Database/AdhocScripts/Support/RelationshipCreationScript.sql new file mode 100644 index 0000000000..aad25a72c3 --- /dev/null +++ b/src/SFA.DAS.Commitments.Database/AdhocScripts/Support/RelationshipCreationScript.sql @@ -0,0 +1,42 @@ +/* +Relationship creation script + +The purpose of this script is to create a Employer-Provider Relationship record in commitments. Under normal circumstances, +a Relationship is created when the Employer first sends a Provider a Cohort. When this Relationship is not created due to +technical issues at the time (at time of writing, the two operations are not atomic), when the Provider goes to view the cohort +and exception is thrown and the only known work-around is to have the Employer send another, empty cohort, to their Provider. +*/ + +declare @ProviderId bigint = 0; -- Set the UKPRN of the provider for whom to create the relationship +declare @EmployerAccountId bigint = 0; -- Set the AccountId of the employer for whom to create the relationship +declare @LegalEntityCode nvarchar(50) = ''; --Set the Code of the legal entity for whom to create the relationship + + + +/* +************* MODIFY BELOW THIS LINE AT YOUR PERIL ******************* +*/ + +insert into [dbo].[Relationship] +select +top 1 +c.ProviderId, +c.ProviderName, +c.EmployerAccountId, +c.LegalEntityId, +c.LegalEntityName, +c.LegalEntityAddress, +c.LegalEntityOrganisationType, +null as Verified, +GETDATE() as CreatedOn +from +[dbo].[Commitment] c +where c.ProviderId = @ProviderId and c.EmployerAccountId = @EmployerAccountId and c.LegalEntityId = @LegalEntityCode +and not exists (select 1 from Relationship where ProviderId = @ProviderId and EmployerAccountId = @EmployerAccountId and LegalEntityId = @LegalEntityCode) +order by c.Id desc + + +if(@@ROWCOUNT=0) +begin + print 'Error - Relationship already exists, or no Commitment found' +end From fa1e77f36ee46cc30e38a1e000a63d8c40946add Mon Sep 17 00:00:00 2001 From: chrisfoster76 Date: Mon, 8 Oct 2018 13:09:30 +0100 Subject: [PATCH 2/2] Adds proj change --- .../SFA.DAS.Commitments.Database.sqlproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SFA.DAS.Commitments.Database/SFA.DAS.Commitments.Database.sqlproj b/src/SFA.DAS.Commitments.Database/SFA.DAS.Commitments.Database.sqlproj index 14efe69c1c..99b2d27216 100644 --- a/src/SFA.DAS.Commitments.Database/SFA.DAS.Commitments.Database.sqlproj +++ b/src/SFA.DAS.Commitments.Database/SFA.DAS.Commitments.Database.sqlproj @@ -136,6 +136,7 @@ +