diff --git a/util/MySqlMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.sql b/util/MySqlMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.sql index 5bc9c3287..840040d32 100644 --- a/util/MySqlMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.sql +++ b/util/MySqlMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.sql @@ -41,7 +41,7 @@ SET `CG`.`ReadOnly` = 0, `CG`.`HidePasswords` = 0, `CG`.`Manage` = 0 - WHERE `C`.`OrganizationId` = `TG`.`OrganizationId`; + WHERE `CG`.`CollectionId` = `C`.`Id` AND `C`.`OrganizationId` = `TG`.`OrganizationId`; -- Insert new rows into `CollectionGroups` INSERT INTO `CollectionGroups` (`CollectionId`, `GroupId`, `ReadOnly`, `HidePasswords`, `Manage`) @@ -58,13 +58,14 @@ -- Step 2 -- Update existing rows in `CollectionUsers` - UPDATE `CollectionUsers` `target` - INNER JOIN `Collection` `C` ON `target`.`CollectionId` = `C`.`Id` + UPDATE `CollectionUsers` `CU` + INNER JOIN `Collection` `C` ON `CU`.`CollectionId` = `C`.`Id` INNER JOIN `TempUsersAccessAll` `TU` - ON `C`.`OrganizationId` = `TU`.`OrganizationId` AND `target`.`OrganizationUserId` = `TU`.`OrganizationUserId` - SET `target`.`ReadOnly` = 0, - `target`.`HidePasswords` = 0, - `target`.`Manage` = 0; + ON `C`.`OrganizationId` = `TU`.`OrganizationId` AND `CU`.`OrganizationUserId` = `TU`.`OrganizationUserId` + SET `CU`.`ReadOnly` = 0, + `CU`.`HidePasswords` = 0, + `CU`.`Manage` = 0 + WHERE `CU`.`CollectionId` = `C`.`Id`; -- Insert new rows into `CollectionUsers` INSERT INTO `CollectionUsers` (`CollectionId`, `OrganizationUserId`, `ReadOnly`, `HidePasswords`, `Manage`) diff --git a/util/PostgresMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.psql b/util/PostgresMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.psql index 6b7c5ee45..b211ac729 100644 --- a/util/PostgresMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.psql +++ b/util/PostgresMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.psql @@ -40,8 +40,8 @@ "HidePasswords" = false, "Manage" = false FROM "Collection" "C" - WHERE "CG"."CollectionId" = "C"."Id" - AND "C"."OrganizationId" IN (SELECT "OrganizationId" FROM "TempGroupsAccessAll"); + JOIN "TempGroupsAccessAll" "TG" ON "CG"."GroupId" = "TG"."GroupId" + WHERE "CG"."CollectionId" = "C"."Id" AND "C"."OrganizationId" = TG."OrganizationId"; -- Insert new rows into CollectionGroups INSERT INTO "CollectionGroups" ("CollectionId", "GroupId", "ReadOnly", "HidePasswords", "Manage") @@ -58,14 +58,14 @@ -- Step 2 -- Update existing rows in CollectionUsers - UPDATE "CollectionUsers" "target" + UPDATE "CollectionUsers" "CU" SET "ReadOnly" = false, "HidePasswords" = false, "Manage" = false FROM "Collection" "C" - WHERE "target"."CollectionId" = "C"."Id" - AND "C"."OrganizationId" IN (SELECT "OrganizationId" FROM "TempUsersAccessAll") - AND "target"."OrganizationUserId" IN (SELECT "OrganizationUserId" FROM "TempUsersAccessAll"); + INNER JOIN "TempUsersAccessAll" "TU" ON "C"."OrganizationId" = "TU"."OrganizationId" AND + "CU"."OrganizationUserId" = "TU"."OrganizationUserId" + WHERE "CU"."CollectionId" = "C"."Id"; -- Insert new rows into CollectionUsers INSERT INTO "CollectionUsers" ("CollectionId", "OrganizationUserId", "ReadOnly", "HidePasswords", "Manage") diff --git a/util/SqliteMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.sql b/util/SqliteMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.sql index d6c12347f..ec59e733b 100644 --- a/util/SqliteMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.sql +++ b/util/SqliteMigrations/HelperScripts/2024-03-22_00_EnableOrgsCollectionEnhancements.sql @@ -62,16 +62,14 @@ -- Step 2 -- Update existing rows in "CollectionUsers" - UPDATE "CollectionUsers" - SET - "ReadOnly" = 0, + UPDATE "CollectionUsers" "CU" + SET "ReadOnly" = 0, "HidePasswords" = 0, "Manage" = 0 - WHERE "CollectionId" IN ( - SELECT "C"."Id" - FROM "Collection" "C" - INNER JOIN "TempUsersAccessAll" "TU" ON "C"."OrganizationId" = "TU"."OrganizationId" - ); + FROM "Collection" "C" + INNER JOIN "TempUsersAccessAll" AS "TU" ON "CU"."OrganizationUserId" = "TU"."OrganizationUserId" AND + "C"."OrganizationId" = "TU"."OrganizationId" + WHERE "CU"."CollectionId" = "C"."Id"; -- Insert new rows into "CollectionUsers" INSERT INTO "CollectionUsers" ("CollectionId", "OrganizationUserId", "ReadOnly", "HidePasswords", "Manage")