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

PM-20574 fixing directory for entities and removing scripts from other databases

This commit is contained in:
Graham Walker 2025-06-13 16:37:02 -05:00
parent 85c4837714
commit d4e284f50a
No known key found for this signature in database
47 changed files with 56 additions and 4455 deletions

View File

@ -1,8 +1,8 @@
using Bit.Api.Dirt.Models;
using Bit.Api.Dirt.Models.Response;
using Bit.Core.Context;
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Models.Data;
using Bit.Core.Dirt.Reports.ReportFeatures.Interfaces;
using Bit.Core.Dirt.Reports.ReportFeatures.OrganizationReportMembers.Interfaces;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;

View File

@ -1,4 +1,4 @@
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Models.Data;
namespace Bit.Api.Dirt.Models.Response;

View File

@ -1,4 +1,4 @@
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Models.Data;
namespace Bit.Api.Dirt.Models.Response;

View File

@ -3,7 +3,7 @@
using Bit.Core.Entities;
using Bit.Core.Utilities;
namespace Bit.Core.Dirt.Reports.Entities;
namespace Bit.Core.Dirt.Entities;
public class OrganizationApplication : ITableObject<Guid>, IRevisable
{

View File

@ -3,7 +3,7 @@
using Bit.Core.Entities;
using Bit.Core.Utilities;
namespace Bit.Core.Dirt.Reports.Entities;
namespace Bit.Core.Dirt.Entities;
public class OrganizationReport : ITableObject<Guid>, IRevisable
{

View File

@ -3,7 +3,7 @@
using Bit.Core.Entities;
using Bit.Core.Utilities;
namespace Bit.Core.Dirt.Reports.Entities;
namespace Bit.Core.Dirt.Entities;
public class PasswordHealthReportApplication : ITableObject<Guid>, IRevisable
{

View File

@ -1,4 +1,4 @@
namespace Bit.Core.Dirt.Reports.Models.Data;
namespace Bit.Core.Dirt.Models.Data;
public class MemberAccessDetails
{

View File

@ -1,7 +1,7 @@
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Reports.ReportFeatures.Interfaces;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;

View File

@ -1,6 +1,6 @@
using Bit.Core.Dirt.Reports.ReportFeatures.Interfaces;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Exceptions;
namespace Bit.Core.Dirt.Reports.ReportFeatures;

View File

@ -1,6 +1,6 @@
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Reports.ReportFeatures.Interfaces;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Exceptions;
namespace Bit.Core.Dirt.Reports.ReportFeatures;

View File

@ -1,4 +1,4 @@
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;
namespace Bit.Core.Dirt.Reports.ReportFeatures.Interfaces;

View File

@ -1,4 +1,4 @@
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
namespace Bit.Core.Dirt.Reports.ReportFeatures.Interfaces;

View File

@ -2,7 +2,7 @@
using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.Repositories;
using Bit.Core.Auth.UserFeatures.TwoFactorAuth.Interfaces;
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Models.Data;
using Bit.Core.Dirt.Reports.ReportFeatures.OrganizationReportMembers.Interfaces;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;
using Bit.Core.Entities;

View File

@ -1,4 +1,4 @@
using Bit.Core.Dirt.Reports.Models.Data;
using Bit.Core.Dirt.Models.Data;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;
namespace Bit.Core.Dirt.Reports.ReportFeatures.OrganizationReportMembers.Interfaces;

View File

@ -1,7 +1,7 @@
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
using Bit.Core.Repositories;
namespace Bit.Core.Dirt.Reports.Repositories;
namespace Bit.Core.Dirt.Repositories;
public interface IOrganizationApplicationRepository : IRepository<OrganizationApplication, Guid>
{

View File

@ -1,7 +1,7 @@
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
using Bit.Core.Repositories;
namespace Bit.Core.Dirt.Reports.Repositories;
namespace Bit.Core.Dirt.Repositories;
public interface IOrganizationReportRepository : IRepository<OrganizationReport, Guid>
{

View File

@ -1,7 +1,7 @@
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
using Bit.Core.Repositories;
namespace Bit.Core.Dirt.Reports.Repositories;
namespace Bit.Core.Dirt.Repositories;
public interface IPasswordHealthReportApplicationRepository : IRepository<PasswordHealthReportApplication, Guid>
{

View File

@ -2,7 +2,7 @@
using Bit.Core.Auth.Repositories;
using Bit.Core.Billing.Providers.Repositories;
using Bit.Core.Billing.Repositories;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.KeyManagement.Repositories;
using Bit.Core.NotificationCenter.Repositories;
using Bit.Core.Platform.Installations;

View File

@ -1,6 +1,6 @@
using System.Data;
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Settings;
using Bit.Infrastructure.Dapper.Repositories;
using Dapper;

View File

@ -1,6 +1,6 @@
using System.Data;
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Settings;
using Bit.Infrastructure.Dapper.Repositories;
using Dapper;

View File

@ -1,6 +1,6 @@
using System.Data;
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Settings;
using Bit.Infrastructure.Dapper.Repositories;
using Dapper;

View File

@ -2,7 +2,7 @@
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
namespace Bit.Infrastructure.EntityFramework.Dirt.Models;
public class OrganizationApplication : Core.Dirt.Reports.Entities.OrganizationApplication
public class OrganizationApplication : Core.Dirt.Entities.OrganizationApplication
{
public virtual Organization Organization { get; set; }
}
@ -11,7 +11,7 @@ public class OrganizationApplicationProfile : Profile
{
public OrganizationApplicationProfile()
{
CreateMap<Core.Dirt.Reports.Entities.OrganizationApplication, OrganizationApplication>()
CreateMap<Core.Dirt.Entities.OrganizationApplication, OrganizationApplication>()
.ReverseMap();
}
}

View File

@ -2,7 +2,7 @@
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
namespace Bit.Infrastructure.EntityFramework.Dirt.Models;
public class OrganizationReport : Core.Dirt.Reports.Entities.OrganizationReport
public class OrganizationReport : Core.Dirt.Entities.OrganizationReport
{
public virtual Organization Organization { get; set; }
}
@ -11,7 +11,7 @@ public class OrganizationReportProfile : Profile
{
public OrganizationReportProfile()
{
CreateMap<Core.Dirt.Reports.Entities.OrganizationReport, OrganizationReport>()
CreateMap<Core.Dirt.Entities.OrganizationReport, OrganizationReport>()
.ReverseMap();
}
}

View File

@ -3,7 +3,7 @@ using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
namespace Bit.Infrastructure.EntityFramework.Dirt.Models;
public class PasswordHealthReportApplication : Core.Dirt.Reports.Entities.PasswordHealthReportApplication
public class PasswordHealthReportApplication : Core.Dirt.Entities.PasswordHealthReportApplication
{
public virtual Organization Organization { get; set; }
}
@ -12,7 +12,7 @@ public class PasswordHealthReportApplicationProfile : Profile
{
public PasswordHealthReportApplicationProfile()
{
CreateMap<Core.Dirt.Reports.Entities.PasswordHealthReportApplication, PasswordHealthReportApplication>()
CreateMap<Core.Dirt.Entities.PasswordHealthReportApplication, PasswordHealthReportApplication>()
.ReverseMap();
}
}

View File

@ -1,5 +1,5 @@
using AutoMapper;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Infrastructure.EntityFramework.Dirt.Models;
using Bit.Infrastructure.EntityFramework.Repositories;
using LinqToDB;
@ -8,14 +8,14 @@ using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories;
public class OrganizationApplicationRepository :
Repository<Core.Dirt.Reports.Entities.OrganizationApplication, OrganizationApplication, Guid>,
Repository<Core.Dirt.Entities.OrganizationApplication, OrganizationApplication, Guid>,
IOrganizationApplicationRepository
{
public OrganizationApplicationRepository(IServiceScopeFactory serviceScopeFactory,
IMapper mapper) : base(serviceScopeFactory, mapper, (DatabaseContext context) => context.OrganizationApplications)
{ }
public async Task<ICollection<Core.Dirt.Reports.Entities.OrganizationApplication>> GetByOrganizationIdAsync(Guid organizationId)
public async Task<ICollection<Core.Dirt.Entities.OrganizationApplication>> GetByOrganizationIdAsync(Guid organizationId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
@ -23,7 +23,7 @@ public class OrganizationApplicationRepository :
var results = await dbContext.OrganizationApplications
.Where(p => p.OrganizationId == organizationId)
.ToListAsync();
return Mapper.Map<ICollection<Core.Dirt.Reports.Entities.OrganizationApplication>>(results);
return Mapper.Map<ICollection<Core.Dirt.Entities.OrganizationApplication>>(results);
}
}
}

View File

@ -1,6 +1,6 @@
using AutoMapper;
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories;
using LinqToDB;
using Microsoft.Extensions.DependencyInjection;

View File

@ -1,5 +1,5 @@
using AutoMapper;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Infrastructure.EntityFramework.Dirt.Models;
using Bit.Infrastructure.EntityFramework.Repositories;
using LinqToDB;
@ -8,14 +8,14 @@ using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories;
public class PasswordHealthReportApplicationRepository :
Repository<Core.Dirt.Reports.Entities.PasswordHealthReportApplication, PasswordHealthReportApplication, Guid>,
Repository<Core.Dirt.Entities.PasswordHealthReportApplication, PasswordHealthReportApplication, Guid>,
IPasswordHealthReportApplicationRepository
{
public PasswordHealthReportApplicationRepository(IServiceScopeFactory serviceScopeFactory,
IMapper mapper) : base(serviceScopeFactory, mapper, (DatabaseContext context) => context.PasswordHealthReportApplications)
{ }
public async Task<ICollection<Core.Dirt.Reports.Entities.PasswordHealthReportApplication>> GetByOrganizationIdAsync(Guid organizationId)
public async Task<ICollection<Core.Dirt.Entities.PasswordHealthReportApplication>> GetByOrganizationIdAsync(Guid organizationId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
@ -23,7 +23,7 @@ public class PasswordHealthReportApplicationRepository :
var results = await dbContext.PasswordHealthReportApplications
.Where(p => p.OrganizationId == organizationId)
.ToListAsync();
return Mapper.Map<ICollection<Core.Dirt.Reports.Entities.PasswordHealthReportApplication>>(results);
return Mapper.Map<ICollection<Core.Dirt.Entities.PasswordHealthReportApplication>>(results);
}
}
}

View File

@ -2,7 +2,7 @@
using Bit.Core.Auth.Repositories;
using Bit.Core.Billing.Providers.Repositories;
using Bit.Core.Billing.Repositories;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Enums;
using Bit.Core.KeyManagement.Repositories;
using Bit.Core.NotificationCenter.Repositories;

View File

@ -1,9 +1,9 @@
using AutoFixture;
using Bit.Core.AdminConsole.Entities;
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Reports.ReportFeatures;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Test.Common.AutoFixture;

View File

@ -1,8 +1,8 @@
using AutoFixture;
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Reports.ReportFeatures;
using Bit.Core.Dirt.Reports.ReportFeatures.Requests;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Exceptions;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;

View File

@ -1,7 +1,7 @@
using AutoFixture;
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Reports.ReportFeatures;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Exceptions;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;

View File

@ -1,6 +1,6 @@
using AutoFixture;
using AutoFixture.Kernel;
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Entities;
using Bit.Infrastructure.EntityFramework.AdminConsole.Repositories;
using Bit.Infrastructure.EntityFramework.Dirt.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories;

View File

@ -1,7 +1,7 @@
using AutoFixture;
using Bit.Core.AdminConsole.Entities;
using Bit.Core.Dirt.Reports.Entities;
using Bit.Core.Dirt.Reports.Repositories;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Repositories;
using Bit.Core.Test.AutoFixture.Attributes;
using Bit.Infrastructure.Dapper.Dirt;

View File

@ -1,111 +0,0 @@
IF OBJECT_ID('dbo.OrganizationReport') IS NULL
BEGIN
CREATE TABLE [dbo].[OrganizationReport]
(
[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_OrganizationReport] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_OrganizationReport_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
);
CREATE NONCLUSTERED INDEX [IX_OrganizationReport_OrganizationId]
ON [dbo].[OrganizationReport]([OrganizationId] ASC);
END
GO
IF OBJECT_ID('dbo.OrganizationReportView') IS NOT NULL
BEGIN
DROP VIEW [dbo].[OrganizationReportView]
END
GO
CREATE VIEW [dbo].[OrganizationReportView] AS
SELECT * FROM [dbo].[OrganizationReport];
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_Create]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7),
@ReportData NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
INSERT INTO [dbo].[OrganizationReport]( [Id],[OrganizationId],[Date],[ReportData],[CreationDate],[RevisionDate] )
VALUES ( @Id,@OrganizationId,@Date,@ReportData,@CreationDate,@RevisionDate);
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_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].[OrganizationReport]
WHERE [OrganizationId] = @OrganizationId;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_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].[OrganizationReport]
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_Update]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7),
@ReportData NVARCHAR(MAX),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
UPDATE [dbo].[OrganizationReport]
SET [OrganizationId] = @OrganizationId,
[Date] = @Date,
[ReportData] = @ReportData,
[RevisionDate] = @RevisionDate
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_DeleteById]
@Id UNIQUEIDENTIFIER
AS
SET NOCOUNT ON;
IF @Id IS NULL
THROW 50000, 'Id cannot be null', 1;
DELETE FROM [dbo].[OrganizationReport]
WHERE [Id] = @Id;
GO

