1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-24 20:58:49 -05:00

Merge branch 'dirt/pm-20574/database_tables_and_scripts_riskinsights' into dirt/pm-20576/report-store-query-commands

This commit is contained in:
voommen-livefront 2025-06-23 09:42:04 -05:00
commit 5f1a9d0d95
22 changed files with 213 additions and 181 deletions

View File

@ -5,14 +5,13 @@ using Bit.Core.Utilities;
namespace Bit.Core.Dirt.Entities;
public class OrganizationReport : ITableObject<Guid>, IRevisable
public class OrganizationReport : ITableObject<Guid>
{
public Guid Id { get; set; }
public Guid OrganizationId { get; set; }
public DateTime Date { get; set; }
public string ReportData { get; set; } = string.Empty;
public DateTime CreationDate { get; set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; set; } = DateTime.UtcNow;
public void SetNewId()
{

View File

@ -8,18 +8,18 @@ AS
SET NOCOUNT ON;
INSERT INTO [dbo].[OrganizationApplication]
(
(
[Id],
[OrganizationId],
[Applications],
[CreationDate],
[RevisionDate]
)
)
VALUES
(
@Id,
@OrganizationId,
@Applications,
@CreationDate,
@RevisionDate
);
@Id,
@OrganizationId,
@Applications,
@CreationDate,
@RevisionDate
);

View File

@ -3,7 +3,5 @@ CREATE PROCEDURE [dbo].[OrganizationApplication_DeleteById]
AS
SET NOCOUNT ON;
DELETE FROM
[dbo].[OrganizationApplication]
WHERE
[Id] = @Id;
DELETE FROM [dbo].[OrganizationApplication]
WHERE [Id] = @Id;

View File

@ -4,10 +4,6 @@ AS
SET NOCOUNT ON;
SELECT
[Id],
[OrganizationId],
[Applications],
[CreationDate],
[RevisionDate]
*
FROM [dbo].[OrganizationApplicationView]
WHERE [Id] = @Id;

View File

@ -4,10 +4,6 @@ AS
SET NOCOUNT ON;
SELECT
[Id],
[OrganizationId],
[Applications],
[CreationDate],
[RevisionDate]
*
FROM [dbo].[OrganizationApplicationView]
WHERE [OrganizationId] = @OrganizationId;

View File

@ -6,9 +6,11 @@ CREATE PROCEDURE [dbo].[OrganizationApplication_Update]
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
UPDATE [dbo].[OrganizationApplication]
SET
[OrganizationId] = @OrganizationId,
[Applications] = @Applications,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE [Id] = @Id;

View File

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

View File

@ -4,11 +4,6 @@ AS
SET NOCOUNT ON;
SELECT
[Id],
[OrganizationId],
[Date],
[ReportData],
[CreationDate],
[RevisionDate]
FROM [dbo].[OrganizationReport]
*
FROM [dbo].[OrganizationReportView]
WHERE [Id] = @Id;

View File

@ -4,11 +4,6 @@ AS
SET NOCOUNT ON;
SELECT
[Id],
[OrganizationId],
[Date],
[ReportData],
[CreationDate],
[RevisionDate]
FROM [dbo].[OrganizationReport]
*
FROM [dbo].[OrganizationReportView]
WHERE [OrganizationId] = @OrganizationId;

View File

@ -1,16 +0,0 @@
CREATE PROCEDURE [dbo].[OrganizationReport_Update]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7),
@ReportData NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
UPDATE [dbo].[OrganizationReport]
SET [OrganizationId] = @OrganizationId,
[Date] = @Date,
[ReportData] = @ReportData,
[RevisionDate] = @RevisionDate
WHERE [Id] = @Id;

View File

@ -4,7 +4,6 @@ CREATE TABLE [dbo].[OrganizationReport] (
[Date] DATETIME2 (7) NOT NULL,
[ReportData] NVARCHAR(MAX) NOT NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
CONSTRAINT [PK_OrganizationReport] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_OrganizationReport_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
);
@ -16,4 +15,4 @@ GO
CREATE NONCLUSTERED INDEX [IX_OrganizationReport_OrganizationId_Date]
ON [dbo].[OrganizationReport]([OrganizationId] ASC, [Date] DESC);
GO
GO

View File

