mirror of
https://github.com/bitwarden/server.git
synced 2025-05-22 12:04:27 -05:00
[PM-221] Adding CipherId to the Send table, create/update sprocs, and added mi… (#3646)
* Adding CipherId to the Send table, create/update sprocs, and added migrations * changing migrator script to drop create sprocs * fixing double brackets * Revert "changing migrator script to drop create sprocs" This reverts commit 2d5171e7e52ee46c88d024a85f326476b338629a. * Remove comment I nitpicked * Script best practices * Fix typo * Try recreate again * Fix missing output * Revert "Try recreate again" This reverts commit 38257ebeaa1a7922b75c19a496aa22acc7e1351d. --------- Co-authored-by: Matt Bishop <mbishop@bitwarden.com> Co-authored-by: federicom09 <fmonesiglio@bitwarden.com>
This commit is contained in:
parent
94d665e6e9
commit
997af0f6ab
@ -117,6 +117,11 @@ public class Send : ITableObject<Guid>
|
|||||||
/// </value>
|
/// </value>
|
||||||
public bool? HideEmail { get; set; }
|
public bool? HideEmail { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Identifies the Cipher associated with this send.
|
||||||
|
/// </summary>
|
||||||
|
public Guid? CipherId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates the send's <see cref="Id" />
|
/// Generates the send's <see cref="Id" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
@ExpirationDate DATETIME2(7),
|
@ExpirationDate DATETIME2(7),
|
||||||
@DeletionDate DATETIME2(7),
|
@DeletionDate DATETIME2(7),
|
||||||
@Disabled BIT,
|
@Disabled BIT,
|
||||||
@HideEmail BIT
|
@HideEmail BIT,
|
||||||
|
@CipherId UNIQUEIDENTIFIER = NULL
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
@ -34,7 +35,8 @@ BEGIN
|
|||||||
[ExpirationDate],
|
[ExpirationDate],
|
||||||
[DeletionDate],
|
[DeletionDate],
|
||||||
[Disabled],
|
[Disabled],
|
||||||
[HideEmail]
|
[HideEmail],
|
||||||
|
[CipherId]
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
(
|
(
|
||||||
@ -52,7 +54,8 @@ BEGIN
|
|||||||
@ExpirationDate,
|
@ExpirationDate,
|
||||||
@DeletionDate,
|
@DeletionDate,
|
||||||
@Disabled,
|
@Disabled,
|
||||||
@HideEmail
|
@HideEmail,
|
||||||
|
@CipherId
|
||||||
)
|
)
|
||||||
|
|
||||||
IF @UserId IS NOT NULL
|
IF @UserId IS NOT NULL
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
@ExpirationDate DATETIME2(7),
|
@ExpirationDate DATETIME2(7),
|
||||||
@DeletionDate DATETIME2(7),
|
@DeletionDate DATETIME2(7),
|
||||||
@Disabled BIT,
|
@Disabled BIT,
|
||||||
@HideEmail BIT
|
@HideEmail BIT,
|
||||||
|
@CipherId UNIQUEIDENTIFIER = NULL
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
@ -34,7 +35,8 @@ BEGIN
|
|||||||
[ExpirationDate] = @ExpirationDate,
|
[ExpirationDate] = @ExpirationDate,
|
||||||
[DeletionDate] = @DeletionDate,
|
[DeletionDate] = @DeletionDate,
|
||||||
[Disabled] = @Disabled,
|
[Disabled] = @Disabled,
|
||||||
[HideEmail] = @HideEmail
|
[HideEmail] = @HideEmail,
|
||||||
|
[CipherId] = @CipherId
|
||||||
WHERE
|
WHERE
|
||||||
[Id] = @Id
|
[Id] = @Id
|
||||||
|
|
||||||
|
@ -14,9 +14,11 @@
|
|||||||
[DeletionDate] DATETIME2 (7) NOT NULL,
|
[DeletionDate] DATETIME2 (7) NOT NULL,
|
||||||
[Disabled] BIT NOT NULL,
|
[Disabled] BIT NOT NULL,
|
||||||
[HideEmail] BIT NULL,
|
[HideEmail] BIT NULL,
|
||||||
|
[CipherId] UNIQUEIDENTIFIER NULL,
|
||||||
CONSTRAINT [PK_Send] PRIMARY KEY CLUSTERED ([Id] ASC),
|
CONSTRAINT [PK_Send] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||||
CONSTRAINT [FK_Send_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
|
CONSTRAINT [FK_Send_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
|
||||||
CONSTRAINT [FK_Send_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
|
CONSTRAINT [FK_Send_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]),
|
||||||
|
CONSTRAINT [FK_Send_Cipher] FOREIGN KEY ([CipherId]) REFERENCES [dbo].[Cipher] ([Id])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
134
util/Migrator/DbScripts/2024-01-04_00_Send_Add_CipherId.sql
Normal file
134
util/Migrator/DbScripts/2024-01-04_00_Send_Add_CipherId.sql
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
-- Add CipherId column
|
||||||
|
IF COL_LENGTH('[dbo].[Send]', 'CipherId') IS NULL
|
||||||
|
BEGIN
|
||||||
|
ALTER TABLE [dbo].[Send]
|
||||||
|
ADD [CipherId] UNIQUEIDENTIFIER NULL,
|
||||||
|
CONSTRAINT [FK_Send_Cipher] FOREIGN KEY ([CipherId]) REFERENCES [dbo].[Cipher]([Id]);
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Refresh View
|
||||||
|
EXECUTE sp_refreshview N'[dbo].[SendView]'
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[Send_Create]
|
||||||
|
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@Type TINYINT,
|
||||||
|
@Data VARCHAR(MAX),
|
||||||
|
@Key VARCHAR(MAX),
|
||||||
|
@Password NVARCHAR(300),
|
||||||
|
@MaxAccessCount INT,
|
||||||
|
@AccessCount INT,
|
||||||
|
@CreationDate DATETIME2(7),
|
||||||
|
@RevisionDate DATETIME2(7),
|
||||||
|
@ExpirationDate DATETIME2(7),
|
||||||
|
@DeletionDate DATETIME2(7),
|
||||||
|
@Disabled BIT,
|
||||||
|
@HideEmail BIT,
|
||||||
|
@CipherId UNIQUEIDENTIFIER = NULL
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
INSERT INTO [dbo].[Send]
|
||||||
|
(
|
||||||
|
[Id],
|
||||||
|
[UserId],
|
||||||
|
[OrganizationId],
|
||||||
|
[Type],
|
||||||
|
[Data],
|
||||||
|
[Key],
|
||||||
|
[Password],
|
||||||
|
[MaxAccessCount],
|
||||||
|
[AccessCount],
|
||||||
|
[CreationDate],
|
||||||
|
[RevisionDate],
|
||||||
|
[ExpirationDate],
|
||||||
|
[DeletionDate],
|
||||||
|
[Disabled],
|
||||||
|
[HideEmail],
|
||||||
|
[CipherId]
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
@Id,
|
||||||
|
@UserId,
|
||||||
|
@OrganizationId,
|
||||||
|
@Type,
|
||||||
|
@Data,
|
||||||
|
@Key,
|
||||||
|
@Password,
|
||||||
|
@MaxAccessCount,
|
||||||
|
@AccessCount,
|
||||||
|
@CreationDate,
|
||||||
|
@RevisionDate,
|
||||||
|
@ExpirationDate,
|
||||||
|
@DeletionDate,
|
||||||
|
@Disabled,
|
||||||
|
@HideEmail,
|
||||||
|
@CipherId
|
||||||
|
)
|
||||||
|
|
||||||
|
IF @UserId IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
IF @Type = 1 --File
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[User_UpdateStorage] @UserId
|
||||||
|
END
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||||
|
END
|
||||||
|
-- TODO: OrganizationId bump?
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[Send_Update]
|
||||||
|
@Id UNIQUEIDENTIFIER,
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@Type TINYINT,
|
||||||
|
@Data VARCHAR(MAX),
|
||||||
|
@Key VARCHAR(MAX),
|
||||||
|
@Password NVARCHAR(300),
|
||||||
|
@MaxAccessCount INT,
|
||||||
|
@AccessCount INT,
|
||||||
|
@CreationDate DATETIME2(7),
|
||||||
|
@RevisionDate DATETIME2(7),
|
||||||
|
@ExpirationDate DATETIME2(7),
|
||||||
|
@DeletionDate DATETIME2(7),
|
||||||
|
@Disabled BIT,
|
||||||
|
@HideEmail BIT,
|
||||||
|
@CipherId UNIQUEIDENTIFIER = NULL
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
[dbo].[Send]
|
||||||
|
SET
|
||||||
|
[UserId] = @UserId,
|
||||||
|
[OrganizationId] = @OrganizationId,
|
||||||
|
[Type] = @Type,
|
||||||
|
[Data] = @Data,
|
||||||
|
[Key] = @Key,
|
||||||
|
[Password] = @Password,
|
||||||
|
[MaxAccessCount] = @MaxAccessCount,
|
||||||
|
[AccessCount] = @AccessCount,
|
||||||
|
[CreationDate] = @CreationDate,
|
||||||
|
[RevisionDate] = @RevisionDate,
|
||||||
|
[ExpirationDate] = @ExpirationDate,
|
||||||
|
[DeletionDate] = @DeletionDate,
|
||||||
|
[Disabled] = @Disabled,
|
||||||
|
[HideEmail] = @HideEmail,
|
||||||
|
[CipherId] = @CipherId
|
||||||
|
WHERE
|
||||||
|
[Id] = @Id
|
||||||
|
|
||||||
|
IF @UserId IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||||
|
END
|
||||||
|
-- TODO: OrganizationId bump?
|
||||||
|
END
|
||||||
|
GO
|
2337
util/MySqlMigrations/Migrations/20240104162658_AddCipherIdToSend.Designer.cs
generated
Normal file
2337
util/MySqlMigrations/Migrations/20240104162658_AddCipherIdToSend.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bit.MySqlMigrations.Migrations;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddCipherIdToSend : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<Guid>(
|
||||||
|
name: "CipherId",
|
||||||
|
table: "Send",
|
||||||
|
type: "char(36)",
|
||||||
|
nullable: true,
|
||||||
|
collation: "ascii_general_ci");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CipherId",
|
||||||
|
table: "Send");
|
||||||
|
}
|
||||||
|
}
|
@ -1157,6 +1157,9 @@ namespace Bit.MySqlMigrations.Migrations
|
|||||||
b.Property<int>("AccessCount")
|
b.Property<int>("AccessCount")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<Guid?>("CipherId")
|
||||||
|
.HasColumnType("char(36)");
|
||||||
|
|
||||||
b.Property<DateTime>("CreationDate")
|
b.Property<DateTime>("CreationDate")
|
||||||
.HasColumnType("datetime(6)");
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
2350
util/PostgresMigrations/Migrations/20240104162650_AddCipherIdToSend.Designer.cs
generated
Normal file
2350
util/PostgresMigrations/Migrations/20240104162650_AddCipherIdToSend.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bit.PostgresMigrations.Migrations;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddCipherIdToSend : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<Guid>(
|
||||||
|
name: "CipherId",
|
||||||
|
table: "Send",
|
||||||
|
type: "uuid",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CipherId",
|
||||||
|
table: "Send");
|
||||||
|
}
|
||||||
|
}
|
@ -1170,6 +1170,9 @@ namespace Bit.PostgresMigrations.Migrations
|
|||||||
b.Property<int>("AccessCount")
|
b.Property<int>("AccessCount")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<Guid?>("CipherId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
b.Property<DateTime>("CreationDate")
|
b.Property<DateTime>("CreationDate")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
2335
util/SqliteMigrations/Migrations/20240104162642_AddCipherIdToSend.Designer.cs
generated
Normal file
2335
util/SqliteMigrations/Migrations/20240104162642_AddCipherIdToSend.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bit.SqliteMigrations.Migrations;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddCipherIdToSend : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<Guid>(
|
||||||
|
name: "CipherId",
|
||||||
|
table: "Send",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CipherId",
|
||||||
|
table: "Send");
|
||||||
|
}
|
||||||
|
}
|
@ -1155,6 +1155,9 @@ namespace Bit.SqliteMigrations.Migrations
|
|||||||
b.Property<int>("AccessCount")
|
b.Property<int>("AccessCount")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<Guid?>("CipherId")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<DateTime>("CreationDate")
|
b.Property<DateTime>("CreationDate")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user