View File

@ -1,126 +0,0 @@
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,
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
IF OBJECT_ID('dbo.OrganizationApplicationView') IS NOT NULL
BEGIN
DROP VIEW [dbo].[OrganizationApplicationView];
END
GO
CREATE VIEW [dbo].[OrganizationApplicationView] AS
SELECT * FROM [dbo].[OrganizationApplication];
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_Create]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Applications NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
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_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].[OrganizationApplication]
WHERE [OrganizationId] = @OrganizationId;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_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].[OrganizationApplication]
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_Update]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Applications NVARCHAR(MAX),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
UPDATE [dbo].[OrganizationApplication]
SET
[OrganizationId] = @OrganizationId,
[Applications] = @Applications,
[RevisionDate] = @RevisionDate
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_DeleteById]
@Id UNIQUEIDENTIFIER
AS
SET NOCOUNT ON;
IF @Id IS NULL
THROW 50000, 'Id cannot be null', 1;
DELETE FROM [dbo].[OrganizationApplication]
WHERE [Id] = @Id;
GO

View File

@ -1,161 +0,0 @@
CREATE OR ALTER PROCEDURE [dbo].[Organization_DeleteById]
@Id UNIQUEIDENTIFIER
WITH RECOMPILE
AS
BEGIN
SET NOCOUNT ON
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @Id
DECLARE @BatchSize INT = 100
WHILE @BatchSize > 0
BEGIN
BEGIN TRANSACTION Organization_DeleteById_Ciphers
DELETE TOP(@BatchSize)
FROM
[dbo].[Cipher]
WHERE
[UserId] IS NULL
AND [OrganizationId] = @Id
SET @BatchSize = @@ROWCOUNT
COMMIT TRANSACTION Organization_DeleteById_Ciphers
END
BEGIN TRANSACTION Organization_DeleteById
DELETE
FROM
[dbo].[AuthRequest]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[SsoUser]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[SsoConfig]
WHERE
[OrganizationId] = @Id
DELETE CU
FROM
[dbo].[CollectionUser] CU
INNER JOIN
[dbo].[OrganizationUser] OU ON [CU].[OrganizationUserId] = [OU].[Id]
WHERE
[OU].[OrganizationId] = @Id
DELETE AP
FROM
[dbo].[AccessPolicy] AP
INNER JOIN
[dbo].[OrganizationUser] OU ON [AP].[OrganizationUserId] = [OU].[Id]
WHERE
[OU].[OrganizationId] = @Id
DELETE GU
FROM
[dbo].[GroupUser] GU
INNER JOIN
[dbo].[OrganizationUser] OU ON [GU].[OrganizationUserId] = [OU].[Id]
WHERE
[OU].[OrganizationId] = @Id
DELETE
FROM
[dbo].[OrganizationUser]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[ProviderOrganization]
WHERE
[OrganizationId] = @Id
EXEC [dbo].[OrganizationApiKey_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationConnection_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationSponsorship_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationDomain_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationIntegration_OrganizationDeleted] @Id
DELETE
FROM
[dbo].[Project]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[Secret]
WHERE
[OrganizationId] = @Id
DELETE AK
FROM
[dbo].[ApiKey] AK
INNER JOIN
[dbo].[ServiceAccount] SA ON [AK].[ServiceAccountId] = [SA].[Id]
WHERE
[SA].[OrganizationId] = @Id
DELETE AP
FROM
[dbo].[AccessPolicy] AP
INNER JOIN
[dbo].[ServiceAccount] SA ON [AP].[GrantedServiceAccountId] = [SA].[Id]
WHERE
[SA].[OrganizationId] = @Id
DELETE
FROM
[dbo].[ServiceAccount]
WHERE
[OrganizationId] = @Id
-- Delete Notification Status
DELETE
NS
FROM
[dbo].[NotificationStatus] NS
INNER JOIN
[dbo].[Notification] N ON N.[Id] = NS.[NotificationId]
WHERE
N.[OrganizationId] = @Id
-- Delete Notification
DELETE
FROM
[dbo].[Notification]
WHERE
[OrganizationId] = @Id
-- Delete Organization Application
DELETE
FROM
[dbo].[OrganizationApplication]
WHERE
[Id] = @Id
-- Delete Organization Report
DELETE
FROM
[dbo].[OrganizationReport]
WHERE
[Id] = @Id
DELETE
FROM
[dbo].[Organization]
WHERE
[Id] = @Id
COMMIT TRANSACTION Organization_DeleteById
END
GO

