1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-16 15:17:33 -05:00

PM-23030 adding migration script (#6009)

* PM-23030 adding migration script

* PM-23030 fixing store procedure sql file

* PM-23030 fixing syntax error

* PM-23030 fixing migration

* PM-23030 fixing sql script

* PM-23030 fixing migration order

* PM_23030 fixing migrations

* PM-23030 fixing migration script validation error

* PM-23030 fixing migration

* PM-23030 trying to fix validation error

* PM-23030 fixing migration script

* PM-23030 updating sql scripts to change data type

* PM-23030 adding report key to organization application

* PM-23030 adding report key migration scripts

* PM-23030 adding migration scripts

* PM-23030 changing key column name
This commit is contained in:
Graham Walker
2025-07-02 14:56:15 -05:00
committed by GitHub
parent c6d38d9db3
commit b7df8525af
23 changed files with 19883 additions and 12 deletions

View File

@ -12,6 +12,7 @@ public class OrganizationApplication : ITableObject<Guid>, IRevisable
public string Applications { get; set; } = string.Empty; public string Applications { get; set; } = string.Empty;
public DateTime CreationDate { get; set; } = DateTime.UtcNow; public DateTime CreationDate { get; set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; set; } = DateTime.UtcNow; public DateTime RevisionDate { get; set; } = DateTime.UtcNow;
public string ContentEncryptionKey { get; set; } = string.Empty;
public void SetNewId() public void SetNewId()
{ {

View File

@ -13,6 +13,8 @@ public class OrganizationReport : ITableObject<Guid>
public string ReportData { get; set; } = string.Empty; public string ReportData { get; set; } = string.Empty;
public DateTime CreationDate { get; set; } = DateTime.UtcNow; public DateTime CreationDate { get; set; } = DateTime.UtcNow;
public string ContentEncryptionKey { get; set; } = string.Empty;
public void SetNewId() public void SetNewId()
{ {
Id = CoreHelpers.GenerateComb(); Id = CoreHelpers.GenerateComb();

View File

@ -3,7 +3,8 @@ CREATE PROCEDURE [dbo].[OrganizationApplication_Create]
@OrganizationId UNIQUEIDENTIFIER, @OrganizationId UNIQUEIDENTIFIER,
@Applications NVARCHAR(MAX), @Applications NVARCHAR(MAX),
@CreationDate DATETIME2(7), @CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7) @RevisionDate DATETIME2(7),
@ContentEncryptionKey VARCHAR(MAX)
AS AS
SET NOCOUNT ON; SET NOCOUNT ON;
@ -13,13 +14,15 @@ AS
[OrganizationId], [OrganizationId],
[Applications], [Applications],
[CreationDate], [CreationDate],
[RevisionDate] [RevisionDate],
[ContentEncryptionKey]
) )
VALUES VALUES
( (
@Id, @Id,
@OrganizationId, @OrganizationId,
@Applications, @Applications,
@CreationDate, @CreationDate,
@RevisionDate @RevisionDate,
); @ContentEncryptionKey
);

View File

@ -3,7 +3,8 @@ CREATE PROCEDURE [dbo].[OrganizationReport_Create]
@OrganizationId UNIQUEIDENTIFIER, @OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7), @Date DATETIME2(7),
@ReportData NVARCHAR(MAX), @ReportData NVARCHAR(MAX),
@CreationDate DATETIME2(7) @CreationDate DATETIME2(7),
@ContentEncryptionKey VARCHAR(MAX)
AS AS
SET NOCOUNT ON; SET NOCOUNT ON;
@ -12,12 +13,14 @@ AS
[OrganizationId], [OrganizationId],
[Date], [Date],
[ReportData], [ReportData],
[CreationDate] [CreationDate],
[ContentEncryptionKey]
) )
VALUES ( VALUES (
@Id, @Id,
@OrganizationId, @OrganizationId,
@Date, @Date,
@ReportData, @ReportData,
@CreationDate @CreationDate,
@ContentEncryptionKey
); );

View File

@ -4,9 +4,10 @@ CREATE TABLE [dbo].[OrganizationApplication] (
[Applications] NVARCHAR(MAX) NOT NULL, [Applications] NVARCHAR(MAX) NOT NULL,
[CreationDate] DATETIME2 (7) NOT NULL, [CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL, [RevisionDate] DATETIME2 (7) NOT NULL,
[ContentEncryptionKey] VARCHAR(MAX) NOT NULL,
CONSTRAINT [PK_OrganizationApplication] PRIMARY KEY CLUSTERED ([Id] ASC), CONSTRAINT [PK_OrganizationApplication] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_OrganizationApplication_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) CONSTRAINT [FK_OrganizationApplication_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
); );
GO GO
CREATE NONCLUSTERED INDEX [IX_OrganizationApplication_OrganizationId] CREATE NONCLUSTERED INDEX [IX_OrganizationApplication_OrganizationId]

View File

@ -4,9 +4,10 @@ CREATE TABLE [dbo].[OrganizationReport] (
[Date] DATETIME2 (7) NOT NULL, [Date] DATETIME2 (7) NOT NULL,
[ReportData] NVARCHAR(MAX) NOT NULL, [ReportData] NVARCHAR(MAX) NOT NULL,
[CreationDate] DATETIME2 (7) NOT NULL, [CreationDate] DATETIME2 (7) NOT NULL,
[ContentEncryptionKey] VARCHAR(MAX) NOT NULL,
CONSTRAINT [PK_OrganizationReport] PRIMARY KEY CLUSTERED ([Id] ASC), CONSTRAINT [PK_OrganizationReport] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_OrganizationReport_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) CONSTRAINT [FK_OrganizationReport_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
); );
GO GO
CREATE NONCLUSTERED INDEX [IX_OrganizationReport_OrganizationId] CREATE NONCLUSTERED INDEX [IX_OrganizationReport_OrganizationId]

