mirror of
https://github.com/bitwarden/server.git
synced 2025-02-07 00:21:32 +01:00
[AC-1682] Removed Postgres scripts and migrations
This commit is contained in:
parent
5383cd16fb
commit
bb00cb4e59
@ -1,47 +0,0 @@
|
||||
-- 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;
|
||||
|
||||
-- Step 2: Create a temporary table to store distinct OrganizationUserIds
|
||||
CREATE TEMP TABLE IF NOT EXISTS TempOrganizationUsers AS
|
||||
SELECT DISTINCT GU."OrganizationUserId"
|
||||
FROM "GroupUser" GU
|
||||
JOIN TempGroup TG ON GU."GroupId" = TG."GroupId";
|
||||
|
||||
-- Step 3: Update existing rows in "CollectionGroups"
|
||||
UPDATE "CollectionGroups" CG
|
||||
SET
|
||||
"ReadOnly" = false,
|
||||
"HidePasswords" = false,
|
||||
"Manage" = false
|
||||
FROM "CollectionGroups" CGUpdate
|
||||
INNER JOIN "Collection" C ON CGUpdate."CollectionId" = C."Id"
|
||||
INNER JOIN TempGroup TG ON CGUpdate."GroupId" = TG."GroupId"
|
||||
WHERE C."OrganizationId" = TG."OrganizationId";
|
||||
|
||||
-- Step 4: Insert new rows into "CollectionGroups"
|
||||
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"
|
||||
WHERE CG."CollectionId" IS NULL;
|
||||
|
||||
-- Step 5: Update Group to clear AccessAll flag
|
||||
UPDATE "Group" G
|
||||
SET "AccessAll" = false, "RevisionDate" = current_timestamp
|
||||
FROM TempGroup TG
|
||||
WHERE G."Id" = TG."GroupId";
|
||||
|
||||
-- Step 6: Update User AccountRevisionDate for each unique OrganizationUserId
|
||||
UPDATE "User" U
|
||||
SET "AccountRevisionDate" = current_timestamp
|
||||
FROM "OrganizationUser" OU
|
||||
JOIN TempOrganizationUsers TOU ON OU."Id" = TOU."OrganizationUserId"
|
||||
WHERE U."Id" = OU."UserId" AND OU."Status" = 2;
|
||||
|
||||
-- Step 7: Drop the temporary tables
|
||||
DROP TABLE IF EXISTS TempGroup;
|
||||
DROP TABLE IF EXISTS TempOrganizationUsers;
|
@ -1,43 +0,0 @@
|
||||
-- Step 1: Create a temporary table
|
||||
CREATE TEMP TABLE IF NOT EXISTS TempOrgUser AS
|
||||
SELECT "Id" AS "OrganizationUserId", "OrganizationId"
|
||||
FROM "OrganizationUser"
|
||||
WHERE "AccessAll" = true;
|
||||
|
||||
-- Step 2: Update existing rows in CollectionUsers
|
||||
UPDATE "CollectionUsers" cu
|
||||
SET
|
||||
"ReadOnly" = false,
|
||||
"HidePasswords" = false,
|
||||
"Manage" = false
|
||||
FROM "CollectionUsers" cuUpdate
|
||||
INNER JOIN "Collection" C ON cuUpdate."CollectionId" = C."Id"
|
||||
INNER JOIN TempOrgUser OU ON cuUpdate."OrganizationUserId" = OU."OrganizationUserId"
|
||||
WHERE C."OrganizationId" = OU."OrganizationId";
|
||||
|
||||
-- Step 3: Insert new rows into CollectionUsers
|
||||
INSERT INTO "CollectionUsers" ("CollectionId", "OrganizationUserId", "ReadOnly", "HidePasswords", "Manage")
|
||||
SELECT C."Id" AS "CollectionId", OU."OrganizationUserId", false, false, false
|
||||
FROM "Collection" AS C
|
||||
INNER JOIN TempOrgUser AS OU ON C."OrganizationId" = OU."OrganizationId"
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM "CollectionUsers" AS CU
|
||||
WHERE CU."CollectionId" = C."Id" AND CU."OrganizationUserId" = OU."OrganizationUserId"
|
||||
);
|
||||
|
||||
-- Step 4: Update OrganizationUser to clear AccessAll flag
|
||||
UPDATE "OrganizationUser" AS OU
|
||||
SET "AccessAll" = false
|
||||
FROM TempOrgUser AS T
|
||||
WHERE OU."Id" = T."OrganizationUserId";
|
||||
|
||||
-- Step 5: Update "User" AccountRevisionDate for each unique OrganizationUserId
|
||||
UPDATE "User" AS U
|
||||
SET "AccountRevisionDate" = current_timestamp
|
||||
FROM "OrganizationUser" AS OU
|
||||
JOIN TempOrgUser AS TOU ON OU."Id" = TOU."OrganizationUserId"
|
||||
WHERE U."Id" = OU."UserId" AND OU."Status" = 2;
|
||||
|
||||
-- Step 6: Drop the temporary table
|
||||
DROP TABLE IF EXISTS TempOrgUser;
|
@ -1,80 +0,0 @@
|
||||
-- Step 1: Update `CollectionUser` with `Manage` = 1 for all users with Manager role or 'EditAssignedCollections' permission
|
||||
-- Create a temporary table
|
||||
CREATE TEMP TABLE IF NOT EXISTS TempOrgUser AS
|
||||
SELECT ou."Id" AS "OrganizationUserId"
|
||||
FROM "OrganizationUser" ou
|
||||
WHERE (ou."Type" = 3 OR
|
||||
(ou."Permissions" IS NOT NULL AND
|
||||
((ou."Permissions"::text)::jsonb->>'editAssignedCollections') = 'true'));
|
||||
|
||||
-- Update CollectionUsers with Manage = 1 using the temporary table
|
||||
UPDATE "CollectionUsers" cu
|
||||
SET
|
||||
"ReadOnly" = false,
|
||||
"HidePasswords" = false,
|
||||
"Manage" = true
|
||||
FROM TempOrgUser temp
|
||||
WHERE cu."OrganizationUserId" = temp."OrganizationUserId";
|
||||
|
||||
-- Update `User` AccountRevisionDate for each unique OrganizationUserId
|
||||
UPDATE "User" AS U
|
||||
SET "AccountRevisionDate" = current_timestamp
|
||||
FROM "OrganizationUser" AS OU
|
||||
JOIN TempOrgUser AS TOU ON OU."Id" = TOU."OrganizationUserId"
|
||||
WHERE OU."Status" = 2 AND U."Id" = OU."UserId";
|
||||
|
||||
-- Drop the temporary table
|
||||
DROP TABLE IF EXISTS TempOrgUser;
|
||||
|
||||
-- Step 2: Insert rows to CollectionUser for Managers and users with 'EditAssignedCollections' permission assigned to groups with collection access
|
||||
-- Store the results in a temporary table
|
||||
CREATE TEMP TABLE IF NOT EXISTS TempCol AS
|
||||
SELECT cg."CollectionId", ou."Id" AS "OrganizationUserId"
|
||||
FROM "CollectionGroups" cg
|
||||
INNER JOIN "GroupUser" gu ON cg."GroupId" = gu."GroupId"
|
||||
INNER JOIN "OrganizationUser" ou ON gu."OrganizationUserId" = ou."Id"
|
||||
WHERE (ou."Type" = 3 OR
|
||||
(ou."Permissions" IS NOT NULL AND
|
||||
((ou."Permissions"::text)::jsonb->>'editAssignedCollections') = 'true'))
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM "CollectionUsers" cu
|
||||
WHERE cu."CollectionId" = cg."CollectionId" AND cu."OrganizationUserId" = ou."Id"
|
||||
);
|
||||
|
||||
-- Insert rows into CollectionUsers using the temporary table
|
||||
INSERT INTO "CollectionUsers" ("CollectionId", "OrganizationUserId", "ReadOnly", "HidePasswords", "Manage")
|
||||
SELECT "CollectionId", "OrganizationUserId", false, false, true
|
||||
FROM TempCol;
|
||||
|
||||
-- Update `User` AccountRevisionDate for each unique OrganizationUserId
|
||||
UPDATE "User" AS U
|
||||
SET "AccountRevisionDate" = current_timestamp
|
||||
FROM "OrganizationUser" AS OU
|
||||
JOIN TempCol AS TC ON OU."Id" = TC."OrganizationUserId"
|
||||
WHERE OU."Status" = 2 AND U."Id" = OU."UserId";
|
||||
|
||||
-- Drop the temporary table
|
||||
DROP TABLE IF EXISTS TempCol;
|
||||
|
||||
-- Step 3: Set all Managers to Users
|
||||
-- Create a temporary table
|
||||
CREATE TEMP TABLE IF NOT EXISTS TempOrgUser AS
|
||||
SELECT ou."Id" AS "OrganizationUserId"
|
||||
FROM "OrganizationUser" ou
|
||||
WHERE ou."Type" = 3;
|
||||
|
||||
-- Update OrganizationUser with Type = 2 using the temporary table
|
||||
UPDATE "OrganizationUser" ou
|
||||
SET "Type" = 2
|
||||
FROM TempOrgUser temp
|
||||
WHERE ou."Id" = temp."OrganizationUserId";
|
||||
|
||||
-- Update `User` AccountRevisionDate for each unique OrganizationUserId
|
||||
UPDATE "User" AS U
|
||||
SET "AccountRevisionDate" = current_timestamp
|
||||
FROM "OrganizationUser" AS OU
|
||||
JOIN TempOrgUser AS TOU ON OU."Id" = TOU."OrganizationUserId"
|
||||
WHERE OU."Status" = 2 AND U."Id" = OU."UserId";
|
||||
|
||||
-- Drop the temporary table
|
||||
DROP TABLE IF EXISTS TempOrgUser;
|
@ -1,4 +0,0 @@
|
||||
-- Set "FlexibleCollections" = true for all organizations that have not yet been migrated.
|
||||
UPDATE "Organization"
|
||||
SET "FlexibleCollections" = true
|
||||
WHERE "FlexibleCollections" = false;
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.PostgresMigrations.Migrations;
|
||||
|
||||
public partial class FCAccessAllCollectionGroups : Migration
|
||||
{
|
||||
private const string _accessAllCollectionGroupsScript = "PostgresMigrations.HelperScripts.2024-02-16_00_AccessAllCollectionGroups.psql";
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql(CoreHelpers.GetEmbeddedResourceContentsAsync(_accessAllCollectionGroupsScript));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
throw new Exception("Irreversible migration");
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.PostgresMigrations.Migrations;
|
||||
|
||||
public partial class FCAccessAllCollectionUsers : Migration
|
||||
{
|
||||
private const string _accessAllCollectionUsersScript = "PostgresMigrations.HelperScripts.2024-02-16_01_AccessAllCollectionUsers.psql";
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql(CoreHelpers.GetEmbeddedResourceContentsAsync(_accessAllCollectionUsersScript));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
throw new Exception("Irreversible migration");
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.PostgresMigrations.Migrations;
|
||||
|
||||
public partial class FCManagersEditAssignedCollectionUsers : Migration
|
||||
{
|
||||
private const string _managersEditAssignedCollectionUsersScript = "PostgresMigrations.HelperScripts.2024-02-16_02_ManagersEditAssignedCollectionUsers.psql";
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql(CoreHelpers.GetEmbeddedResourceContentsAsync(_managersEditAssignedCollectionUsersScript));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
throw new Exception("Irreversible migration");
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.PostgresMigrations.Migrations;
|
||||
|
||||
public partial class FCEnableOrgsFlexibleCollections : Migration
|
||||
{
|
||||
private const string _enableOrgsFlexibleCollectionsScript = "PostgresMigrations.HelperScripts.2024-02-16_03_EnableOrgsFlexibleCollections.psql";
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql(CoreHelpers.GetEmbeddedResourceContentsAsync(_enableOrgsFlexibleCollectionsScript));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
throw new Exception("Irreversible migration");
|
||||
}
|
||||
}
|
@ -24,9 +24,5 @@
|
||||
<EmbeddedResource Include="HelperScripts\2021-10-21_00_SetMaxAutoscaleSeatCount.psql" />
|
||||
<EmbeddedResource Include="HelperScripts\2022-03-01_00_Up_MigrateOrganizationApiKeys.psql" />
|
||||
<EmbeddedResource Include="HelperScripts\2022-03-01_00_Down_MigrateOrganizationApiKeys.psql" />
|
||||
<EmbeddedResource Include="HelperScripts\2024-02-16_00_AccessAllCollectionGroups.psql" />
|
||||
<EmbeddedResource Include="HelperScripts\2024-02-16_01_AccessAllCollectionUsers.psql" />
|
||||
<EmbeddedResource Include="HelperScripts\2024-02-16_02_ManagersEditAssignedCollectionUsers.psql" />
|
||||
<EmbeddedResource Include="HelperScripts\2024-02-16_03_EnableOrgsFlexibleCollections.psql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user