View File

@ -1,21 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.MySqlMigrations.Migrations;
/// <inheritdoc />
public partial class _20250602_00_AddOrgUserDefaultCollectionsql : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}

View File

@ -1,105 +0,0 @@
IF OBJECT_ID('dbo.OrganizationReport') IS NULL
BEGIN
CREATE TABLE [dbo].[OrganizationReport]
(
[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_OrganizationReport] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_OrganizationReport_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
);
CREATE NONCLUSTERED INDEX [IX_OrganizationReport_OrganizationId]
ON [dbo].[OrganizationReport]([OrganizationId] ASC);
END
GO
CREATE OR ALTER VIEW[dbo].[OrganizationReportView] AS
SELECT * FROM [dbo].[OrganizationReport];
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_Create]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7),
@ReportData NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
INSERT INTO [dbo].[OrganizationReport]( [Id],[OrganizationId],[Date],[ReportData],[CreationDate],[RevisionDate] )
VALUES ( @Id,@OrganizationId,@Date,@ReportData,@CreationDate,@RevisionDate);
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_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].[OrganizationReport]
WHERE [OrganizationId] = @OrganizationId;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_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].[OrganizationReport]
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_Update]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7),
@ReportData NVARCHAR(MAX),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
UPDATE [dbo].[OrganizationReport]
SET [OrganizationId] = @OrganizationId,
[Date] = @Date,
[ReportData] = @ReportData,
[RevisionDate] = @RevisionDate
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_DeleteById]
@Id UNIQUEIDENTIFIER
AS
SET NOCOUNT ON;
IF @Id IS NULL
THROW 50000, 'Id cannot be null', 1;
DELETE FROM [dbo].[OrganizationReport]
WHERE [Id] = @Id;
GO

