1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05: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
3 changed files with 56 additions and 15 deletions

View File

@ -131,9 +131,23 @@
SET `U`.`AccountRevisionDate` = UTC_TIMESTAMP(); SET `U`.`AccountRevisionDate` = UTC_TIMESTAMP();
-- Step 5: Set `FlexibleCollections` = 1 for all organizations that have not yet been migrated. -- Step 5: Set `FlexibleCollections` = 1 for all organizations that have not yet been migrated.
UPDATE `Organization` UPDATE `Organization` AS `O`
SET `FlexibleCollections` = 1 JOIN (
WHERE `FlexibleCollections` = 0; 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 -- Step 6: Drop the temporary tables
DROP TEMPORARY TABLE IF EXISTS `TempGroupsAccessAll`; DROP TEMPORARY TABLE IF EXISTS `TempGroupsAccessAll`;

View File

@ -124,9 +124,24 @@
); );
-- Step 5: Set "FlexibleCollections" = true for all organizations that have not yet been migrated. -- Step 5: Set "FlexibleCollections" = true for all organizations that have not yet been migrated.
UPDATE "Organization" UPDATE "Organization" AS "O"
SET "FlexibleCollections" = true 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 -- Step 6: Drop the temporary tables
DROP TABLE IF EXISTS "TempGroupsAccessAll"; DROP TABLE IF EXISTS "TempGroupsAccessAll";

View File

@ -144,8 +144,20 @@
-- Step 5: Set "FlexibleCollections" = 1 for all organizations that have not yet been migrated. -- Step 5: Set "FlexibleCollections" = 1 for all organizations that have not yet been migrated.
UPDATE "Organization" UPDATE "Organization"
SET "FlexibleCollections" = 1 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 -- Step 6: Drop the temporary tables
DROP TABLE IF EXISTS "TempGroupsAccessAll"; DROP TABLE IF EXISTS "TempGroupsAccessAll";