1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

[AC-1682] Setting FlexibleCollections = 1 only for Orgs that had data migrated in previous steps

This commit is contained in:
Rui Tome 2024-03-29 12:13:04 +00:00
parent 7b54d78d67
commit 28bba94d81
No known key found for this signature in database
GPG Key ID: 526239D96A8EC066
3 changed files with 56 additions and 15 deletions

View File

@ -131,11 +131,25 @@
SET `U`.`AccountRevisionDate` = UTC_TIMESTAMP();
-- Step 5: Set `FlexibleCollections` = 1 for all organizations that have not yet been migrated.
UPDATE `Organization`
SET `FlexibleCollections` = 1
WHERE `FlexibleCollections` = 0;
UPDATE `Organization` AS `O`
JOIN (
SELECT DISTINCT `TG`.`OrganizationId`
FROM `TempGroupsAccessAll` AS `TG`
UNION
SELECT DISTINCT `TU`.`OrganizationId`
FROM `TempUsersAccessAll` AS `TU`
UNION
SELECT DISTINCT `OU`.`OrganizationId`
FROM `TempUserManagers` AS `OU`
) AS `TempOrgIds` ON `O`.`Id` = `TempOrgIds`.`OrganizationId`
SET `O`.`FlexibleCollections` = 1
WHERE `O`.`FlexibleCollections` = 0;
-- Step 6: Drop the temporary tables
DROP TEMPORARY TABLE IF EXISTS `TempGroupsAccessAll`;
DROP TEMPORARY TABLE IF EXISTS `TempUsersAccessAll`;
DROP TEMPORARY TABLE IF EXISTS `TempUserManagers`;
DROP TEMPORARY TABLE IF EXISTS `TempGroupsAccessAll`;
DROP TEMPORARY TABLE IF EXISTS `TempUsersAccessAll`;
DROP TEMPORARY TABLE IF EXISTS `TempUserManagers`;

View File

@ -124,12 +124,27 @@
);
-- Step 5: Set "FlexibleCollections" = true for all organizations that have not yet been migrated.
UPDATE "Organization"
UPDATE "Organization" AS "O"
SET "FlexibleCollections" = true
WHERE "FlexibleCollections" = false;
FROM (
SELECT DISTINCT "TG"."OrganizationId"
FROM "TempGroupsAccessAll" AS "TG"
UNION
SELECT DISTINCT "TU"."OrganizationId"
FROM "TempUsersAccessAll" AS "TU"
UNION
SELECT DISTINCT "OU"."OrganizationId"
FROM "TempUserManagers" AS "OU"
) AS "TempOrgIds"
WHERE "O"."Id" = "TempOrgIds"."OrganizationId"
AND "O"."FlexibleCollections" = false;
-- Step 6: Drop the temporary tables
DROP TABLE IF EXISTS "TempGroupsAccessAll";
DROP TABLE IF EXISTS "TempUsersAccessAll";
DROP TABLE IF EXISTS "TempUserManagers";
DROP TABLE IF EXISTS "TempGroupsAccessAll";
DROP TABLE IF EXISTS "TempUsersAccessAll";
DROP TABLE IF EXISTS "TempUserManagers";

View File

@ -144,10 +144,22 @@
-- Step 5: Set "FlexibleCollections" = 1 for all organizations that have not yet been migrated.
UPDATE "Organization"
SET "FlexibleCollections" = 1
WHERE "FlexibleCollections" = 0;
WHERE "Id" IN (
SELECT DISTINCT "TG"."OrganizationId"
FROM "TempGroupsAccessAll" AS "TG"
UNION
SELECT DISTINCT "TU"."OrganizationId"
FROM "TempUsersAccessAll" AS "TU"
UNION
SELECT DISTINCT "OU"."OrganizationId"
FROM "TempUserManagers" AS "OU"
) AND "FlexibleCollections" = 0;
-- Step 6: Drop the temporary tables
DROP TABLE IF EXISTS "TempGroupsAccessAll";
DROP TABLE IF EXISTS "TempUsersAccessAll";
DROP TABLE IF EXISTS "TempUserManagers";
DROP TABLE IF EXISTS "TempGroupsAccessAll";
DROP TABLE IF EXISTS "TempUsersAccessAll";
DROP TABLE IF EXISTS "TempUserManagers";