Skip to content

Commit

Permalink
Merge pull request #413 from SkillsFundingAgency/DPP-1671_Data_fix_mi…
Browse files Browse the repository at this point in the history
…ssing_relationship

Adds script to create relationship
  • Loading branch information
m-nagashree authored Oct 9, 2018
2 parents f7ed7f4 + fa1e77f commit f0e73cb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<None Include="Database.publish.xml" />
<Build Include="Tables\BulkUpload.sql" />
<None Include="AdhocScripts\Support\ApprenticeshipStopFixUpScript.sql" />
<None Include="AdhocScripts\Support\RelationshipCreationScript.sql" />
</ItemGroup>
<ItemGroup>
<PostDeploy Include="PostDeployment\PostDeploymentScript.sql" />
Expand Down

0 comments on commit f0e73cb

Please sign in to comment.