View File

@ -1,120 +0,0 @@
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,
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];
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_Create]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Applications NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
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_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].[OrganizationApplication]
WHERE [OrganizationId] = @OrganizationId;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_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].[OrganizationApplication]
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_Update]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Applications NVARCHAR(MAX),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
UPDATE [dbo].[OrganizationApplication]
SET
[OrganizationId] = @OrganizationId,
[Applications] = @Applications,
[RevisionDate] = @RevisionDate
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_DeleteById]
@Id UNIQUEIDENTIFIER
AS
SET NOCOUNT ON;
IF @Id IS NULL
THROW 50000, 'Id cannot be null', 1;
DELETE FROM [dbo].[OrganizationApplication]
WHERE [Id] = @Id;
GO

View File

@ -1,161 +0,0 @@
CREATE OR ALTER PROCEDURE [dbo].[Organization_DeleteById]
@Id UNIQUEIDENTIFIER
WITH RECOMPILE
AS
BEGIN
SET NOCOUNT ON
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @Id
DECLARE @BatchSize INT = 100
WHILE @BatchSize > 0
BEGIN
BEGIN TRANSACTION Organization_DeleteById_Ciphers
DELETE TOP(@BatchSize)
FROM
[dbo].[Cipher]
WHERE
[UserId] IS NULL
AND [OrganizationId] = @Id
SET @BatchSize = @@ROWCOUNT
COMMIT TRANSACTION Organization_DeleteById_Ciphers
END
BEGIN TRANSACTION Organization_DeleteById
DELETE
FROM
[dbo].[AuthRequest]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[SsoUser]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[SsoConfig]
WHERE
[OrganizationId] = @Id
DELETE CU
FROM
[dbo].[CollectionUser] CU
INNER JOIN
[dbo].[OrganizationUser] OU ON [CU].[OrganizationUserId] = [OU].[Id]
WHERE
[OU].[OrganizationId] = @Id
DELETE AP
FROM
[dbo].[AccessPolicy] AP
INNER JOIN
[dbo].[OrganizationUser] OU ON [AP].[OrganizationUserId] = [OU].[Id]
WHERE
[OU].[OrganizationId] = @Id
DELETE GU
FROM
[dbo].[GroupUser] GU
INNER JOIN
[dbo].[OrganizationUser] OU ON [GU].[OrganizationUserId] = [OU].[Id]
WHERE
[OU].[OrganizationId] = @Id
DELETE
FROM
[dbo].[OrganizationUser]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[ProviderOrganization]
WHERE
[OrganizationId] = @Id
EXEC [dbo].[OrganizationApiKey_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationConnection_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationSponsorship_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationDomain_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationIntegration_OrganizationDeleted] @Id
DELETE
FROM
[dbo].[Project]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[Secret]
WHERE
[OrganizationId] = @Id
DELETE AK
FROM
[dbo].[ApiKey] AK
INNER JOIN
[dbo].[ServiceAccount] SA ON [AK].[ServiceAccountId] = [SA].[Id]
WHERE
[SA].[OrganizationId] = @Id
DELETE AP
FROM
[dbo].[AccessPolicy] AP
INNER JOIN
[dbo].[ServiceAccount] SA ON [AP].[GrantedServiceAccountId] = [SA].[Id]
WHERE
[SA].[OrganizationId] = @Id
DELETE
FROM
[dbo].[ServiceAccount]
WHERE
[OrganizationId] = @Id
-- Delete Notification Status
DELETE
NS
FROM
[dbo].[NotificationStatus] NS
INNER JOIN
[dbo].[Notification] N ON N.[Id] = NS.[NotificationId]
WHERE
N.[OrganizationId] = @Id
-- Delete Notification
DELETE
FROM
[dbo].[Notification]
WHERE
[OrganizationId] = @Id
-- Delete Organization Application
DELETE
FROM
[dbo].[OrganizationApplication]
WHERE
[Id] = @Id
-- Delete Organization Report
DELETE
FROM
[dbo].[OrganizationReport]
WHERE
[Id] = @Id
DELETE
FROM
[dbo].[Organization]
WHERE
[Id] = @Id
COMMIT TRANSACTION Organization_DeleteById
END
GO