@ -7,7 +7,6 @@ BEGIN
[Date] DATETIME2 (7) NOT NULL,
[ReportData] NVARCHAR(MAX) NOT NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
CONSTRAINT [PK_OrganizationReport] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_OrganizationReport_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
);
@ -32,8 +31,7 @@ CREATE PROCEDURE [dbo].[OrganizationReport_Create]
@OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7),
@ReportData NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
@CreationDate DATETIME2(7)
AS
SET NOCOUNT ON;
@ -42,16 +40,14 @@ AS
[OrganizationId],
[Date],
[ReportData],
[CreationDate],
[RevisionDate]
[CreationDate]
)
VALUES (
@Id,
@OrganizationId,
@Date,
@ReportData,
@CreationDate,
@RevisionDate
@CreationDate
);
GO
@ -71,13 +67,8 @@ AS
SET NOCOUNT ON;
SELECT
[Id],
[OrganizationId],
[Date],
[ReportData],
[CreationDate],
[RevisionDate]
FROM [dbo].[OrganizationReport]
*
FROM [dbo].[OrganizationReportView]
WHERE [Id] = @Id;
GO
@ -88,31 +79,7 @@ AS
SET NOCOUNT ON;
SELECT
[Id],
[OrganizationId],
[Date],
[ReportData],
[CreationDate],
[RevisionDate]
FROM [dbo].[OrganizationReport]
*
FROM [dbo].[OrganizationReportView]
WHERE [OrganizationId] = @OrganizationId;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_Update]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7),
@ReportData NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
UPDATE [dbo].[OrganizationReport]
SET [OrganizationId] = @OrganizationId,
[Date] = @Date,
[ReportData] = @ReportData,
[RevisionDate] = @RevisionDate
WHERE [Id] = @Id;
GO

View File

@ -1,26 +1,22 @@
IF OBJECT_ID('dbo.OrganizationApplication') IS NULL
BEGIN
CREATE TABLE [dbo].[OrganizationApplication]
(
[Id] UNIQUEIDENTIFIER NOT NULL,
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
[Applications] NVARCHAR(MAX) NOT NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
CREATE TABLE [dbo].[OrganizationApplication] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
[Applications] NVARCHAR(MAX) NOT NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
CONSTRAINT [PK_OrganizationApplication] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_OrganizationApplication_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
);
);
CREATE NONCLUSTERED INDEX [IX_OrganizationApplication_OrganizationId]
ON [dbo].[OrganizationApplication]([OrganizationId] ASC);
END
GO
CREATE OR ALTER VIEW [dbo].[OrganizationApplicationView]
AS
SELECT *
FROM [dbo].[OrganizationApplication];
CREATE OR ALTER VIEW [dbo].[OrganizationApplicationView] AS
SELECT * FROM [dbo].[OrganizationApplication];
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_Create]
@ -33,50 +29,21 @@ AS
SET NOCOUNT ON;
INSERT INTO [dbo].[OrganizationApplication]
(
(
[Id],
[OrganizationId],
[Applications],
[CreationDate],
[RevisionDate]
)
)
VALUES
(
@Id,
@OrganizationId,
@Applications,
@CreationDate,
@RevisionDate
);
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_DeleteById]
@Id UNIQUEIDENTIFIER
AS
SET NOCOUNT ON;
DELETE FROM
[dbo].[OrganizationApplication]
WHERE
[Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_ReadById]
@Id UNIQUEIDENTIFIER
AS
SET NOCOUNT ON;
SELECT
[Id],
[OrganizationId],
[Applications],
[CreationDate],
[RevisionDate]
FROM [dbo].[OrganizationApplicationView]
WHERE [Id] = @Id;
@Id,
@OrganizationId,
@Applications,
@CreationDate,
@RevisionDate
);
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_ReadByOrganizationId]
@ -85,14 +52,20 @@ AS
SET NOCOUNT ON;
SELECT
[Id],
[OrganizationId],
[Applications],
[CreationDate],
[RevisionDate]
*
FROM [dbo].[OrganizationApplicationView]
WHERE [OrganizationId] = @OrganizationId;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_ReadById]
@Id UNIQUEIDENTIFIER
AS
SET NOCOUNT ON;
SELECT
*
FROM [dbo].[OrganizationApplicationView]
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_Update]
@ -103,11 +76,22 @@ CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_Update]
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
UPDATE [dbo].[OrganizationApplication]
SET
[OrganizationId] = @OrganizationId,
[Applications] = @Applications,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_DeleteById]
@Id UNIQUEIDENTIFIER
AS
SET NOCOUNT ON;
DELETE FROM [dbo].[OrganizationApplication]
WHERE [Id] = @Id;
GO

View File

