Skip to content

Commit

Permalink
fix(n2n): adjust migration script (#259)
Browse files Browse the repository at this point in the history
* fix(n2n): add default value for companyApplicationType
* fix(n2n): add migration script for owner and type
* chore: on rollback remove entries from agreement_assigned_company_roles
* chore: on rollback remove entries from company_assigned_roles
Refs: CPLP-3152
---------
Co-authored-by: Norbert Truchsess <[email protected]>
Reviewed-By: Norbert Truchsess <[email protected]>
  • Loading branch information
Phil91 authored Sep 8, 2023
1 parent cc2671d commit 0ae6589
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

#nullable disable

#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional

namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.Migrations.Migrations
{
/// <inheritdoc />
Expand Down Expand Up @@ -161,7 +159,48 @@ protected override void Up(MigrationBuilder migrationBuilder)
{ 3, "SHARED" }
});

migrationBuilder.Sql("UPDATE portal.identity_providers set identity_provider_type_id = 3 where identity_provider_category_id = 1;");
migrationBuilder.Sql(@"UPDATE portal.identity_providers AS ip SET
identity_provider_type_id = CASE
WHEN ip.identity_provider_category_id = 1 THEN 3
WHEN ip.identity_provider_category_id IN (2, 3) THEN
CASE
WHEN (
SELECT COUNT(*)
FROM portal.company_identity_providers
WHERE identity_provider_id = ip.id
) = 1 THEN 1
ELSE 2
END
END,
owner_id = CASE
WHEN ip.identity_provider_category_id = 1 THEN
(SELECT c.id
FROM portal.companies AS c
JOIN portal.company_assigned_roles AS cr ON c.id = cr.company_id
WHERE cr.company_role_id = 4
LIMIT 1)
WHEN ip.identity_provider_category_id IN (2, 3) THEN
CASE
WHEN (
SELECT COUNT(*)
FROM portal.company_identity_providers
WHERE identity_provider_id = ip.id
) = 1 THEN
(
SELECT company_id
FROM portal.company_identity_providers
WHERE identity_provider_id = ip.id
)
ELSE
(
SELECT c.id
FROM portal.companies AS c
JOIN portal.company_assigned_roles AS cr ON c.id = cr.company_id
WHERE cr.company_role_id = 4
LIMIT 1
)
END
END;");
migrationBuilder.Sql("UPDATE portal.identity_providers set identity_provider_category_id = 2 where identity_provider_category_id = 1;");
migrationBuilder.Sql("UPDATE portal.company_applications set company_application_type_id = 1;");

Expand Down Expand Up @@ -249,6 +288,8 @@ protected override void Down(MigrationBuilder migrationBuilder)
values: new object[] { 1, "KEYCLOAK_SHARED" });

migrationBuilder.Sql("UPDATE portal.identity_providers set identity_provider_category_id = 1 where identity_provider_type_id = 3;");
migrationBuilder.Sql("DELETE from portal.agreement_assigned_company_roles where company_role_id = 5");
migrationBuilder.Sql("DELETE from portal.company_assigned_roles where company_role_id = 5");

migrationBuilder.DropForeignKey(
name: "fk_company_applications_companies_onboarding_service_provider_",
Expand Down

0 comments on commit 0ae6589

Please sign in to comment.