1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

Merge branch 'main' into ac/ac-1682/ef-migrations

# Conflicts:
#	src/Sql/dbo/Stored Procedures/Organization_EnableCollectionEnhancements.sql
#	util/SqliteMigrations/SqliteMigrations.csproj
This commit is contained in:
Rui Tome
2024-02-16 12:47:39 +00:00
382 changed files with 22664 additions and 5025 deletions

View File

@ -0,0 +1,156 @@
CREATE OR ALTER PROCEDURE [dbo].[Organization_EnableCollectionEnhancements]
@OrganizationId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
-- Step 1: AccessAll migration for Groups
-- Create a temporary table to store the groups with AccessAll = 1
SELECT [Id] AS [GroupId], [OrganizationId]
INTO #TempGroupsAccessAll
FROM [dbo].[Group]
WHERE [OrganizationId] = @OrganizationId
AND [AccessAll] = 1;
-- Step 2: AccessAll migration for OrganizationUsers
-- Create a temporary table to store the OrganizationUsers with AccessAll = 1
SELECT [Id] AS [OrganizationUserId], [OrganizationId]
INTO #TempUsersAccessAll
FROM [dbo].[OrganizationUser]
WHERE [OrganizationId] = @OrganizationId
AND [AccessAll] = 1;
-- Step 3: For all OrganizationUsers with Manager role or 'EditAssignedCollections' permission update their existing CollectionUser rows and insert new rows with [Manage] = 1
-- and finally update all OrganizationUsers with Manager role to User role
-- Create a temporary table to store the OrganizationUsers with Manager role or 'EditAssignedCollections' permission
SELECT ou.[Id] AS [OrganizationUserId],
CASE WHEN ou.[Type] = 3 THEN 1 ELSE 0 END AS [IsManager]
INTO #TempUserManagers
FROM [dbo].[OrganizationUser] ou
WHERE ou.[OrganizationId] = @OrganizationId
AND (ou.[Type] = 3 OR (ou.[Permissions] IS NOT NULL
AND ISJSON(ou.[Permissions]) > 0 AND JSON_VALUE(ou.[Permissions], '$.editAssignedCollections') = 'true'));
-- Step 4: Bump AccountRevisionDate for all OrganizationUsers updated in the previous steps
-- Combine and union the distinct OrganizationUserIds from all steps into a single variable
DECLARE @OrgUsersToBump [dbo].[GuidIdArray]
INSERT INTO @OrgUsersToBump
SELECT DISTINCT [OrganizationUserId] AS Id
FROM (
-- Step 1
SELECT GU.[OrganizationUserId]
FROM [dbo].[GroupUser] GU
INNER JOIN #TempGroupsAccessAll TG ON GU.[GroupId] = TG.[GroupId]
UNION
-- Step 2
SELECT [OrganizationUserId]
FROM #TempUsersAccessAll
UNION
-- Step 3
SELECT [OrganizationUserId]
FROM #TempUserManagers
) AS CombinedOrgUsers;
BEGIN TRY
BEGIN TRANSACTION;
-- Step 1
-- Update existing rows in [dbo].[CollectionGroup]
UPDATE CG
SET
CG.[ReadOnly] = 0,
CG.[HidePasswords] = 0,
CG.[Manage] = 0
FROM [dbo].[CollectionGroup] CG
INNER JOIN [dbo].[Collection] C ON CG.[CollectionId] = C.[Id]
INNER JOIN #TempGroupsAccessAll TG ON CG.[GroupId] = TG.[GroupId]
WHERE C.[OrganizationId] = TG.[OrganizationId];
-- Insert new rows into [dbo].[CollectionGroup]
INSERT INTO [dbo].[CollectionGroup] ([CollectionId], [GroupId], [ReadOnly], [HidePasswords], [Manage])
SELECT C.[Id], TG.[GroupId], 0, 0, 0
FROM [dbo].[Collection] C
INNER JOIN #TempGroupsAccessAll TG ON C.[OrganizationId] = TG.[OrganizationId]
LEFT JOIN [dbo].[CollectionGroup] CG ON CG.[CollectionId] = C.[Id] AND CG.[GroupId] = TG.[GroupId]
WHERE CG.[CollectionId] IS NULL;
-- Update Group to clear AccessAll flag and update RevisionDate
UPDATE G
SET [AccessAll] = 0, [RevisionDate] = GETUTCDATE()
FROM [dbo].[Group] G
INNER JOIN #TempGroupsAccessAll TG ON G.[Id] = TG.[GroupId];
-- Step 2
-- Update existing rows in [dbo].[CollectionUser]
UPDATE target
SET
target.[ReadOnly] = 0,
target.[HidePasswords] = 0,
target.[Manage] = 0
FROM [dbo].[CollectionUser] AS target
INNER JOIN [dbo].[Collection] AS C ON target.[CollectionId] = C.[Id]
INNER JOIN #TempUsersAccessAll AS TU ON C.[OrganizationId] = TU.[OrganizationId] AND target.[OrganizationUserId] = TU.[OrganizationUserId];
-- Insert new rows into [dbo].[CollectionUser]
INSERT INTO [dbo].[CollectionUser] ([CollectionId], [OrganizationUserId], [ReadOnly], [HidePasswords], [Manage])
SELECT C.[Id] AS [CollectionId], TU.[OrganizationUserId], 0, 0, 0
FROM [dbo].[Collection] C
INNER JOIN #TempUsersAccessAll TU ON C.[OrganizationId] = TU.[OrganizationId]
LEFT JOIN [dbo].[CollectionUser] target
ON target.[CollectionId] = C.[Id] AND target.[OrganizationUserId] = TU.[OrganizationUserId]
WHERE target.[CollectionId] IS NULL;
-- Update OrganizationUser to clear AccessAll flag
UPDATE OU
SET [AccessAll] = 0, [RevisionDate] = GETUTCDATE()
FROM [dbo].[OrganizationUser] OU
INNER JOIN #TempUsersAccessAll TU ON OU.[Id] = TU.[OrganizationUserId];
-- Step 3
-- Update [dbo].[CollectionUser] with [Manage] = 1 using the temporary table
UPDATE CU
SET CU.[ReadOnly] = 0,
CU.[HidePasswords] = 0,
CU.[Manage] = 1
FROM [dbo].[CollectionUser] CU
INNER JOIN #TempUserManagers TUM ON CU.[OrganizationUserId] = TUM.[OrganizationUserId];
-- Insert rows to [dbo].[CollectionUser] with [Manage] = 1 using the temporary table
-- This is for orgUsers who are Managers / EditAssignedCollections but have access via a group
-- We cannot give the whole group Manage permissions so we have to give them a direct assignment
INSERT INTO [dbo].[CollectionUser] ([CollectionId], [OrganizationUserId], [ReadOnly], [HidePasswords], [Manage])
SELECT DISTINCT CG.[CollectionId], TUM.[OrganizationUserId], 0, 0, 1
FROM [dbo].[CollectionGroup] CG
INNER JOIN [dbo].[GroupUser] GU ON CG.[GroupId] = GU.[GroupId]
INNER JOIN #TempUserManagers TUM ON GU.[OrganizationUserId] = TUM.[OrganizationUserId]
WHERE NOT EXISTS (
SELECT 1 FROM [dbo].[CollectionUser] CU
WHERE CU.[CollectionId] = CG.[CollectionId] AND CU.[OrganizationUserId] = TUM.[OrganizationUserId]
);
-- Update [dbo].[OrganizationUser] to migrate all OrganizationUsers with Manager role to User role
UPDATE OU
SET OU.[Type] = 2, OU.[RevisionDate] = GETUTCDATE() -- User
FROM [dbo].[OrganizationUser] OU
INNER JOIN #TempUserManagers TUM ON ou.[Id] = TUM.[OrganizationUserId]
WHERE TUM.[IsManager] = 1; -- Filter for Managers
-- Step 4
-- Execute User_BumpAccountRevisionDateByOrganizationUserIds for the distinct OrganizationUserIds
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserIds] @OrgUsersToBump;
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION;
THROW;
END CATCH;
-- Drop the temporary table
DROP TABLE #TempGroupsAccessAll;
DROP TABLE #TempUsersAccessAll;
DROP TABLE #TempUserManagers;
END
GO