@ -25,6 +25,53 @@ namespace Bit.MySqlMigrations.Migrations
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
modelBuilder.Entity("Bit.Core.Dirt.Reports.Models.Data.OrganizationMemberBaseDetail", b =>
{
b.Property<Guid>("CipherId")
.HasColumnType("char(36)");
b.Property<Guid?>("CollectionId")
.HasColumnType("char(36)");
b.Property<string>("CollectionName")
.HasColumnType("longtext");
b.Property<string>("Email")
.HasColumnType("longtext");
b.Property<Guid?>("GroupId")
.HasColumnType("char(36)");
b.Property<string>("GroupName")
.HasColumnType("longtext");
b.Property<bool?>("HidePasswords")
.HasColumnType("tinyint(1)");
b.Property<bool?>("Manage")
.HasColumnType("tinyint(1)");
b.Property<bool?>("ReadOnly")
.HasColumnType("tinyint(1)");
b.Property<string>("ResetPasswordKey")
.HasColumnType("longtext");
b.Property<string>("TwoFactorProviders")
.HasColumnType("longtext");
b.Property<Guid?>("UserGuid")
.HasColumnType("char(36)");
b.Property<string>("UserName")
.HasColumnType("longtext");
b.Property<bool>("UsesKeyConnector")
.HasColumnType("tinyint(1)");
b.ToTable("OrganizationMemberBaseDetails");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", b =>
{
b.Property<Guid>("Id")
@ -970,9 +1017,6 @@ namespace Bit.MySqlMigrations.Migrations
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("RevisionDate")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.HasIndex("Id")

View File

@ -42,8 +42,7 @@ public partial class _2025061300_OrganizationReportsql : Migration
Date = table.Column<DateTime>(type: "datetime(6)", nullable: false),
ReportData = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
CreationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
RevisionDate = table.Column<DateTime>(type: "datetime(6)", nullable: false)
CreationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{

View File

@ -1014,9 +1014,6 @@ namespace Bit.MySqlMigrations.Migrations
.IsRequired()
.HasColumnType("longtext");
b.Property<DateTime>("RevisionDate")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.HasIndex("Id")

View File

@ -26,6 +26,53 @@ namespace Bit.PostgresMigrations.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Bit.Core.Dirt.Reports.Models.Data.OrganizationMemberBaseDetail", b =>
{
b.Property<Guid>("CipherId")
.HasColumnType("uuid");
b.Property<Guid?>("CollectionId")
.HasColumnType("uuid");
b.Property<string>("CollectionName")
.HasColumnType("text");
b.Property<string>("Email")
.HasColumnType("text");
b.Property<Guid?>("GroupId")
.HasColumnType("uuid");
b.Property<string>("GroupName")
.HasColumnType("text");
b.Property<bool?>("HidePasswords")
.HasColumnType("boolean");
b.Property<bool?>("Manage")
.HasColumnType("boolean");
b.Property<bool?>("ReadOnly")
.HasColumnType("boolean");
b.Property<string>("ResetPasswordKey")
.HasColumnType("text");
b.Property<string>("TwoFactorProviders")
.HasColumnType("text");
b.Property<Guid?>("UserGuid")
.HasColumnType("uuid");
b.Property<string>("UserName")
.HasColumnType("text");
b.Property<bool>("UsesKeyConnector")
.HasColumnType("boolean");
b.ToTable("OrganizationMemberBaseDetails");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", b =>
{
b.Property<Guid>("Id")
@ -975,9 +1022,6 @@ namespace Bit.PostgresMigrations.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("RevisionDate")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("Id")

View File

@ -39,8 +39,7 @@ public partial class _2025061300_OrganizationReportsql : Migration
OrganizationId = table.Column<Guid>(type: "uuid", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
ReportData = table.Column<string>(type: "text", nullable: false),
CreationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
RevisionDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
CreationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{

View File

@ -1019,9 +1019,6 @@ namespace Bit.PostgresMigrations.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("RevisionDate")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("Id")

View File

@ -20,6 +20,53 @@ namespace Bit.SqliteMigrations.Migrations
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.8");
modelBuilder.Entity("Bit.Core.Dirt.Reports.Models.Data.OrganizationMemberBaseDetail", b =>
{
b.Property<Guid>("CipherId")
.HasColumnType("TEXT");
b.Property<Guid?>("CollectionId")
.HasColumnType("TEXT");
b.Property<string>("CollectionName")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasColumnType("TEXT");
b.Property<Guid?>("GroupId")
.HasColumnType("TEXT");
b.Property<string>("GroupName")
.HasColumnType("TEXT");
b.Property<bool?>("HidePasswords")
.HasColumnType("INTEGER");
b.Property<bool?>("Manage")
.HasColumnType("INTEGER");
b.Property<bool?>("ReadOnly")
.HasColumnType("INTEGER");
b.Property<string>("ResetPasswordKey")
.HasColumnType("TEXT");
b.Property<string>("TwoFactorProviders")
.HasColumnType("TEXT");
b.Property<Guid?>("UserGuid")
.HasColumnType("TEXT");
b.Property<string>("UserName")
.HasColumnType("TEXT");
b.Property<bool>("UsesKeyConnector")
.HasColumnType("INTEGER");
b.ToTable("OrganizationMemberBaseDetails");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", b =>
{
b.Property<Guid>("Id")
@ -959,9 +1006,6 @@ namespace Bit.SqliteMigrations.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("RevisionDate")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Id")

View File

@ -39,8 +39,7 @@ public partial class _2025061300_OrganizationReportsql : Migration
OrganizationId = table.Column<Guid>(type: "TEXT", nullable: false),
Date = table.Column<DateTime>(type: "TEXT", nullable: false),
ReportData = table.Column<string>(type: "TEXT", nullable: false),
CreationDate = table.Column<DateTime>(type: "TEXT", nullable: false),
RevisionDate = table.Column<DateTime>(type: "TEXT", nullable: false)
CreationDate = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{

View File

@ -1003,9 +1003,6 @@ namespace Bit.SqliteMigrations.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("RevisionDate")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Id")