View File

@ -1,105 +0,0 @@
IF OBJECT_ID('dbo.OrganizationReport') IS NULL
BEGIN
CREATE TABLE [dbo].[OrganizationReport]
(
[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_OrganizationReport] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_OrganizationReport_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
);
CREATE NONCLUSTERED INDEX [IX_OrganizationReport_OrganizationId]
ON [dbo].[OrganizationReport]([OrganizationId] ASC);
END
GO
CREATE OR ALTER VIEW[dbo].[OrganizationReportView] AS
SELECT * FROM [dbo].[OrganizationReport];
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_Create]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7),
@ReportData NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
INSERT INTO [dbo].[OrganizationReport]( [Id],[OrganizationId],[Date],[ReportData],[CreationDate],[RevisionDate] )
VALUES ( @Id,@OrganizationId,@Date,@ReportData,@CreationDate,@RevisionDate);
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_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].[OrganizationReport]
WHERE [OrganizationId] = @OrganizationId;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_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].[OrganizationReport]
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_Update]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Date DATETIME2(7),
@ReportData NVARCHAR(MAX),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
UPDATE [dbo].[OrganizationReport]
SET [OrganizationId] = @OrganizationId,
[Date] = @Date,
[ReportData] = @ReportData,
[RevisionDate] = @RevisionDate
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationReport_DeleteById]
@Id UNIQUEIDENTIFIER
AS
SET NOCOUNT ON;
IF @Id IS NULL
THROW 50000, 'Id cannot be null', 1;
DELETE FROM [dbo].[OrganizationReport]
WHERE [Id] = @Id;
GO