View File

@ -0,0 +1,54 @@
-- Add columns LimitCollectionCreationDeletion, AllowAdminAccessToAllCollectionItems, FlexibleCollections to view
CREATE OR ALTER VIEW [dbo].[ProviderUserProviderOrganizationDetailsView]
AS
SELECT
PU.[UserId],
PO.[OrganizationId],
O.[Name],
O.[Enabled],
O.[UsePolicies],
O.[UseSso],
O.[UseKeyConnector],
O.[UseScim],
O.[UseGroups],
O.[UseDirectory],
O.[UseEvents],
O.[UseTotp],
O.[Use2fa],
O.[UseApi],
O.[UseResetPassword],
O.[SelfHost],
O.[UsersGetPremium],
O.[UseCustomPermissions],
O.[Seats],
O.[MaxCollections],
O.[MaxStorageGb],
O.[Identifier],
PO.[Key],
O.[PublicKey],
O.[PrivateKey],
PU.[Status],
PU.[Type],
PO.[ProviderId],
PU.[Id] ProviderUserId,
P.[Name] ProviderName,
O.[PlanType],
O.[LimitCollectionCreationDeletion],
O.[AllowAdminAccessToAllCollectionItems],
O.[FlexibleCollections]
FROM
[dbo].[ProviderUser] PU
INNER JOIN
[dbo].[ProviderOrganization] PO ON PO.[ProviderId] = PU.[ProviderId]
INNER JOIN
[dbo].[Organization] O ON O.[Id] = PO.[OrganizationId]
INNER JOIN
[dbo].[Provider] P ON P.[Id] = PU.[ProviderId]
GO
--Manually refresh ProviderOrganizationOrganizationDetailsView
IF OBJECT_ID('[dbo].[ProviderUserProviderOrganizationDetails_ReadByUserIdStatus]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[ProviderUserProviderOrganizationDetails_ReadByUserIdStatus]';
END
GO

View File

@ -0,0 +1,27 @@
CREATE OR ALTER PROCEDURE [dbo].[CipherOrganizationDetails_ReadUnassignedByOrganizationId]
@OrganizationId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT
C.*,
CASE
WHEN O.[UseTotp] = 1 THEN 1
ELSE 0
END [OrganizationUseTotp]
FROM
[dbo].[CipherView] C
LEFT JOIN
[dbo].[OrganizationView] O ON O.[Id] = C.[OrganizationId]
LEFT JOIN
[dbo].[CollectionCipher] CC ON C.[Id] = CC.[CipherId]
LEFT JOIN
[dbo].[Collection] S ON S.[Id] = CC.[CollectionId]
AND S.[OrganizationId] = C.[OrganizationId]
WHERE
C.[UserId] IS NULL
AND C.[OrganizationId] = @OrganizationId
AND CC.[CipherId] IS NULL
END
GO

View File

@ -0,0 +1,61 @@
CREATE OR ALTER PROCEDURE [dbo].[Grant_Save]
@Key NVARCHAR(200),
@Type NVARCHAR(50),
@SubjectId NVARCHAR(200),
@SessionId NVARCHAR(100),
@ClientId NVARCHAR(200),
@Description NVARCHAR(200),
@CreationDate DATETIME2,
@ExpirationDate DATETIME2,
@ConsumedDate DATETIME2,
@Data NVARCHAR(MAX)
AS
BEGIN
SET NOCOUNT ON
-- First, try to update the existing row
UPDATE [dbo].[Grant]
SET
[Type] = @Type,
[SubjectId] = @SubjectId,
[SessionId] = @SessionId,
[ClientId] = @ClientId,
[Description] = @Description,
[CreationDate] = @CreationDate,
[ExpirationDate] = @ExpirationDate,
[ConsumedDate] = @ConsumedDate,
[Data] = @Data
WHERE
[Key] = @Key
-- If no row was updated, insert a new one
IF @@ROWCOUNT = 0
BEGIN
INSERT INTO [dbo].[Grant]
(
[Key],
[Type],
[SubjectId],
[SessionId],
[ClientId],
[Description],
[CreationDate],
[ExpirationDate],
[ConsumedDate],
[Data]
)
VALUES
(
@Key,
@Type,
@SubjectId,
@SessionId,
@ClientId,
@Description,
@CreationDate,
@ExpirationDate,
@ConsumedDate,
@Data
)
END
END

View File

@ -6,8 +6,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="dbup-sqlserver" Version="5.0.37" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="dbup-sqlserver" Version="5.0.40" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup>

View File

@ -1,4 +1,4 @@
FROM mcr.microsoft.com/mssql/server:2019-CU17-ubuntu-20.04
FROM mcr.microsoft.com/mssql/server:2022-CU11-ubuntu-22.04
LABEL com.bitwarden.product="bitwarden"
@ -6,8 +6,8 @@ USER root:root
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
gosu \
tzdata \
gosu \
tzdata \
&& rm -rf /var/lib/apt/lists/*
COPY backup-db.sql /
@ -17,7 +17,6 @@ COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh \
&& chmod +x /backup-db.sh
# Does not work unfortunately (https://github.com/bitwarden/server/issues/286)
RUN /opt/mssql/bin/mssql-conf set telemetry.customerfeedback false
HEALTHCHECK --start-period=120s --timeout=3s CMD /opt/mssql-tools/bin/sqlcmd \

View File

@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0
FROM mcr.microsoft.com/dotnet/aspnet:8.0
LABEL com.bitwarden.product="bitwarden"

View File

@ -11,8 +11,8 @@
<ItemGroup>
<PackageReference Include="CommandDotNet" Version="7.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
</ItemGroup>
</Project>

View File

@ -72,7 +72,22 @@ public partial class GrantIdWithIndexes : Migration
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.Sql("ALTER TABLE `Grant` ADD COLUMN `Id` INT AUTO_INCREMENT UNIQUE;");
migrationBuilder.Sql(@"
DROP PROCEDURE IF EXISTS GrantSchemaChange;
CREATE PROCEDURE GrantSchemaChange()
BEGIN
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Grant' AND COLUMN_NAME = 'Id') THEN
ALTER TABLE `Grant` DROP COLUMN `Id`;
END IF;
ALTER TABLE `Grant` ADD COLUMN `Id` INT AUTO_INCREMENT UNIQUE;
END;
CALL GrantSchemaChange();
DROP PROCEDURE GrantSchemaChange;"
);
migrationBuilder.AddPrimaryKey(
name: "PK_Grant",

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,46 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.MySqlMigrations.Migrations;
/// <inheritdoc />
public partial class AddAuthTableIndexes : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_SsoUser_OrganizationId_ExternalId",
table: "SsoUser",
columns: new[] { "OrganizationId", "ExternalId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_SsoUser_OrganizationId_UserId",
table: "SsoUser",
columns: new[] { "OrganizationId", "UserId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Grant_ExpirationDate",
table: "Grant",
column: "ExpirationDate");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_SsoUser_OrganizationId_ExternalId",
table: "SsoUser");
migrationBuilder.DropIndex(
name: "IX_SsoUser_OrganizationId_UserId",
table: "SsoUser");
migrationBuilder.DropIndex(
name: "IX_Grant_ExpirationDate",
table: "Grant");
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.MySqlMigrations.Migrations;
/// <inheritdoc />
public partial class RemoveSMBetaFromOrganization : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "SecretsManagerBeta",
table: "Organization");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "SecretsManagerBeta",
table: "Organization",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
}
}

View File

@ -3,8 +3,8 @@ using System;
using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
@ -17,7 +17,7 @@ namespace Bit.MySqlMigrations.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.14")
.HasAnnotation("ProductVersion", "7.0.15")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", b =>
@ -136,9 +136,6 @@ namespace Bit.MySqlMigrations.Migrations
b.Property<int?>("Seats")
.HasColumnType("int");
b.Property<bool>("SecretsManagerBeta")
.HasColumnType("tinyint(1)");
b.Property<bool>("SelfHost")
.HasColumnType("tinyint(1)");
@ -490,7 +487,7 @@ namespace Bit.MySqlMigrations.Migrations
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn);
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("ClientId")
.IsRequired()
@ -533,8 +530,12 @@ namespace Bit.MySqlMigrations.Migrations
.HasColumnType("varchar(50)");
b.HasKey("Id")
.HasName("PK_Grant")
.HasAnnotation("SqlServer:Clustered", true);
b.HasIndex("ExpirationDate")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("Key")
.IsUnique();
@ -590,10 +591,20 @@ namespace Bit.MySqlMigrations.Migrations
b.HasKey("Id");
b.HasIndex("OrganizationId");
b.HasIndex("OrganizationId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("UserId");
b.HasIndex("OrganizationId", "ExternalId")
.IsUnique()
.HasAnnotation("Npgsql:IndexInclude", new[] { "UserId" })
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("OrganizationId", "UserId")
.IsUnique()
.HasAnnotation("SqlServer:Clustered", false);
b.ToTable("SsoUser", (string)null);
});

View File

@ -10,7 +10,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.14">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.15">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,47 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.PostgresMigrations.Migrations;
/// <inheritdoc />
public partial class AddAuthTableIndexes : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_SsoUser_OrganizationId_ExternalId",
table: "SsoUser",
columns: new[] { "OrganizationId", "ExternalId" },
unique: true)
.Annotation("Npgsql:IndexInclude", new[] { "UserId" });
migrationBuilder.CreateIndex(
name: "IX_SsoUser_OrganizationId_UserId",
table: "SsoUser",
columns: new[] { "OrganizationId", "UserId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Grant_ExpirationDate",
table: "Grant",
column: "ExpirationDate");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_SsoUser_OrganizationId_ExternalId",
table: "SsoUser");
migrationBuilder.DropIndex(
name: "IX_SsoUser_OrganizationId_UserId",
table: "SsoUser");
migrationBuilder.DropIndex(
name: "IX_Grant_ExpirationDate",
table: "Grant");
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.PostgresMigrations.Migrations;
/// <inheritdoc />
public partial class RemoveSMBetaFromOrganization : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "SecretsManagerBeta",
table: "Organization");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "SecretsManagerBeta",
table: "Organization",
type: "boolean",
nullable: false,
defaultValue: false);
}
}

View File

@ -18,7 +18,7 @@ namespace Bit.PostgresMigrations.Migrations
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:CollationDefinition:postgresIndetermanisticCollation", "en-u-ks-primary,en-u-ks-primary,icu,False")
.HasAnnotation("ProductVersion", "7.0.14")
.HasAnnotation("ProductVersion", "7.0.15")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -140,9 +140,6 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<int?>("Seats")
.HasColumnType("integer");
b.Property<bool>("SecretsManagerBeta")
.HasColumnType("boolean");
b.Property<bool>("SelfHost")
.HasColumnType("boolean");
@ -539,8 +536,12 @@ namespace Bit.PostgresMigrations.Migrations
.HasColumnType("character varying(50)");
b.HasKey("Id")
.HasName("PK_Grant")
.HasAnnotation("SqlServer:Clustered", true);
b.HasIndex("ExpirationDate")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("Key")
.IsUnique();
@ -601,10 +602,21 @@ namespace Bit.PostgresMigrations.Migrations
b.HasKey("Id");
b.HasIndex("OrganizationId");
b.HasIndex("OrganizationId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("UserId");
b.HasIndex("OrganizationId", "ExternalId")
.IsUnique()
.HasAnnotation("SqlServer:Clustered", false);
NpgsqlIndexBuilderExtensions.IncludeProperties(b.HasIndex("OrganizationId", "ExternalId"), new[] { "UserId" });
b.HasIndex("OrganizationId", "UserId")
.IsUnique()
.HasAnnotation("SqlServer:Clustered", false);
b.ToTable("SsoUser", (string)null);
});

View File

@ -6,7 +6,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.14">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.15">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View File

@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0
FROM mcr.microsoft.com/dotnet/aspnet:8.0
LABEL com.bitwarden.product="bitwarden"

View File

@ -1,12 +1,12 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0
FROM mcr.microsoft.com/dotnet/aspnet:8.0
LABEL com.bitwarden.product="bitwarden" com.bitwarden.project="setup"
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
openssl \
gosu \
&& rm -rf /var/lib/apt/lists/*
openssl \
gosu \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY obj/build-output/publish .

View File

@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Handlebars.Net" Version="2.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
</ItemGroup>

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.14">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.15">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View File

@ -0,0 +1,45 @@
ALTER TABLE
"Grant" RENAME TO "Old_Grant";
CREATE TABLE "Grant"
(
"Key" TEXT NOT NULL CONSTRAINT "PK_Grant" PRIMARY KEY,
"Type" TEXT NULL,
"SubjectId" TEXT NULL,
"SessionId" TEXT NULL,
"ClientId" TEXT NULL,
"Description" TEXT NULL,
"CreationDate" TEXT NOT NULL,
"ExpirationDate" TEXT NULL,
"ConsumedDate" TEXT NULL,
"Data" TEXT NULL
);
INSERT INTO
"Grant"
(
"Key",
"Type",
"SubjectId",
"SessionId",
"ClientId",
"Description",
"CreationDate",
"ExpirationDate",
"ConsumedDate",
"Data"
)
SELECT
"Key",
"Type",
"SubjectId",
"SessionId",
"ClientId",
"Description",
"CreationDate",
"ExpirationDate",
"ConsumedDate",
"Data"
FROM "Old_Grant";
DROP TABLE "Old_Grant";

View File

@ -0,0 +1,46 @@
ALTER TABLE
"Grant" RENAME TO "Old_Grant";
CREATE TABLE "Grant"
(
"Id" INTEGER PRIMARY KEY AUTOINCREMENT,
"Key" TEXT NOT NULL,
"Type" TEXT NOT NULL,
"SubjectId" TEXT NULL,
"SessionId" TEXT NULL,
"ClientId" TEXT NOT NULL,
"Description" TEXT NULL,
"CreationDate" TEXT NOT NULL,
"ExpirationDate" TEXT NULL,
"ConsumedDate" TEXT NULL,
"Data" TEXT NOT NULL
);
INSERT INTO
"Grant"
(
"Key",
"Type",
"SubjectId",
"SessionId",
"ClientId",
"Description",
"CreationDate",
"ExpirationDate",
"ConsumedDate",
"Data"
)
SELECT
"Key",
"Type",
"SubjectId",
"SessionId",
"ClientId",
"Description",
"CreationDate",
"ExpirationDate",
"ConsumedDate",
"Data"
FROM "Old_Grant";
DROP TABLE "Old_Grant";

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Bit.EfShared;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@ -7,59 +8,12 @@ namespace Bit.SqliteMigrations.Migrations;
/// <inheritdoc />
public partial class GrantIdWithIndexes : Migration
{
private const string _scriptLocationTemplate = "2023-12-04_00_{0}_GrantIndexes.sql";
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_Grant",
table: "Grant");
migrationBuilder.AlterColumn<string>(
name: "Type",
table: "Grant",
type: "TEXT",
maxLength: 50,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "TEXT",
oldMaxLength: 50,
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Data",
table: "Grant",
type: "TEXT",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "TEXT",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "ClientId",
table: "Grant",
type: "TEXT",
maxLength: 200,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "TEXT",
oldMaxLength: 200,
oldNullable: true);
migrationBuilder.AddColumn<int>(
name: "Id",
table: "Grant",
type: "INTEGER",
nullable: false,
defaultValue: 0)
.Annotation("Sqlite:Autoincrement", true);
migrationBuilder.AddPrimaryKey(
name: "PK_Grant",
table: "Grant",
column: "Id");
migrationBuilder.SqlResource(_scriptLocationTemplate);
migrationBuilder.CreateIndex(
name: "IX_Grant_Key",
@ -71,49 +25,10 @@ public partial class GrantIdWithIndexes : Migration
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_Grant",
table: "Grant");
migrationBuilder.SqlResource(_scriptLocationTemplate);
migrationBuilder.DropIndex(
name: "IX_Grant_Key",
table: "Grant");
migrationBuilder.DropColumn(
name: "Id",
table: "Grant");
migrationBuilder.AlterColumn<string>(
name: "Type",
table: "Grant",
type: "TEXT",
maxLength: 50,
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT",
oldMaxLength: 50);
migrationBuilder.AlterColumn<string>(
name: "Data",
table: "Grant",
type: "TEXT",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT");
migrationBuilder.AlterColumn<string>(
name: "ClientId",
table: "Grant",
type: "TEXT",
maxLength: 200,
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT",
oldMaxLength: 200);
migrationBuilder.AddPrimaryKey(
name: "PK_Grant",
table: "Grant",
column: "Key");
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,46 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.SqliteMigrations.Migrations;
/// <inheritdoc />
public partial class AddAuthTableIndexes : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_SsoUser_OrganizationId_ExternalId",
table: "SsoUser",
columns: new[] { "OrganizationId", "ExternalId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_SsoUser_OrganizationId_UserId",
table: "SsoUser",
columns: new[] { "OrganizationId", "UserId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Grant_ExpirationDate",
table: "Grant",
column: "ExpirationDate");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_SsoUser_OrganizationId_ExternalId",
table: "SsoUser");
migrationBuilder.DropIndex(
name: "IX_SsoUser_OrganizationId_UserId",
table: "SsoUser");
migrationBuilder.DropIndex(
name: "IX_Grant_ExpirationDate",
table: "Grant");
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.SqliteMigrations.Migrations;
/// <inheritdoc />
public partial class RemoveSMBetaFromOrganization : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "SecretsManagerBeta",
table: "Organization");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "SecretsManagerBeta",
table: "Organization",
type: "INTEGER",
nullable: false,
defaultValue: false);
}
}

View File

@ -4,6 +4,7 @@ using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
@ -15,7 +16,7 @@ namespace Bit.SqliteMigrations.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.14");
modelBuilder.HasAnnotation("ProductVersion", "7.0.15");
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", b =>
{
@ -133,9 +134,6 @@ namespace Bit.SqliteMigrations.Migrations
b.Property<int?>("Seats")
.HasColumnType("INTEGER");
b.Property<bool>("SecretsManagerBeta")
.HasColumnType("INTEGER");
b.Property<bool>("SelfHost")
.HasColumnType("INTEGER");
@ -487,7 +485,7 @@ namespace Bit.SqliteMigrations.Migrations
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasAnnotation("Sqlite:Autoincrement", true);
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("ClientId")
.IsRequired()
@ -530,8 +528,12 @@ namespace Bit.SqliteMigrations.Migrations
.HasColumnType("TEXT");
b.HasKey("Id")
.HasName("PK_Grant")
.HasAnnotation("SqlServer:Clustered", true);
b.HasIndex("ExpirationDate")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("Key")
.IsUnique();
@ -587,10 +589,20 @@ namespace Bit.SqliteMigrations.Migrations
b.HasKey("Id");
b.HasIndex("OrganizationId");
b.HasIndex("OrganizationId")
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("UserId");
b.HasIndex("OrganizationId", "ExternalId")
.IsUnique()
.HasAnnotation("Npgsql:IndexInclude", new[] { "UserId" })
.HasAnnotation("SqlServer:Clustered", false);
b.HasIndex("OrganizationId", "UserId")
.IsUnique()
.HasAnnotation("SqlServer:Clustered", false);
b.ToTable("SsoUser", (string)null);
});

View File

@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
@ -12,7 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.14">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.15">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
@ -23,6 +22,8 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="HelperScripts\2023-12-04_00_Up_GrantIndexes.sql" />
<EmbeddedResource Include="HelperScripts\2023-12-04_00_Down_GrantIndexes.sql" />
<EmbeddedResource Include="HelperScripts\2024-01-12_00_AccessAllCollectionGroups.sql" />
<EmbeddedResource Include="HelperScripts\2024-01-12_01_AccessAllCollectionUsers.sql" />
<EmbeddedResource Include="HelperScripts\2024-01-12_02_ManagersEditAssignedCollectionUsers.sql" />