Skip to content
Snippets Groups Projects
Commit 966eda9e authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Add Down and fix up

parent 1a4130c7
No related tags found
1 merge request!108Draft: New: ResponsibleOrganization & ResponsibleInstitution
......@@ -32,6 +32,7 @@
<None Remove="Migrations\Migration202207191035GitlabResourceType_up.sql" />
<None Remove="Migrations\Migration202302271031RemDupGitlabProjectQuotas_up.sql" />
<None Remove="Migrations\Migration202302271200TopLevelProjectOrganizations_up.sql" />
<None Remove="Migrations\Migration202307041441ResponsibleOrganization_down.sql" />
<None Remove="Migrations\Migration202307041441ResponsibleOrganization_up.sql" />
</ItemGroup>
......@@ -60,6 +61,7 @@
<EmbeddedResource Include="Migrations\Migration202201190837NRWFHResources_up.sql" />
<EmbeddedResource Include="Migrations\Migration202302271031RemDupGitlabProjectQuotas_up.sql" />
<EmbeddedResource Include="Migrations\Migration202302271200TopLevelProjectOrganizations_up.sql" />
<EmbeddedResource Include="Migrations\Migration202307041441ResponsibleOrganization_down.sql" />
<EmbeddedResource Include="Migrations\Migration202307041441ResponsibleOrganization_up.sql" />
</ItemGroup>
......
......@@ -8,6 +8,8 @@ namespace Coscine.Migrations.Migrations
{
public override void Down()
{
Execute.EmbeddedScript("Migration202307041441ResponsibleOrganization_down.sql");
Delete
.Column("ResponsibleInstitution")
.FromTable("Projects");
......
INSERT INTO ProjectInstitute (OrganizationUrl, ProjectId)
SELECT ResponsibleOrganization, ID FROM Projects;
UPDATE Projects
SET Projects.ResponsibleOrganization = ISNULL((
SELECT
FIRST_VALUE(A.OrganizationUrl) OVER (PARTITION BY A.ProjectId ORDER BY CASE A.OrganizationUrl WHEN 'https://ror.org/04xfq0f34' THEN '0' ELSE A.OrganizationUrl END) as Org
SELECT TOP 1
FIRST_VALUE(A.OrganizationUrl)
OVER
(PARTITION BY A.ProjectId
ORDER BY CASE A.OrganizationUrl
WHEN 'https://ror.org/04xfq0f34'
THEN '0'
ELSE A.OrganizationUrl END
) as Org
FROM
(
SELECT OrganizationUrl, ProjectId
FROM ProjectInstitute
) AS A
WHERE A.ProjectId = Projects.Id
), 'https://ror.org/04xfq0f34')
\ No newline at end of file
), 'https://ror.org/04xfq0f34');
DELETE FROM ProjectInstitute
WHERE ProjectInstitute.OrganizationUrl IN (
SELECT ResponsibleOrganization FROM Projects
WHERE Projects.Id = ProjectInstitute.ProjectId
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment