1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-15 14:47:45 -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 DateTime CreationDate { get; set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; set; } = DateTime.UtcNow;
public string ContentEncryptionKey { get; set; } = string.Empty;
public void SetNewId()
{

View File

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

View File

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

View File

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

View File

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

View File

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

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()
.HasColumnType("longtext");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("CreationDate")
.HasColumnType("datetime(6)");
@ -1004,6 +1008,10 @@ namespace Bit.MySqlMigrations.Migrations
b.Property<Guid>("Id")
.HasColumnType("char(36)");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("CreationDate")
.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()
.HasColumnType("text");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("CreationDate")
.HasColumnType("timestamp with time zone");
@ -1009,6 +1013,10 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<Guid>("Id")
.HasColumnType("uuid");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("CreationDate")
.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()
.HasColumnType("TEXT");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreationDate")
.HasColumnType("TEXT");
@ -993,6 +997,10 @@ namespace Bit.SqliteMigrations.Migrations
b.Property<Guid>("Id")
.HasColumnType("TEXT");
b.Property<string>("ContentEncryptionKey")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreationDate")
.HasColumnType("TEXT");