1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 17:12:49 -05:00

[AC-1682] Postgres migrations

This commit is contained in:
Rui Tome
2023-12-20 11:57:36 +00:00
parent c5f1be4d79
commit 86ba89f230
9 changed files with 4752 additions and 63 deletions

View File

@ -1,10 +1,10 @@
-- Create a temporary table to store the groups with AccessAll = true
CREATE TEMPORARY TABLE TempGroup AS
-- Step 1: Create a temporary table to store the groups with AccessAll = 1
CREATE TEMP TABLE IF NOT EXISTS TempGroup AS
SELECT "Id" AS "GroupId", "OrganizationId"
FROM "Group"
WHERE "AccessAll" = true;
-- Update existing rows in "CollectionGroups"
-- Step 2: Update existing rows in "CollectionGroup"
UPDATE "CollectionGroups" CG
SET
"ReadOnly" = false,
@ -12,16 +12,16 @@ SET
"Manage" = false
FROM "CollectionGroups" CGUpdate
INNER JOIN "Collection" C ON CGUpdate."CollectionId" = C."Id"
INNER JOIN TempGroup TG ON CGUpdate."GroupId" = TG."GroupId"
INNER JOIN TempGroup TG ON CGUpdate."GroupId" = TG."GroupId"
WHERE C."OrganizationId" = TG."OrganizationId";
-- Insert new rows into "CollectionGroups"
-- Step 3: Insert new rows into "CollectionGroup"
INSERT INTO "CollectionGroups" ("CollectionId", "GroupId", "ReadOnly", "HidePasswords", "Manage")
SELECT C."Id", TG."GroupId", false, false, false
FROM "Collection" C
INNER JOIN TempGroup TG ON C."OrganizationId" = TG."OrganizationId"
LEFT JOIN "CollectionGroups" CG ON CG."CollectionId" = C."Id" AND CG."GroupId" = TG."GroupId"
INNER JOIN TempGroup TG ON C."OrganizationId" = TG."OrganizationId"
LEFT JOIN "CollectionGroups" CG ON CG."CollectionId" = C."Id" AND CG."GroupId" = TG."GroupId"
WHERE CG."CollectionId" IS NULL;
-- Drop the temporary table
-- Step 4: Drop the temporary table
DROP TABLE IF EXISTS TempGroup;