1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-06 19:28:08 +01:00

chore(db): add Installation.LastActivityDate column (#5060)

* chore(mssql): add `Installation.LastActivityDate` column

* chore(ef): add `Installation.LastActivityDate` column
This commit is contained in:
Addison Beck 2024-12-13 16:04:55 -05:00 committed by GitHub
parent 141a046a28
commit a8091bf585
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 9014 additions and 14 deletions

View File

@ -4,12 +4,20 @@ namespace Bit.Infrastructure.EntityFramework.Models;
public class Installation : Core.Entities.Installation
{
// Shadow property - to be introduced by https://bitwarden.atlassian.net/browse/PM-11129
// This isn't a value or entity used by self hosted servers, but it's
// being added for synchronicity between database provider options.
public DateTime? LastActivityDate { get; set; }
}
public class InstallationMapperProfile : Profile
{
public InstallationMapperProfile()
{
CreateMap<Core.Entities.Installation, Installation>()
// Shadow property - to be introduced by https://bitwarden.atlassian.net/browse/PM-11129
.ForMember(i => i.LastActivityDate, opt => opt.Ignore())
.ReverseMap();
CreateMap<Core.Entities.Installation, Installation>().ReverseMap();
}
}

View File

@ -1,9 +1,10 @@
CREATE PROCEDURE [dbo].[Installation_Create]
CREATE PROCEDURE [dbo].[Installation_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@Email NVARCHAR(256),
@Key VARCHAR(150),
@Enabled BIT,
@CreationDate DATETIME2(7)
@CreationDate DATETIME2(7),
@LastActivityDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON
@ -14,7 +15,8 @@ BEGIN
[Email],
[Key],
[Enabled],
[CreationDate]
[CreationDate],
[LastActivityDate]
)
VALUES
(
@ -22,6 +24,7 @@ BEGIN
@Email,
@Key,
@Enabled,
@CreationDate
@CreationDate,
@LastActivityDate
)
END

View File

@ -1,9 +1,10 @@
CREATE PROCEDURE [dbo].[Installation_Update]
CREATE PROCEDURE [dbo].[Installation_Update]
@Id UNIQUEIDENTIFIER,
@Email NVARCHAR(256),
@Key VARCHAR(150),
@Enabled BIT,
@CreationDate DATETIME2(7)
@CreationDate DATETIME2(7),
@LastActivityDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON
@ -14,7 +15,8 @@ BEGIN
[Email] = @Email,
[Key] = @Key,
[Enabled] = @Enabled,
[CreationDate] = @CreationDate
[CreationDate] = @CreationDate,
[LastActivityDate] = @LastActivityDate
WHERE
[Id] = @Id
END
END

View File

@ -1,9 +1,10 @@
CREATE TABLE [dbo].[Installation] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[Email] NVARCHAR (256) NOT NULL,
[Key] VARCHAR (150) NOT NULL,
[Enabled] BIT NOT NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
CREATE TABLE [dbo].[Installation] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[Email] NVARCHAR (256) NOT NULL,
[Key] VARCHAR (150) NOT NULL,
[Enabled] BIT NOT NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[LastActivityDate] DATETIME2 (7) NULL,
CONSTRAINT [PK_Installation] PRIMARY KEY CLUSTERED ([Id] ASC)
);

View File

@ -0,0 +1,72 @@
IF COL_LENGTH('[dbo].[Installation]', 'LastActivityDate') IS NULL
BEGIN
ALTER TABLE
[dbo].[Installation]
ADD
[LastActivityDate] DATETIME2 (7) NULL
END
GO
CREATE OR ALTER VIEW [dbo].[InstallationView]
AS
SELECT
*
FROM
[dbo].[Installation]
GO
CREATE OR ALTER PROCEDURE [dbo].[Installation_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@Email NVARCHAR(256),
@Key VARCHAR(150),
@Enabled BIT,
@CreationDate DATETIME2(7),
@LastActivityDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[Installation]
(
[Id],
[Email],
[Key],
[Enabled],
[CreationDate],
[LastActivityDate]
)
VALUES
(
@Id,
@Email,
@Key,
@Enabled,
@CreationDate,
@LastActivityDate
)
END
GO
CREATE OR ALTER PROCEDURE [dbo].[Installation_Update]
@Id UNIQUEIDENTIFIER,
@Email NVARCHAR(256),
@Key VARCHAR(150),
@Enabled BIT,
@CreationDate DATETIME2(7),
@LastActivityDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[Installation]
SET
[Email] = @Email,
[Key] = @Key,
[Enabled] = @Enabled,
[CreationDate] = @CreationDate,
[LastActivityDate] = @LastActivityDate
WHERE
[Id] = @Id
END
GO

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.MySqlMigrations.Migrations;
/// <inheritdoc />
public partial class AddInstallationLastActivityDateColumn : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "LastActivityDate",
table: "Installation",
type: "datetime(6)",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "LastActivityDate",
table: "Installation");
}
}

View File

@ -1165,6 +1165,9 @@ namespace Bit.MySqlMigrations.Migrations
.HasMaxLength(150)
.HasColumnType("varchar(150)");
b.Property<DateTime?>("LastActivityDate")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.ToTable("Installation", (string)null);

View File

@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.PostgresMigrations.Migrations;
/// <inheritdoc />
public partial class AddInstallationLastActivityDateColumn : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "LastActivityDate",
table: "Installation",
type: "timestamp with time zone",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "LastActivityDate",
table: "Installation");
}
}

View File

@ -1170,6 +1170,9 @@ namespace Bit.PostgresMigrations.Migrations
.HasMaxLength(150)
.HasColumnType("character varying(150)");
b.Property<DateTime?>("LastActivityDate")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Installation", (string)null);

View File

@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.SqliteMigrations.Migrations;
/// <inheritdoc />
public partial class AddInstallationLastActivityDateColumn : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "LastActivityDate",
table: "Installation",
type: "TEXT",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "LastActivityDate",
table: "Installation");
}
}

View File

@ -1154,6 +1154,9 @@ namespace Bit.SqliteMigrations.Migrations
.HasMaxLength(150)
.HasColumnType("TEXT");
b.Property<DateTime?>("LastActivityDate")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Installation", (string)null);