View File

@ -1,120 +0,0 @@
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,
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];
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_Create]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Applications NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
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_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].[OrganizationApplication]
WHERE [OrganizationId] = @OrganizationId;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_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].[OrganizationApplication]
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_Update]
@Id UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Applications NVARCHAR(MAX),
@RevisionDate DATETIME2(7)
AS
SET NOCOUNT ON;
UPDATE [dbo].[OrganizationApplication]
SET
[OrganizationId] = @OrganizationId,
[Applications] = @Applications,
[RevisionDate] = @RevisionDate
WHERE [Id] = @Id;
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationApplication_DeleteById]
@Id UNIQUEIDENTIFIER
AS
SET NOCOUNT ON;
IF @Id IS NULL
THROW 50000, 'Id cannot be null', 1;
DELETE FROM [dbo].[OrganizationApplication]
WHERE [Id] = @Id;
GO

View File

@ -1,161 +0,0 @@
CREATE OR ALTER PROCEDURE [dbo].[Organization_DeleteById]
@Id UNIQUEIDENTIFIER
WITH RECOMPILE
AS
BEGIN
SET NOCOUNT ON
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @Id
DECLARE @BatchSize INT = 100
WHILE @BatchSize > 0
BEGIN
BEGIN TRANSACTION Organization_DeleteById_Ciphers
DELETE TOP(@BatchSize)
FROM
[dbo].[Cipher]
WHERE
[UserId] IS NULL
AND [OrganizationId] = @Id
SET @BatchSize = @@ROWCOUNT
COMMIT TRANSACTION Organization_DeleteById_Ciphers
END
BEGIN TRANSACTION Organization_DeleteById
DELETE
FROM
[dbo].[AuthRequest]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[SsoUser]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[SsoConfig]
WHERE
[OrganizationId] = @Id
DELETE CU
FROM
[dbo].[CollectionUser] CU
INNER JOIN
[dbo].[OrganizationUser] OU ON [CU].[OrganizationUserId] = [OU].[Id]
WHERE
[OU].[OrganizationId] = @Id
DELETE AP
FROM
[dbo].[AccessPolicy] AP
INNER JOIN
[dbo].[OrganizationUser] OU ON [AP].[OrganizationUserId] = [OU].[Id]
WHERE
[OU].[OrganizationId] = @Id
DELETE GU
FROM
[dbo].[GroupUser] GU
INNER JOIN
[dbo].[OrganizationUser] OU ON [GU].[OrganizationUserId] = [OU].[Id]
WHERE
[OU].[OrganizationId] = @Id
DELETE
FROM
[dbo].[OrganizationUser]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[ProviderOrganization]
WHERE
[OrganizationId] = @Id
EXEC [dbo].[OrganizationApiKey_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationConnection_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationSponsorship_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationDomain_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationIntegration_OrganizationDeleted] @Id
DELETE
FROM
[dbo].[Project]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[Secret]
WHERE
[OrganizationId] = @Id
DELETE AK
FROM
[dbo].[ApiKey] AK
INNER JOIN
[dbo].[ServiceAccount] SA ON [AK].[ServiceAccountId] = [SA].[Id]
WHERE
[SA].[OrganizationId] = @Id
DELETE AP
FROM
[dbo].[AccessPolicy] AP
INNER JOIN
[dbo].[ServiceAccount] SA ON [AP].[GrantedServiceAccountId] = [SA].[Id]
WHERE
[SA].[OrganizationId] = @Id
DELETE
FROM
[dbo].[ServiceAccount]
WHERE
[OrganizationId] = @Id
-- Delete Notification Status
DELETE
NS
FROM
[dbo].[NotificationStatus] NS
INNER JOIN
[dbo].[Notification] N ON N.[Id] = NS.[NotificationId]
WHERE
N.[OrganizationId] = @Id
-- Delete Notification
DELETE
FROM
[dbo].[Notification]
WHERE
[OrganizationId] = @Id
-- Delete Organization Application
DELETE
FROM
[dbo].[OrganizationApplication]
WHERE
[Id] = @Id
-- Delete Organization Report
DELETE
FROM
[dbo].[OrganizationReport]
WHERE
[Id] = @Id
DELETE
FROM
[dbo].[Organization]
WHERE
[Id] = @Id
COMMIT TRANSACTION Organization_DeleteById
END
GO