mirror of
https://github.com/bitwarden/server.git
synced 2025-02-05 00:01:30 +01:00
[AC-1682] Removed MySql scripts and migrations
This commit is contained in:
parent
6c21d4e96a
commit
5383cd16fb
@ -1,47 +0,0 @@
|
||||
-- Step 1: Create a temporary table to store the groups with AccessAll = 1
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS TempGroup AS
|
||||
SELECT `Id` AS `GroupId`, `OrganizationId`
|
||||
FROM `Group`
|
||||
WHERE `AccessAll` = 1;
|
||||
|
||||
-- Step 2: Create a temporary table to store distinct OrganizationUserIds
|
||||
CREATE TEMPORARY 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
|
||||
INNER JOIN `Collection` C ON CG.`CollectionId` = C.`Id`
|
||||
INNER JOIN TempGroup TG ON CG.`GroupId` = TG.`GroupId`
|
||||
SET
|
||||
CG.`ReadOnly` = 0,
|
||||
CG.`HidePasswords` = 0,
|
||||
CG.`Manage` = 0
|
||||
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`, 0, 0, 0
|
||||
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
|
||||
INNER JOIN TempGroup TG ON G.`Id` = TG.`GroupId`
|
||||
SET G.`AccessAll` = 0, G.`RevisionDate` = UTC_TIMESTAMP();
|
||||
|
||||
-- Step 6: Update User AccountRevisionDate for each unique OrganizationUserId
|
||||
UPDATE `User` U
|
||||
INNER JOIN `OrganizationUser` OU ON OU.`UserId` = U.`Id`
|
||||
INNER JOIN TempOrganizationUsers TOU ON TOU.`OrganizationUserId` = OU.`Id`
|
||||
SET U.`AccountRevisionDate` = UTC_TIMESTAMP()
|
||||
WHERE OU.`Status` = 2;
|
||||
|
||||
-- Step 7: Drop the temporary tables
|
||||
DROP TEMPORARY TABLE IF EXISTS TempGroup;
|
||||
DROP TEMPORARY TABLE IF EXISTS TempOrganizationUsers;
|
@ -1,40 +0,0 @@
|
||||
-- Step 1: Create a temporary table
|
||||
CREATE TEMPORARY TABLE TempOrgUser AS
|
||||
SELECT `Id` AS `OrganizationUserId`, `OrganizationId`
|
||||
FROM `OrganizationUser`
|
||||
WHERE `AccessAll` = 1;
|
||||
|
||||
-- Step 2: Update existing rows in CollectionUsers
|
||||
UPDATE `CollectionUsers` AS `target`
|
||||
INNER JOIN `Collection` AS `C` ON `target`.`CollectionId` = `C`.`Id`
|
||||
INNER JOIN `TempOrgUser` AS `OU` ON `C`.`OrganizationId` = `OU`.`OrganizationId`
|
||||
SET
|
||||
`target`.`ReadOnly` = 0,
|
||||
`target`.`HidePasswords` = 0,
|
||||
`target`.`Manage` = 0;
|
||||
|
||||
-- Step 3: Insert new rows into CollectionUsers
|
||||
INSERT INTO `CollectionUsers` (`CollectionId`, `OrganizationUserId`, `ReadOnly`, `HidePasswords`, `Manage`)
|
||||
SELECT `C`.`Id` AS `CollectionId`, `OU`.`OrganizationUserId`, 0, 0, 0
|
||||
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`
|
||||
INNER JOIN `TempOrgUser` AS `T` ON `OU`.`Id` = `T`.`OrganizationUserId`
|
||||
SET `OU`.`AccessAll` = 0;
|
||||
|
||||
-- Step 5: Update `User` AccountRevisionDate for each unique OrganizationUserId
|
||||
UPDATE `User` AS `U`
|
||||
INNER JOIN `OrganizationUser` AS `OU` ON `OU`.`UserId` = `U`.`Id`
|
||||
INNER JOIN `TempOrgUser` AS `TOU` ON `TOU`.`OrganizationUserId` = `OU`.`Id`
|
||||
SET `U`.`AccountRevisionDate` = UTC_TIMESTAMP()
|
||||
WHERE `OU`.`Status` = 2;
|
||||
|
||||
-- Step 6: Drop the temporary table
|
||||
DROP TEMPORARY TABLE IF EXISTS TempOrgUser;
|
@ -1,74 +0,0 @@
|
||||
-- Step 1: Update `CollectionUser` with `Manage` = 1 for all users with Manager role or 'EditAssignedCollections' permission
|
||||
-- Create a temporary table
|
||||
CREATE TEMPORARY TABLE TempOrgUser AS
|
||||
SELECT ou.Id AS OrganizationUserId
|
||||
FROM OrganizationUser ou
|
||||
WHERE ou.Type = 3 OR (ou.Permissions IS NOT NULL AND
|
||||
JSON_VALID(ou.Permissions) > 0 AND JSON_UNQUOTE(JSON_EXTRACT(ou.Permissions, '$.editAssignedCollections')) = 'true');
|
||||
|
||||
-- Update CollectionUsers with Manage = 1 using the temporary table
|
||||
UPDATE CollectionUsers cu
|
||||
INNER JOIN TempOrgUser temp ON cu.OrganizationUserId = temp.OrganizationUserId
|
||||
SET cu.ReadOnly = 0,
|
||||
cu.HidePasswords = 0,
|
||||
cu.Manage = 1;
|
||||
|
||||
-- Update `User` AccountRevisionDate for each unique OrganizationUserId
|
||||
UPDATE `User` AS `U`
|
||||
INNER JOIN `OrganizationUser` AS `OU` ON `OU`.`UserId` = `U`.`Id`
|
||||
INNER JOIN `TempOrgUser` AS `TOU` ON `TOU`.`OrganizationUserId` = `OU`.`Id`
|
||||
SET `U`.`AccountRevisionDate` = UTC_TIMESTAMP()
|
||||
WHERE `OU`.`Status` = 2;
|
||||
|
||||
-- Drop the temporary table
|
||||
DROP TEMPORARY 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 TEMPORARY 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 JSON_VALID(ou.Permissions) > 0 AND JSON_UNQUOTE(JSON_EXTRACT(ou.Permissions, '$.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, 0, 0, 1
|
||||
FROM TempCol;
|
||||
|
||||
-- Update `User` AccountRevisionDate for each unique OrganizationUserId
|
||||
UPDATE `User` AS `U`
|
||||
INNER JOIN `OrganizationUser` AS `OU` ON `OU`.`UserId` = `U`.`Id`
|
||||
INNER JOIN `TempCol` AS `TC` ON `TC`.`OrganizationUserId` = `OU`.`Id`
|
||||
SET `U`.`AccountRevisionDate` = UTC_TIMESTAMP()
|
||||
WHERE `OU`.`Status` = 2;
|
||||
|
||||
-- Drop the temporary table
|
||||
DROP TEMPORARY TABLE IF EXISTS TempCol;
|
||||
|
||||
-- Step 3: Set all Managers to Users
|
||||
-- Create a temporary table
|
||||
CREATE TEMPORARY TABLE 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
|
||||
INNER JOIN TempOrgUser temp ON ou.Id = temp.OrganizationUserId
|
||||
SET ou.Type = 2;
|
||||
|
||||
-- Update `User` AccountRevisionDate for each unique OrganizationUserId
|
||||
UPDATE `User` AS `U`
|
||||
INNER JOIN `OrganizationUser` AS `OU` ON `OU`.`UserId` = `U`.`Id`
|
||||
INNER JOIN `TempOrgUser` AS `TOU` ON `TOU`.`OrganizationUserId` = `OU`.`Id`
|
||||
SET `U`.`AccountRevisionDate` = UTC_TIMESTAMP()
|
||||
WHERE `OU`.`Status` = 2;
|
||||
|
||||
-- Drop the temporary table
|
||||
DROP TEMPORARY TABLE IF EXISTS TempOrgUser;
|
@ -1,4 +0,0 @@
|
||||
-- Set `FlexibleCollections` = 1 for all organizations that have not yet been migrated.
|
||||
UPDATE `Organization`
|
||||
SET `FlexibleCollections` = 1
|
||||
WHERE `FlexibleCollections` = 0;
|
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.MySqlMigrations.Migrations;
|
||||
|
||||
public partial class FCAccessAllCollectionGroups : Migration
|
||||
{
|
||||
private const string _accessAllCollectionGroupsScript = "MySqlMigrations.HelperScripts.2024-02-16_00_AccessAllCollectionGroups.sql";
|
||||
|
||||
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.MySqlMigrations.Migrations;
|
||||
|
||||
public partial class FCAccessAllCollectionUsers : Migration
|
||||
{
|
||||
private const string _accessAllCollectionUsersScript = "MySqlMigrations.HelperScripts.2024-02-16_01_AccessAllCollectionUsers.sql";
|
||||
|
||||
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.MySqlMigrations.Migrations;
|
||||
|
||||
public partial class FCManagersEditAssignedCollectionUsers : Migration
|
||||
{
|
||||
private const string _managersEditAssignedCollectionUsersScript = "MySqlMigrations.HelperScripts.2024-02-16_02_ManagersEditAssignedCollectionUsers.sql";
|
||||
|
||||
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.MySqlMigrations.Migrations;
|
||||
|
||||
public partial class FCEnableOrgsFlexibleCollections : Migration
|
||||
{
|
||||
private const string _enableOrgsFlexibleCollectionsScript = "MySqlMigrations.HelperScripts.2024-02-16_03_EnableOrgsFlexibleCollections.sql";
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql(CoreHelpers.GetEmbeddedResourceContentsAsync(_enableOrgsFlexibleCollectionsScript));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
throw new Exception("Irreversible migration");
|
||||
}
|
||||
}
|
@ -29,9 +29,5 @@
|
||||
<EmbeddedResource Include="HelperScripts\2021-10-21_00_SetMaxAutoscaleSeatCount.sql" />
|
||||
<EmbeddedResource Include="HelperScripts\2022-03-01_00_Up_MigrateOrganizationApiKeys.sql" />
|
||||
<EmbeddedResource Include="HelperScripts\2022-03-01_00_Down_MigrateOrganizationApiKeys.sql" />
|
||||
<EmbeddedResource Include="HelperScripts\2024-02-16_00_AccessAllCollectionGroups.sql" />
|
||||
<EmbeddedResource Include="HelperScripts\2024-02-16_01_AccessAllCollectionUsers.sql" />
|
||||
<EmbeddedResource Include="HelperScripts\2024-02-16_02_ManagersEditAssignedCollectionUsers.sql" />
|
||||
<EmbeddedResource Include="HelperScripts\2024-02-16_03_EnableOrgsFlexibleCollections.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user