View File

@ -0,0 +1,44 @@
IF COL_LENGTH('[dbo].[OrganizationReport]', 'ContentEncryptionKey') IS NULL
BEGIN
ALTER TABLE [dbo].[OrganizationReport]
ADD [ContentEncryptionKey] VARCHAR(MAX) NOT NULL;
END
GO
CREATE OR ALTER VIEW [dbo].[OrganizationReportView]
AS
SELECT
*
FROM
[dbo].[OrganizationReport]
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7),
@ReportData NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@ContentEncryptionKey VARCHAR(MAX)
AS
SET NOCOUNT ON;
INSERT INTO [dbo].[OrganizationReport]
(
[Id],
[OrganizationId],
[Date],
[ReportData],
[CreationDate],
[ContentEncryptionKey]
)
VALUES
(
@Id,
@OrganizationId,
@Date,
@ReportData,
@CreationDate,
@ContentEncryptionKey
);
GO

View File

@ -0,0 +1,44 @@
IF COL_LENGTH('[dbo].[OrganizationApplication]', 'ContentEncryptionKey') IS NULL
BEGIN
ALTER TABLE [dbo].[OrganizationApplication]
ADD [ContentEncryptionKey] VARCHAR(MAX) NOT NULL;
END
GO
CREATE OR ALTER VIEW [dbo].[OrganizationApplicationView]
AS
SELECT
*
FROM
[dbo].[OrganizationApplication]
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Applications NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7),
@ContentEncryptionKey VARCHAR(MAX)
AS
SET NOCOUNT ON;
INSERT INTO [dbo].[OrganizationApplication]
(
[Id],
[OrganizationId],
[Applications],
[CreationDate],
[RevisionDate],
[ContentEncryptionKey]
)
VALUES
(
@Id,
@OrganizationId,
@Applications,
@CreationDate,
@RevisionDate,
@ContentEncryptionKey
);
GO

View File

@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.MySqlMigrations.Migrations;
/// <inheritdoc />
public partial class _20250626_00_AlterOrganizationReportsql : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "ContentEncryptionKey",
table: "OrganizationReport",
type: "longtext",
nullable: false)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "ContentEncryptionKey",
table: "OrganizationApplication",
type: "longtext",
nullable: false)
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ContentEncryptionKey",
table: "OrganizationReport");
migrationBuilder.DropColumn(
name: "ContentEncryptionKey",
table: "OrganizationApplication");
}
}

View File

@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.MySqlMigrations.Migrations;
/// <inheritdoc />
public partial class _20250701_00_AlterOrganizationApplicationsql : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}

View File

@ -979,6 +979,10 @@ namespace Bit.MySqlMigrations.Migrations
.IsRequired() .IsRequired()
.HasColumnType("longtext"); .HasColumnType("longtext");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("CreationDate") b.Property<DateTime>("CreationDate")
.HasColumnType("datetime(6)"); .HasColumnType("datetime(6)");
@ -1004,6 +1008,10 @@ namespace Bit.MySqlMigrations.Migrations
b.Property<Guid>("Id") b.Property<Guid>("Id")
.HasColumnType("char(36)"); .HasColumnType("char(36)");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("CreationDate") b.Property<DateTime>("CreationDate")
.HasColumnType("datetime(6)"); .HasColumnType("datetime(6)");

View File

@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.PostgresMigrations.Migrations;
/// <inheritdoc />
public partial class _20250626_00_AlterOrganizationReportsql : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "ContentEncryptionKey",
table: "OrganizationReport",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "ContentEncryptionKey",
table: "OrganizationApplication",
type: "text",
nullable: false,
defaultValue: "");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ContentEncryptionKey",
table: "OrganizationReport");
migrationBuilder.DropColumn(
name: "ContentEncryptionKey",
table: "OrganizationApplication");
}
}

View File

@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.PostgresMigrations.Migrations;
/// <inheritdoc />
public partial class _20250701_00_AlterOrganizationApplicationsql : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}

View File

@ -984,6 +984,10 @@ namespace Bit.PostgresMigrations.Migrations
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("CreationDate") b.Property<DateTime>("CreationDate")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp with time zone");
@ -1009,6 +1013,10 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<Guid>("Id") b.Property<Guid>("Id")
.HasColumnType("uuid"); .HasColumnType("uuid");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("CreationDate") b.Property<DateTime>("CreationDate")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp with time zone");

View File

@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.SqliteMigrations.Migrations;
/// <inheritdoc />
public partial class _20250626_00_AlterOrganizationReportsql : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "ContentEncryptionKey",
table: "OrganizationReport",
type: "TEXT",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "ContentEncryptionKey",
table: "OrganizationApplication",
type: "TEXT",
nullable: false,
defaultValue: "");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ContentEncryptionKey",
table: "OrganizationReport");
migrationBuilder.DropColumn(
name: "ContentEncryptionKey",
table: "OrganizationApplication");
}
}

View File

@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.SqliteMigrations.Migrations;
/// <inheritdoc />
public partial class _20250701_00_AlterOrganizationApplicationsql : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}

View File

@ -968,6 +968,10 @@ namespace Bit.SqliteMigrations.Migrations
.IsRequired() .IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreationDate") b.Property<DateTime>("CreationDate")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@ -993,6 +997,10 @@ namespace Bit.SqliteMigrations.Migrations
b.Property<Guid>("Id") b.Property<Guid>("Id")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreationDate") b.Property<DateTime>("CreationDate")
.HasColumnType("TEXT"); .HasColumnType("TEXT");