From 1b6adf40f155e599d8e81724f3e4ac8fb2b29d81 Mon Sep 17 00:00:00 2001 From: Graham Walker Date: Fri, 16 May 2025 17:35:55 -0500 Subject: [PATCH] PM-20574 adding tables, stored procedures, and migration files --- .../RiskInsightCriticalApplication.cs | 18 +++ .../Reports/Entities/RiskInsightReport.cs | 19 +++ .../RiskInsightCriticalApplication_Create.sql | 25 ++++ ...kInsightCriticalApplication_DeleteById.sql | 10 ++ ...iticalApplication_ReadByOrganizationId.sql | 16 +++ ...skInsightCriticalApplication_ReadyById.sql | 16 +++ .../RiskInsightCriticalApplication_Update.sql | 13 ++ .../RiskInsightReport_Create.sql | 12 ++ .../RiskInsightReport_DeleteById.sql | 10 ++ .../RiskInsightReport_ReadById.Sql | 17 +++ ...RiskInsightReport_ReadByOrganizationId.sql | 17 +++ .../RiskInsightReport_Update.sql | 14 ++ .../Tables/RiskInsightCriticalApplication.sql | 12 ++ src/Sql/Dirt/dbo/Tables/RiskInsightReport.sql | 13 ++ .../RiskInsightCriticalApplicationView.sql | 5 + .../Dirt/dbo/Views/RiskInsightReportView.sql | 2 + .../2025-05-16-00_RiskInsightReport.sql | 111 +++++++++++++++ ...5-16-01_RiskInsightCriticalApplication.sql | 126 ++++++++++++++++++ 18 files changed, 456 insertions(+) create mode 100644 src/Core/Dirt/Reports/Entities/RiskInsightCriticalApplication.cs create mode 100644 src/Core/Dirt/Reports/Entities/RiskInsightReport.cs create mode 100644 src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_Create.sql create mode 100644 src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_DeleteById.sql create mode 100644 src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_ReadByOrganizationId.sql create mode 100644 src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_ReadyById.sql create mode 100644 src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_Update.sql create mode 100644 src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_Create.sql create mode 100644 src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_DeleteById.sql create mode 100644 src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_ReadById.Sql create mode 100644 src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_ReadByOrganizationId.sql create mode 100644 src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_Update.sql create mode 100644 src/Sql/Dirt/dbo/Tables/RiskInsightCriticalApplication.sql create mode 100644 src/Sql/Dirt/dbo/Tables/RiskInsightReport.sql create mode 100644 src/Sql/Dirt/dbo/Views/RiskInsightCriticalApplicationView.sql create mode 100644 src/Sql/Dirt/dbo/Views/RiskInsightReportView.sql create mode 100644 util/Migrator/DbScripts/2025-05-16-00_RiskInsightReport.sql create mode 100644 util/Migrator/DbScripts/2025-05-16-01_RiskInsightCriticalApplication.sql diff --git a/src/Core/Dirt/Reports/Entities/RiskInsightCriticalApplication.cs b/src/Core/Dirt/Reports/Entities/RiskInsightCriticalApplication.cs new file mode 100644 index 0000000000..68731266e5 --- /dev/null +++ b/src/Core/Dirt/Reports/Entities/RiskInsightCriticalApplication.cs @@ -0,0 +1,18 @@ +using Bit.Core.Entities; +using Bit.Core.Utilities; + +namespace Bit.Core.Dirt.Reports.Entities; + +public class RiskInsightCriticalApplication : ITableObject, IRevisable +{ + public Guid Id { get; set; } + public Guid OrganizationId { get; set; } + public string Applications { get; set; } = string.Empty; + public DateTime CreationDate { get; set; } = DateTime.UtcNow; + public DateTime RevisionDate { get; set; } = DateTime.UtcNow; + + public void SetNewId() + { + Id = CoreHelpers.GenerateComb(); + } +} diff --git a/src/Core/Dirt/Reports/Entities/RiskInsightReport.cs b/src/Core/Dirt/Reports/Entities/RiskInsightReport.cs new file mode 100644 index 0000000000..d5edf7ca28 --- /dev/null +++ b/src/Core/Dirt/Reports/Entities/RiskInsightReport.cs @@ -0,0 +1,19 @@ +using Bit.Core.Entities; +using Bit.Core.Utilities; + +namespace Bit.Core.Dirt.Reports.Entities; + +public class RiskInsightReport : ITableObject, IRevisable +{ + 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() + { + Id = CoreHelpers.GenerateComb(); + } +} diff --git a/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_Create.sql b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_Create.sql new file mode 100644 index 0000000000..2c4d39aa4e --- /dev/null +++ b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_Create.sql @@ -0,0 +1,25 @@ +CREATE PROCEDURE [dbo].[RiskInsightCriticalApplication_Create] + @Id UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER, + @Applications NVARCHAR(MAX), + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7) +AS + SET NOCOUNT ON; + + INSERT INTO [dbo].[RiskInsightCriticalApplication] + ( + [Id], + [OrganizationId], + [Applications], + [CreationDate], + [RevisionDate] + ) + VALUES + ( + @Id, + @OrganizationId, + @Applications, + @CreationDate, + @RevisionDate + ); diff --git a/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_DeleteById.sql b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_DeleteById.sql new file mode 100644 index 0000000000..eb7ac6807d --- /dev/null +++ b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_DeleteById.sql @@ -0,0 +1,10 @@ +CREATE PROCEDURE [dbo].[RiskInsightCriticalApplication_DeleteById] + @Id UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @Id IS NULL + THROW 50000, 'Id cannot be null', 1; + + DELETE FROM [dbo].[RiskInsightCriticalApplication] + WHERE [Id] = @Id diff --git a/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_ReadByOrganizationId.sql b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_ReadByOrganizationId.sql new file mode 100644 index 0000000000..c3228d0249 --- /dev/null +++ b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_ReadByOrganizationId.sql @@ -0,0 +1,16 @@ +CREATE PROCEDURE [dbo].[RiskInsightCriticalApplication_ReadByOrganizationId] + @OrganizationId UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @OrganizationId IS NULL + THROW 50000, 'OrganizationId cannot be null', 1; + + SELECT + [Id], + [OrganizationId], + [Applications], + [CreationDate], + [RevisionDate] + FROM [dbo].[RiskInsightCriticalApplication] + WHERE [OrganizationId] = @OrganizationId; diff --git a/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_ReadyById.sql b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_ReadyById.sql new file mode 100644 index 0000000000..4b539a483b --- /dev/null +++ b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_ReadyById.sql @@ -0,0 +1,16 @@ +CREATE PROCEDURE [dbo].[RiskInsightCriticalApplication_ReadById] + @Id UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @Id IS NULL + THROW 50000, 'Id cannot be null', 1; + + SELECT + [Id], + [OrganizationId], + [Applications], + [CreationDate], + [RevisionDate] + FROM [dbo].[RiskInsightCriticalApplication] + WHERE [Id] = @Id; diff --git a/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_Update.sql b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_Update.sql new file mode 100644 index 0000000000..b595a0d306 --- /dev/null +++ b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightCriticalApplication_Update.sql @@ -0,0 +1,13 @@ +CREATE PROCEDURE [dbo].[RiskInsightCriticalApplication_Update] + @Id UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER, + @Applications NVARCHAR(MAX), + @RevisionDate DATETIME2(7) +AS + SET NOCOUNT ON; + UPDATE [dbo].[RiskInsightCriticalApplication] + SET + [OrganizationId] = @OrganizationId, + [Applications] = @Applications, + [RevisionDate] = @RevisionDate + WHERE [Id] = @Id; diff --git a/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_Create.sql b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_Create.sql new file mode 100644 index 0000000000..7c8fe67bdd --- /dev/null +++ b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_Create.sql @@ -0,0 +1,12 @@ +CREATE PROCEDURE [dbo].[RiskInsightReport_Create] + @Id UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER, + @Date DATETIME2(7), + @ReportData NVARCHAR(MAX), + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7) +AS + SET NOCOUNT ON; + + INSERT INTO [dbo].[RiskInsightReport]( [Id],[OrganizationId],[Date],[ReportData],[CreationDate],[RevisionDate] ) + VALUES ( @Id,@OrganizationId,@Date,@ReportData,@CreationDate,@RevisionDate); diff --git a/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_DeleteById.sql b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_DeleteById.sql new file mode 100644 index 0000000000..bcb8ae6f36 --- /dev/null +++ b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_DeleteById.sql @@ -0,0 +1,10 @@ +CREATE PROCEDURE [dbo].[RiskInsightReport_DeleteById] + @Id UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @Id IS NULL + THROW 50000, 'Id cannot be null', 1; + + DELETE FROM [dbo].[RiskInsightReport] + WHERE [Id] = @Id diff --git a/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_ReadById.Sql b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_ReadById.Sql new file mode 100644 index 0000000000..8a77f5c655 --- /dev/null +++ b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_ReadById.Sql @@ -0,0 +1,17 @@ +CREATE PROCEDURE [dbo].[RiskInsightReport_ReadById] + @Id UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @Id IS NULL + THROW 50000, 'Id cannot be null', 1; + + SELECT + [Id], + [OrganizationId], + [Date], + [ReportData], + [CreationDate], + [RevisionDate] + FROM [dbo].[RiskInsightReport] + WHERE [Id] = @Id; diff --git a/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_ReadByOrganizationId.sql b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_ReadByOrganizationId.sql new file mode 100644 index 0000000000..e0f8384310 --- /dev/null +++ b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_ReadByOrganizationId.sql @@ -0,0 +1,17 @@ +CREATE PROCEDURE [dbo].[RiskInsightReport_ReadByOrganizationId] + @OrganizationId UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @OrganizationId IS NULL + THROW 50000, 'OrganizationId cannot be null', 1; + + SELECT + [Id], + [OrganizationId], + [Date], + [ReportData], + [CreationDate], + [RevisionDate] + FROM [dbo].[RiskInsightReport] + WHERE [OrganizationId] = @OrganizationId; diff --git a/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_Update.sql b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_Update.sql new file mode 100644 index 0000000000..05bd0ec71f --- /dev/null +++ b/src/Sql/Dirt/dbo/Stored Procedures/RiskInsightReport_Update.sql @@ -0,0 +1,14 @@ +CREATE PROCEDURE [dbo].[RiskInsightReport_Update] + @Id UNIQUEIDENTIFIER OUTPUT, + @OrganizationId UNIQUEIDENTIFIER, + @Date DATETIME2(7), + @ReportData NVARCHAR(MAX), + @RevisionDate DATETIME2(7) +AS + SET NOCOUNT ON; + UPDATE [dbo].[RiskInsightReport] + SET [OrganizationId] = @OrganizationId, + [Date] = @Date, + [ReportData] = @ReportData, + [RevisionDate] = @RevisionDate + WHERE [Id] = @Id diff --git a/src/Sql/Dirt/dbo/Tables/RiskInsightCriticalApplication.sql b/src/Sql/Dirt/dbo/Tables/RiskInsightCriticalApplication.sql new file mode 100644 index 0000000000..cbd4129b8f --- /dev/null +++ b/src/Sql/Dirt/dbo/Tables/RiskInsightCriticalApplication.sql @@ -0,0 +1,12 @@ +CREATE TABLE [dbo].[RiskInsightCriticalApplication] ( + [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_RiskInsightCriticalApplication] PRIMARY KEY CLUSTERED ([Id] ASC), + CONSTRAINT [FK_RiskInsightCriticalApplication_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) + ); + +CREATE NONCLUSTERED INDEX [IX_RiskInsightCriticalApplication_OrganizationId] + ON [dbo].[RiskInsightCriticalApplication]([OrganizationId] ASC); diff --git a/src/Sql/Dirt/dbo/Tables/RiskInsightReport.sql b/src/Sql/Dirt/dbo/Tables/RiskInsightReport.sql new file mode 100644 index 0000000000..13ad139c8c --- /dev/null +++ b/src/Sql/Dirt/dbo/Tables/RiskInsightReport.sql @@ -0,0 +1,13 @@ +CREATE TABLE [dbo].[RiskInsightReport] ( + [Id] UNIQUEIDENTIFIER NOT NULL, + [OrganizationId] UNIQUEIDENTIFIER NOT NULL, + [Date] DATETIME2 (7) NOT NULL, + [ReportData] NVARCHAR(MAX) NOT NULL, + [CreationDate] DATETIME2 (7) NOT NULL, + [RevisionDate] DATETIME2 (7) NOT NULL, + CONSTRAINT [PK_RiskInsightReport] PRIMARY KEY CLUSTERED ([Id] ASC), + CONSTRAINT [FK_RiskInsightReport_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) + ); + +CREATE NONCLUSTERED INDEX [IX_RiskInsightReport_OrganizationId] + ON [dbo].[RiskInsightReport]([OrganizationId] ASC); diff --git a/src/Sql/Dirt/dbo/Views/RiskInsightCriticalApplicationView.sql b/src/Sql/Dirt/dbo/Views/RiskInsightCriticalApplicationView.sql new file mode 100644 index 0000000000..0b1122c829 --- /dev/null +++ b/src/Sql/Dirt/dbo/Views/RiskInsightCriticalApplicationView.sql @@ -0,0 +1,5 @@ +CREATE VIEW [dbo].[RiskInsightCriticalApplicationView] +AS +SELECT + * +FROM [dbo].[RiskInsightCriticalApplication]; diff --git a/src/Sql/Dirt/dbo/Views/RiskInsightReportView.sql b/src/Sql/Dirt/dbo/Views/RiskInsightReportView.sql new file mode 100644 index 0000000000..568248decd --- /dev/null +++ b/src/Sql/Dirt/dbo/Views/RiskInsightReportView.sql @@ -0,0 +1,2 @@ +CREATE VIEW [dbo].[RiskInsightReportView] AS +SELECT * FROM [dbo].[RiskInsightReport]; diff --git a/util/Migrator/DbScripts/2025-05-16-00_RiskInsightReport.sql b/util/Migrator/DbScripts/2025-05-16-00_RiskInsightReport.sql new file mode 100644 index 0000000000..1572e9df20 --- /dev/null +++ b/util/Migrator/DbScripts/2025-05-16-00_RiskInsightReport.sql @@ -0,0 +1,111 @@ +IF OBJECT_ID('dbo.RiskInsightReport') IS NULL +BEGIN + CREATE TABLE [dbo].[RiskInsightReport] + ( + [Id] UNIQUEIDENTIFIER NOT NULL, + [OrganizationId] UNIQUEIDENTIFIER NOT NULL, + [Date] DATETIME2 (7) NOT NULL, + [ReportData] NVARCHAR(MAX) NOT NULL, + [CreationDate] DATETIME2 (7) NOT NULL, + [RevisionDate] DATETIME2 (7) NOT NULL, + CONSTRAINT [PK_RiskInsightReport] PRIMARY KEY CLUSTERED ([Id] ASC), + CONSTRAINT [FK_RiskInsightReport_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) + ); + + CREATE NONCLUSTERED INDEX [IX_RiskInsightReport_OrganizationId] + ON [dbo].[RiskInsightReport]([OrganizationId] ASC); +END +GO + +IF OBJECT_ID('dbo.RiskInsightReportView') IS NOT NULL +BEGIN + DROP VIEW [dbo].[RiskInsightReportView] +END +GO + +CREATE VIEW [dbo].[RiskInsightReportView] AS + SELECT * FROM [dbo].[RiskInsightReport]; +GO + +CREATE OR ALTER PROCEDURE [dbo].[RiskInsightReport_Create] + @Id UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER, + @Date DATETIME2(7), + @ReportData NVARCHAR(MAX), + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7) +AS + SET NOCOUNT ON; + INSERT INTO [dbo].[RiskInsightReport]( [Id],[OrganizationId],[Date],[ReportData],[CreationDate],[RevisionDate] ) + VALUES ( @Id,@OrganizationId,@Date,@ReportData,@CreationDate,@RevisionDate); +GO + +CREATE OR ALTER PROCEDURE [dbo].[RiskInsightReport_ReadByOrganizationId] + @OrganizationId UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @OrganizationId IS NULL + THROW 50000, 'OrganizationId cannot be null', 1; + + SELECT + [Id], + [OrganizationId], + [Date], + [ReportData], + [CreationDate], + [RevisionDate] + FROM [dbo].[RiskInsightReport] + WHERE [OrganizationId] = @OrganizationId; +GO + +CREATE OR ALTER PROCEDURE [dbo].[RiskInsightReport_ReadById] + @Id UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @Id IS NULL + THROW 50000, 'Id cannot be null', 1; + + SELECT + [Id], + [OrganizationId], + [Date], + [ReportData], + [CreationDate], + [RevisionDate] + FROM [dbo].[RiskInsightReport] + WHERE [Id] = @Id; +GO + +CREATE OR ALTER PROCEDURE [dbo].[RiskInsightReport_Update] + @Id UNIQUEIDENTIFIER OUTPUT, + @OrganizationId UNIQUEIDENTIFIER, + @Date DATETIME2(7), + @ReportData NVARCHAR(MAX), + @RevisionDate DATETIME2(7) +AS + SET NOCOUNT ON; + UPDATE [dbo].[RiskInsightReport] + SET [OrganizationId] = @OrganizationId, + [Date] = @Date, + [ReportData] = @ReportData, + [RevisionDate] = @RevisionDate + WHERE [Id] = @Id; +GO + +CREATE OR ALTER PROCEDURE [dbo].[RiskInsightReport_DeleteById] + @Id UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @Id IS NULL + THROW 50000, 'Id cannot be null', 1; + + DELETE FROM [dbo].[RiskInsightReport] + WHERE [Id] = @Id; +GO + + + + diff --git a/util/Migrator/DbScripts/2025-05-16-01_RiskInsightCriticalApplication.sql b/util/Migrator/DbScripts/2025-05-16-01_RiskInsightCriticalApplication.sql new file mode 100644 index 0000000000..94730f1eef --- /dev/null +++ b/util/Migrator/DbScripts/2025-05-16-01_RiskInsightCriticalApplication.sql @@ -0,0 +1,126 @@ +IF OBJECT_ID('dbo.RiskInsightCriticalApplication') IS NULL +BEGIN + CREATE TABLE [dbo].[RiskInsightCriticalApplication] ( + [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_RiskInsightCriticalApplication] PRIMARY KEY CLUSTERED ([Id] ASC), + CONSTRAINT [FK_RiskInsightCriticalApplication_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) + ); + + CREATE NONCLUSTERED INDEX [IX_RiskInsightCriticalApplication_OrganizationId] + ON [dbo].[RiskInsightCriticalApplication]([OrganizationId] ASC); +END +GO + +IF OBJECT_ID('dbo.RiskInsightCriticalApplicationView') IS NOT NULL +BEGIN + DROP VIEW [dbo].[RiskInsightCriticalApplicationView]; +END +GO + +CREATE VIEW [dbo].[RiskInsightCriticalApplicationView] AS + SELECT * FROM [dbo].[RiskInsightCriticalApplication]; +GO + +CREATE OR ALTER PROCEDURE [dbo].[RiskInsightCriticalApplication_Create] + @Id UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER, + @Applications NVARCHAR(MAX), + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7) +AS + SET NOCOUNT ON; + + INSERT INTO [dbo].[RiskInsightCriticalApplication] + ( + [Id], + [OrganizationId], + [Applications], + [CreationDate], + [RevisionDate] + ) + VALUES + ( + @Id, + @OrganizationId, + @Applications, + @CreationDate, + @RevisionDate + ); +GO + +CREATE OR ALTER PROCEDURE [dbo].[RiskInsightCriticalApplication_ReadByOrganizationId] + @OrganizationId UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @OrganizationId IS NULL + THROW 50000, 'OrganizationId cannot be null', 1; + + SELECT + [Id], + [OrganizationId], + [Applications], + [CreationDate], + [RevisionDate] + FROM [dbo].[RiskInsightCriticalApplication] + WHERE [OrganizationId] = @OrganizationId; +GO + +CREATE OR ALTER PROCEDURE [dbo].[RiskInsightCriticalApplication_ReadById] + @Id UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @Id IS NULL + THROW 50000, 'Id cannot be null', 1; + + SELECT + [Id], + [OrganizationId], + [Applications], + [CreationDate], + [RevisionDate] + FROM [dbo].[RiskInsightCriticalApplication] + WHERE [Id] = @Id; +GO + +CREATE OR ALTER PROCEDURE [dbo].[RiskInsightCriticalApplication_Update] + @Id UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER, + @Applications NVARCHAR(MAX), + @RevisionDate DATETIME2(7) +AS + SET NOCOUNT ON; + UPDATE [dbo].[RiskInsightCriticalApplication] + SET + [OrganizationId] = @OrganizationId, + [Applications] = @Applications, + [RevisionDate] = @RevisionDate + WHERE [Id] = @Id; +GO + +CREATE OR ALTER PROCEDURE [dbo].[RiskInsightCriticalApplication_DeleteById] + @Id UNIQUEIDENTIFIER +AS + SET NOCOUNT ON; + + IF @Id IS NULL + THROW 50000, 'Id cannot be null', 1; + + DELETE FROM [dbo].[RiskInsightCriticalApplication] + WHERE [Id] = @Id; +GO + + + + + + + + + +