diff --git a/docker-unified/Dockerfile b/docker-unified/Dockerfile
index 9d15f7eea03c..ce9bd5aa874f 100644
--- a/docker-unified/Dockerfile
+++ b/docker-unified/Dockerfile
@@ -75,6 +75,7 @@ COPY util/MySqlMigrations/*.csproj ./util/MySqlMigrations/
COPY util/PostgresMigrations/*.csproj ./util/PostgresMigrations/
COPY util/SqliteMigrations/*.csproj ./util/SqliteMigrations/
COPY bitwarden_license/src/Commercial.Core/*.csproj ./bitwarden_license/src/Commercial.Core/
+COPY bitwarden_license/src/Commercial.Infrastructure.EntityFramework/*.csproj ./bitwarden_license/src/Commercial.Infrastructure.EntityFramework/
COPY Directory.Build.props .
# Restore Admin project dependencies and tools
@@ -129,6 +130,7 @@ COPY util/PostgresMigrations/. ./util/PostgresMigrations/
COPY util/SqliteMigrations/. ./util/SqliteMigrations/
COPY util/EfShared/. ./util/EfShared/
COPY bitwarden_license/src/Commercial.Core/. ./bitwarden_license/src/Commercial.Core/
+COPY bitwarden_license/src/Commercial.Infrastructure.EntityFramework/. ./bitwarden_license/src/Commercial.Infrastructure.EntityFramework/
COPY .git/. ./.git/
# Build Admin app
diff --git a/src/Api/Api.csproj b/src/Api/Api.csproj
index f574247511e6..613dba05af30 100644
--- a/src/Api/Api.csproj
+++ b/src/Api/Api.csproj
@@ -18,13 +18,13 @@
-
+
diff --git a/src/Sql/Sql.sqlproj b/src/Sql/Sql.sqlproj
index 70c5d7718817..3e26fd58a245 100644
--- a/src/Sql/Sql.sqlproj
+++ b/src/Sql/Sql.sqlproj
@@ -74,7 +74,6 @@
-
diff --git a/src/Sql/dbo/Stored Procedures/ApiKey/ApiKey_ReadById.sql b/src/Sql/dbo/Stored Procedures/ApiKey/ApiKey_ReadById.sql
deleted file mode 100644
index fafa45d0abac..000000000000
--- a/src/Sql/dbo/Stored Procedures/ApiKey/ApiKey_ReadById.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-CREATE PROCEDURE [dbo].[ApiKey_ReadById]
- @Id UNIQUEIDENTIFIER
-AS
-BEGIN
- SET NOCOUNT ON
-
- SELECT
- *
- FROM
- [dbo].[ApiKeyView]
- WHERE
- [Id] = @Id
-END
diff --git a/src/Sql/dbo/Stored Procedures/Organization_DeleteById.sql b/src/Sql/dbo/Stored Procedures/Organization_DeleteById.sql
index 3f900203be63..c54a08c0296b 100644
--- a/src/Sql/dbo/Stored Procedures/Organization_DeleteById.sql
+++ b/src/Sql/dbo/Stored Procedures/Organization_DeleteById.sql
@@ -73,6 +73,20 @@ BEGIN
WHERE
[OrganizationId] = @Id
+ DELETE AK
+ FROM
+ [dbo].[ApiKey] AK
+ INNER JOIN
+ [dbo].[ServiceAccount] SA ON [AK].[ServiceAccountId] = [SA].[Id]
+ WHERE
+ [SA].[OrganizationId] = @Id
+
+ DELETE
+ FROM
+ [dbo].[ServiceAccount]
+ WHERE
+ [OrganizationId] = @Id
+
DELETE
FROM
[dbo].[Organization]
diff --git a/src/Sql/dbo/Stored Procedures/User_DeleteById.sql b/src/Sql/dbo/Stored Procedures/User_DeleteById.sql
index 726b7cb58ddc..ce32f2f24a42 100644
--- a/src/Sql/dbo/Stored Procedures/User_DeleteById.sql
+++ b/src/Sql/dbo/Stored Procedures/User_DeleteById.sql
@@ -58,6 +58,16 @@ BEGIN
WHERE
OU.[UserId] = @Id
+ -- Delete AccessPolicy
+ DELETE
+ AP
+ FROM
+ [dbo].[AccessPolicy] AP
+ INNER JOIN
+ [dbo].[OrganizationUser] OU ON OU.[Id] = AP.[OrganizationUserId]
+ WHERE
+ [UserId] = @Id
+
-- Delete organization users
DELETE
FROM
diff --git a/src/Sql/dbo/Tables/ProjectSecret.sql b/src/Sql/dbo/Tables/ProjectSecret.sql
index 73a2c8b0e354..6162dc7288c8 100644
--- a/src/Sql/dbo/Tables/ProjectSecret.sql
+++ b/src/Sql/dbo/Tables/ProjectSecret.sql
@@ -7,4 +7,4 @@
);
GO
-CREATE INDEX [IX_ProjectSecret_SecretsId] ON [ProjectSecret] ([SecretsId]);
+CREATE NONCLUSTERED INDEX [IX_ProjectSecret_SecretsId] ON [ProjectSecret] ([SecretsId]);
diff --git a/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql b/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql
index 18f21ad81f6b..5c93a181b557 100644
--- a/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql
+++ b/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql
@@ -17,10 +17,10 @@ SELECT
O.[Use2fa],
O.[UseApi],
O.[UseResetPassword],
- O.[UseSecretsManager],
O.[SelfHost],
O.[UsersGetPremium],
O.[UseCustomPermissions],
+ O.[UseSecretsManager],
O.[Seats],
O.[MaxCollections],
O.[MaxStorageGb],
diff --git a/util/Migrator/DbScripts/2022-07-20_00_CreateSecretTable.sql b/util/Migrator/DbScripts/2022-07-20_00_CreateSecretTable.sql
deleted file mode 100644
index bd9dd66f8b32..000000000000
--- a/util/Migrator/DbScripts/2022-07-20_00_CreateSecretTable.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-IF OBJECT_ID('[dbo].[Secret]') IS NULL
-BEGIN
- CREATE TABLE [dbo].[Secret] (
- [Id] UNIQUEIDENTIFIER NOT NULL,
- [OrganizationId] UNIQUEIDENTIFIER NOT NULL,
- [Key] NVARCHAR(MAX) NULL,
- [Value] NVARCHAR(MAX) NULL,
- [Note] NVARCHAR(MAX) NULL,
- [CreationDate] DATETIME2(7) NOT NULL,
- [RevisionDate] DATETIME2(7) NOT NULL,
- [DeletedDate] DATETIME2(7) NULL,
- CONSTRAINT [PK_Secret] PRIMARY KEY CLUSTERED ([Id] ASC),
- CONSTRAINT [FK_Secret_OrganizationId] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization]([Id]) ON DELETE CASCADE
- );
-
- CREATE NONCLUSTERED INDEX [IX_Secret_OrganizationId] ON [dbo].[Secret] ([OrganizationId] ASC);
-
- CREATE NONCLUSTERED INDEX [IX_Secret_DeletedDate] ON [dbo].[Secret] ([DeletedDate] ASC);
-END
-GO
diff --git a/util/Migrator/DbScripts/2022-08-10_00_Project.sql b/util/Migrator/DbScripts/2022-08-10_00_Project.sql
deleted file mode 100644
index 247aa2dd8fe4..000000000000
--- a/util/Migrator/DbScripts/2022-08-10_00_Project.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-IF OBJECT_ID('[dbo].[Project]') IS NULL
-BEGIN
-CREATE TABLE [dbo].[Project] (
- [Id] UNIQUEIDENTIFIER NOT NULL,
- [OrganizationId] UNIQUEIDENTIFIER NOT NULL,
- [Name] NVARCHAR(MAX) NULL,
- [CreationDate] DATETIME2 (7),
- [RevisionDate] DATETIME2 (7),
- [DeletedDate] DATETIME2 (7) NULL,
- CONSTRAINT [PK_Project] PRIMARY KEY CLUSTERED ([Id] ASC),
- CONSTRAINT [FK_Project_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) ON DELETE CASCADE,
-);
-
-CREATE NONCLUSTERED INDEX [IX_Project_OrganizationId] ON [dbo].[Project] ([OrganizationId] ASC);
-
-CREATE NONCLUSTERED INDEX [IX_Project_DeletedDate] ON [dbo].[Project] ([DeletedDate] ASC);
-
-END
-
-GO
diff --git a/util/Migrator/DbScripts/2022-09-19_00_ProjectSecret.sql b/util/Migrator/DbScripts/2022-09-19_00_ProjectSecret.sql
deleted file mode 100644
index 84443b7cc6d0..000000000000
--- a/util/Migrator/DbScripts/2022-09-19_00_ProjectSecret.sql
+++ /dev/null
@@ -1,120 +0,0 @@
-CREATE OR ALTER PROCEDURE [dbo].[Organization_DeleteById]
- @Id UNIQUEIDENTIFIER
-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].[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
- 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
-
- DELETE
- FROM
- [dbo].[Project]
- WHERE
- [OrganizationId] = @Id
-
- DELETE
- FROM
- [dbo].[Secret]
- WHERE
- [OrganizationId] = @Id
-
- DELETE
- FROM
- [dbo].[Organization]
- WHERE
- [Id] = @Id
-
- COMMIT TRANSACTION Organization_DeleteById
-END
-GO
-
--- Update project and secret table to NOT on delete cascade anymore
-IF EXISTS (SELECT name
- FROM sys.foreign_keys
- WHERE name = 'FK_Project_Organization')
-BEGIN
- ALTER TABLE [Project] DROP CONSTRAINT FK_Project_Organization;
-END
-
-ALTER TABLE [Project] ADD CONSTRAINT [FK_Project_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]);
-
-IF EXISTS (SELECT name
- FROM sys.foreign_keys
- WHERE name = 'FK_Secret_OrganizationId')
-BEGIN
- ALTER TABLE [Secret] DROP CONSTRAINT FK_Secret_OrganizationId;
-END
-
-ALTER TABLE [Secret] ADD CONSTRAINT [FK_Secret_OrganizationId] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]);
-
-IF OBJECT_ID('[dbo].[ProjectSecret]') IS NULL
-BEGIN
- CREATE TABLE [ProjectSecret] (
- [ProjectsId] UNIQUEIDENTIFIER NOT NULL,
- [SecretsId] UNIQUEIDENTIFIER NOT NULL,
- CONSTRAINT [PK_ProjectSecret] PRIMARY KEY ([ProjectsId], [SecretsId]),
- CONSTRAINT [FK_ProjectSecret_Project_ProjectsId] FOREIGN KEY ([ProjectsId]) REFERENCES [Project] ([Id]) ON DELETE CASCADE,
- CONSTRAINT [FK_ProjectSecret_Secret_SecretsId] FOREIGN KEY ([SecretsId]) REFERENCES [Secret] ([Id]) ON DELETE CASCADE
- );
-
- CREATE INDEX [IX_ProjectSecret_SecretsId] ON [ProjectSecret] ([SecretsId]);
-
-END
-
-GO
-
diff --git a/util/Migrator/DbScripts/2022-09-26_00_SmServiceAccount.sql b/util/Migrator/DbScripts/2022-09-26_00_SmServiceAccount.sql
deleted file mode 100644
index fc8953917d38..000000000000
--- a/util/Migrator/DbScripts/2022-09-26_00_SmServiceAccount.sql
+++ /dev/null
@@ -1,16 +0,0 @@
-IF OBJECT_ID('[dbo].[ServiceAccount]') IS NULL
-BEGIN
-CREATE TABLE [dbo].[ServiceAccount]
-(
- [Id] UNIQUEIDENTIFIER NOT NULL,
- [OrganizationId] UNIQUEIDENTIFIER NOT NULL,
- [Name] NVARCHAR(MAX) NULL,
- [CreationDate] DATETIME2(7) NOT NULL,
- [RevisionDate] DATETIME2(7) NOT NULL,
- CONSTRAINT [PK_ServiceAccount] PRIMARY KEY CLUSTERED ([Id] ASC),
- CONSTRAINT [FK_ServiceAccount_OrganizationId] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization]([Id]) ON DELETE CASCADE
-);
-
-CREATE NONCLUSTERED INDEX [IX_ServiceAccount_OrganizationId] ON [dbo].[ServiceAccount] ([OrganizationId] ASC);
-END
-GO
diff --git a/util/Migrator/DbScripts/2022-09-27_00_ApiKey.sql b/util/Migrator/DbScripts/2022-09-27_00_ApiKey.sql
deleted file mode 100644
index c219a274ca3e..000000000000
--- a/util/Migrator/DbScripts/2022-09-27_00_ApiKey.sql
+++ /dev/null
@@ -1,43 +0,0 @@
-IF OBJECT_ID('[dbo].[ApiKey]') IS NULL
-BEGIN
- CREATE TABLE [dbo].[ApiKey] (
- [Id] UNIQUEIDENTIFIER,
- [ServiceAccountId] UNIQUEIDENTIFIER NULL,
- [Name] VARCHAR(200) NOT NULL,
- [ClientSecret] VARCHAR(30) NOT NULL,
- [Scope] NVARCHAR (4000) NOT NULL,
- [EncryptedPayload] NVARCHAR (4000) NOT NULL,
- [Key] VARCHAR (MAX) NOT NULL,
- [ExpireAt] DATETIME2(7) NOT NULL,
- [CreationDate] DATETIME2(7) NOT NULL,
- [RevisionDate] DATETIME2(7) NOT NULL,
- CONSTRAINT [PK_ApiKey] PRIMARY KEY CLUSTERED ([Id] ASC),
- CONSTRAINT [FK_ApiKey_ServiceAccountId] FOREIGN KEY ([ServiceAccountId]) REFERENCES [dbo].[ServiceAccount] ([Id])
- );
-
- CREATE NONCLUSTERED INDEX [IX_ApiKey_ServiceAccountId]
- ON [dbo].[ApiKey]([ServiceAccountId] ASC);
-END
-GO
-
-CREATE OR ALTER VIEW [dbo].[ApiKeyView]
-AS
-SELECT
- *
-FROM
- [dbo].[ApiKey]
-GO
-
-CREATE OR ALTER PROCEDURE [dbo].[ApiKey_ReadById]
- @Id UNIQUEIDENTIFIER
-AS
-BEGIN
- SET NOCOUNT ON
-
- SELECT
- *
- FROM
- [dbo].[ApiKeyView]
- WHERE
- [Id] = @Id
-END
diff --git a/util/Migrator/DbScripts/2022-10-25_00_AccessPolicy.sql b/util/Migrator/DbScripts/2022-10-25_00_AccessPolicy.sql
deleted file mode 100644
index 1bf9f770fd30..000000000000
--- a/util/Migrator/DbScripts/2022-10-25_00_AccessPolicy.sql
+++ /dev/null
@@ -1,93 +0,0 @@
--- Remove ON DELETE for service accounts
-IF EXISTS (SELECT name FROM sys.foreign_keys WHERE name = 'FK_ServiceAccount_OrganizationId')
-BEGIN
- ALTER TABLE [ServiceAccount] DROP CONSTRAINT [FK_ServiceAccount_OrganizationId];
-END
-
-ALTER TABLE [ServiceAccount] ADD CONSTRAINT [FK_ServiceAccount_OrganizationId] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]);
-GO
-
-IF OBJECT_ID('[dbo].[AccessPolicy]') IS NULL
-BEGIN
- CREATE TABLE [AccessPolicy] (
- [Id] UNIQUEIDENTIFIER NOT NULL,
- [Discriminator] NVARCHAR(50) NOT NULL,
- [OrganizationUserId] UNIQUEIDENTIFIER NULL,
- [GroupId] UNIQUEIDENTIFIER NULL,
- [ServiceAccountId] UNIQUEIDENTIFIER NULL,
- [GrantedProjectId] UNIQUEIDENTIFIER NULL,
- [GrantedServiceAccountId] UNIQUEIDENTIFIER NULL,
- [Read] BIT NOT NULL,
- [Write] BIT NOT NULL,
- [CreationDate] DATETIME2 NOT NULL,
- [RevisionDate] DATETIME2 NOT NULL,
- CONSTRAINT [PK_AccessPolicy] PRIMARY KEY CLUSTERED ([Id]),
- CONSTRAINT [FK_AccessPolicy_Group_GroupId] FOREIGN KEY ([GroupId]) REFERENCES [Group] ([Id]) ON DELETE CASCADE,
- CONSTRAINT [FK_AccessPolicy_OrganizationUser_OrganizationUserId] FOREIGN KEY ([OrganizationUserId]) REFERENCES [OrganizationUser] ([Id]),
- CONSTRAINT [FK_AccessPolicy_Project_GrantedProjectId] FOREIGN KEY ([GrantedProjectId]) REFERENCES [Project] ([Id]) ON DELETE CASCADE,
- CONSTRAINT [FK_AccessPolicy_ServiceAccount_GrantedServiceAccountId] FOREIGN KEY ([GrantedServiceAccountId]) REFERENCES [ServiceAccount] ([Id]),
- CONSTRAINT [FK_AccessPolicy_ServiceAccount_ServiceAccountId] FOREIGN KEY ([ServiceAccountId]) REFERENCES [ServiceAccount] ([Id])
- );
-
- CREATE NONCLUSTERED INDEX [IX_AccessPolicy_GroupId] ON [AccessPolicy] ([GroupId]);
-
- CREATE NONCLUSTERED INDEX [IX_AccessPolicy_OrganizationUserId] ON [AccessPolicy] ([OrganizationUserId]);
-
- CREATE NONCLUSTERED INDEX [IX_AccessPolicy_GrantedProjectId] ON [AccessPolicy] ([GrantedProjectId]);
-
- CREATE NONCLUSTERED INDEX [IX_AccessPolicy_ServiceAccountId] ON [AccessPolicy] ([ServiceAccountId]);
-
- CREATE NONCLUSTERED INDEX [IX_AccessPolicy_GrantedServiceAccountId] ON [AccessPolicy] ([GrantedServiceAccountId]);
-END
-GO
-
-CREATE OR ALTER PROCEDURE [dbo].[OrganizationUser_DeleteById]
- @Id UNIQUEIDENTIFIER
-AS
-BEGIN
- SET NOCOUNT ON
-
- EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @Id
-
- DECLARE @OrganizationId UNIQUEIDENTIFIER
- DECLARE @UserId UNIQUEIDENTIFIER
-
- SELECT
- @OrganizationId = [OrganizationId],
- @UserId = [UserId]
- FROM
- [dbo].[OrganizationUser]
- WHERE
- [Id] = @Id
-
- IF @OrganizationId IS NOT NULL AND @UserId IS NOT NULL
- BEGIN
- EXEC [dbo].[SsoUser_Delete] @UserId, @OrganizationId
- END
-
- DELETE
- FROM
- [dbo].[CollectionUser]
- WHERE
- [OrganizationUserId] = @Id
-
- DELETE
- FROM
- [dbo].[GroupUser]
- WHERE
- [OrganizationUserId] = @Id
-
- DELETE
- FROM
- [dbo].[AccessPolicy]
- WHERE
- [OrganizationUserId] = @Id
-
- EXEC [dbo].[OrganizationSponsorship_OrganizationUserDeleted] @Id
-
- DELETE
- FROM
- [dbo].[OrganizationUser]
- WHERE
- [Id] = @Id
-END
diff --git a/util/Migrator/DbScripts/2022-11-01_00_ApiKeyUi.sql b/util/Migrator/DbScripts/2022-11-01_00_ApiKeyUi.sql
deleted file mode 100644
index f6316fb44239..000000000000
--- a/util/Migrator/DbScripts/2022-11-01_00_ApiKeyUi.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-CREATE OR ALTER PROCEDURE [dbo].[ApiKey_ReadByServiceAccountId]
- @ServiceAccountId UNIQUEIDENTIFIER
-AS
-BEGIN
- SET NOCOUNT ON
-
- SELECT
- *
- FROM
- [dbo].[ApiKeyView]
- WHERE
- [ServiceAccountId] = @ServiceAccountId
-END
diff --git a/util/Migrator/DbScripts/2022-11-03_00_ApiKeyDetails.sql b/util/Migrator/DbScripts/2022-11-03_00_ApiKeyDetails.sql
deleted file mode 100644
index 6ab0e3200610..000000000000
--- a/util/Migrator/DbScripts/2022-11-03_00_ApiKeyDetails.sql
+++ /dev/null
@@ -1,24 +0,0 @@
-CREATE OR ALTER VIEW [dbo].[ApiKeyDetailsView]
-AS
-SELECT
- AK.*,
- SA.[OrganizationId] ServiceAccountOrganizationId
-FROM
- [dbo].[ApiKey] AS AK
-LEFT JOIN
- [dbo].[ServiceAccount] SA ON SA.[Id] = AK.[ServiceAccountId]
-GO
-
-CREATE OR ALTER PROCEDURE [dbo].[ApiKeyDetails_ReadById]
- @Id UNIQUEIDENTIFIER
-AS
-BEGIN
- SET NOCOUNT ON
-
- SELECT
- *
- FROM
- [dbo].[ApiKeyDetailsView]
- WHERE
- [Id] = @Id
-END
diff --git a/util/Migrator/DbScripts/2022-11-14_00_ApiKey_Create.sql b/util/Migrator/DbScripts/2022-11-14_00_ApiKey_Create.sql
deleted file mode 100644
index 6c54e2fdc973..000000000000
--- a/util/Migrator/DbScripts/2022-11-14_00_ApiKey_Create.sql
+++ /dev/null
@@ -1,42 +0,0 @@
-CREATE OR ALTER PROCEDURE [dbo].[ApiKey_Create]
- @Id UNIQUEIDENTIFIER OUTPUT,
- @ServiceAccountId UNIQUEIDENTIFIER,
- @Name VARCHAR(200),
- @ClientSecret VARCHAR(30),
- @Scope NVARCHAR(4000),
- @EncryptedPayload NVARCHAR(4000),
- @Key VARCHAR(MAX),
- @ExpireAt DATETIME2(7),
- @CreationDate DATETIME2(7),
- @RevisionDate DATETIME2(7)
-AS
-BEGIN
- SET NOCOUNT ON
-
- INSERT INTO [dbo].[ApiKey]
- (
- [Id],
- [ServiceAccountId],
- [Name],
- [ClientSecret],
- [Scope],
- [EncryptedPayload],
- [Key],
- [ExpireAt],
- [CreationDate],
- [RevisionDate]
- )
- VALUES
- (
- @Id,
- @ServiceAccountId,
- @Name,
- @ClientSecret,
- @Scope,
- @EncryptedPayload,
- @Key,
- @ExpireAt,
- @CreationDate,
- @RevisionDate
- )
-END
diff --git a/util/Migrator/DbScripts/2022-11-15_00_SecretsManagerFlag.sql b/util/Migrator/DbScripts/2022-11-15_00_SecretsManagerFlag.sql
deleted file mode 100644
index 792b57f856dc..000000000000
--- a/util/Migrator/DbScripts/2022-11-15_00_SecretsManagerFlag.sql
+++ /dev/null
@@ -1,316 +0,0 @@
-IF COL_LENGTH('[dbo].[Organization]', 'UseSecretsManager') IS NULL
- BEGIN
- ALTER TABLE
- [dbo].[Organization]
- ADD
- [UseSecretsManager] BIT NOT NULL CONSTRAINT [DF_Organization_UseSecretsManager] DEFAULT (0)
- END
-GO
-
-CREATE OR ALTER PROCEDURE [dbo].[Organization_Create]
- @Id UNIQUEIDENTIFIER OUTPUT,
- @Identifier NVARCHAR(50),
- @Name NVARCHAR(50),
- @BusinessName NVARCHAR(50),
- @BusinessAddress1 NVARCHAR(50),
- @BusinessAddress2 NVARCHAR(50),
- @BusinessAddress3 NVARCHAR(50),
- @BusinessCountry VARCHAR(2),
- @BusinessTaxNumber NVARCHAR(30),
- @BillingEmail NVARCHAR(256),
- @Plan NVARCHAR(50),
- @PlanType TINYINT,
- @Seats INT,
- @MaxCollections SMALLINT,
- @UsePolicies BIT,
- @UseSso BIT,
- @UseGroups BIT,
- @UseDirectory BIT,
- @UseEvents BIT,
- @UseTotp BIT,
- @Use2fa BIT,
- @UseApi BIT,
- @UseResetPassword BIT,
- @SelfHost BIT,
- @UsersGetPremium BIT,
- @Storage BIGINT,
- @MaxStorageGb SMALLINT,
- @Gateway TINYINT,
- @GatewayCustomerId VARCHAR(50),
- @GatewaySubscriptionId VARCHAR(50),
- @ReferenceData VARCHAR(MAX),
- @Enabled BIT,
- @LicenseKey VARCHAR(100),
- @PublicKey VARCHAR(MAX),
- @PrivateKey VARCHAR(MAX),
- @TwoFactorProviders NVARCHAR(MAX),
- @ExpirationDate DATETIME2(7),
- @CreationDate DATETIME2(7),
- @RevisionDate DATETIME2(7),
- @OwnersNotifiedOfAutoscaling DATETIME2(7),
- @MaxAutoscaleSeats INT,
- @UseKeyConnector BIT = 0,
- @UseScim BIT = 0,
- @UseSecretsManager BIT = 0
-AS
-BEGIN
- SET NOCOUNT ON
-
- INSERT INTO [dbo].[Organization]
- (
- [Id],
- [Identifier],
- [Name],
- [BusinessName],
- [BusinessAddress1],
- [BusinessAddress2],
- [BusinessAddress3],
- [BusinessCountry],
- [BusinessTaxNumber],
- [BillingEmail],
- [Plan],
- [PlanType],
- [Seats],
- [MaxCollections],
- [UsePolicies],
- [UseSso],
- [UseGroups],
- [UseDirectory],
- [UseEvents],
- [UseTotp],
- [Use2fa],
- [UseApi],
- [UseResetPassword],
- [SelfHost],
- [UsersGetPremium],
- [Storage],
- [MaxStorageGb],
- [Gateway],
- [GatewayCustomerId],
- [GatewaySubscriptionId],
- [ReferenceData],
- [Enabled],
- [LicenseKey],
- [PublicKey],
- [PrivateKey],
- [TwoFactorProviders],
- [ExpirationDate],
- [CreationDate],
- [RevisionDate],
- [OwnersNotifiedOfAutoscaling],
- [MaxAutoscaleSeats],
- [UseKeyConnector],
- [UseScim],
- [UseSecretsManager]
- )
- VALUES
- (
- @Id,
- @Identifier,
- @Name,
- @BusinessName,
- @BusinessAddress1,
- @BusinessAddress2,
- @BusinessAddress3,
- @BusinessCountry,
- @BusinessTaxNumber,
- @BillingEmail,
- @Plan,
- @PlanType,
- @Seats,
- @MaxCollections,
- @UsePolicies,
- @UseSso,
- @UseGroups,
- @UseDirectory,
- @UseEvents,
- @UseTotp,
- @Use2fa,
- @UseApi,
- @UseResetPassword,
- @SelfHost,
- @UsersGetPremium,
- @Storage,
- @MaxStorageGb,
- @Gateway,
- @GatewayCustomerId,
- @GatewaySubscriptionId,
- @ReferenceData,
- @Enabled,
- @LicenseKey,
- @PublicKey,
- @PrivateKey,
- @TwoFactorProviders,
- @ExpirationDate,
- @CreationDate,
- @RevisionDate,
- @OwnersNotifiedOfAutoscaling,
- @MaxAutoscaleSeats,
- @UseKeyConnector,
- @UseScim,
- @UseSecretsManager
- )
-END
-GO
-
-CREATE OR ALTER PROCEDURE [dbo].[Organization_Update]
- @Id UNIQUEIDENTIFIER,
- @Identifier NVARCHAR(50),
- @Name NVARCHAR(50),
- @BusinessName NVARCHAR(50),
- @BusinessAddress1 NVARCHAR(50),
- @BusinessAddress2 NVARCHAR(50),
- @BusinessAddress3 NVARCHAR(50),
- @BusinessCountry VARCHAR(2),
- @BusinessTaxNumber NVARCHAR(30),
- @BillingEmail NVARCHAR(256),
- @Plan NVARCHAR(50),
- @PlanType TINYINT,
- @Seats INT,
- @MaxCollections SMALLINT,
- @UsePolicies BIT,
- @UseSso BIT,
- @UseGroups BIT,
- @UseDirectory BIT,
- @UseEvents BIT,
- @UseTotp BIT,
- @Use2fa BIT,
- @UseApi BIT,
- @UseResetPassword BIT,
- @SelfHost BIT,
- @UsersGetPremium BIT,
- @Storage BIGINT,
- @MaxStorageGb SMALLINT,
- @Gateway TINYINT,
- @GatewayCustomerId VARCHAR(50),
- @GatewaySubscriptionId VARCHAR(50),
- @ReferenceData VARCHAR(MAX),
- @Enabled BIT,
- @LicenseKey VARCHAR(100),
- @PublicKey VARCHAR(MAX),
- @PrivateKey VARCHAR(MAX),
- @TwoFactorProviders NVARCHAR(MAX),
- @ExpirationDate DATETIME2(7),
- @CreationDate DATETIME2(7),
- @RevisionDate DATETIME2(7),
- @OwnersNotifiedOfAutoscaling DATETIME2(7),
- @MaxAutoscaleSeats INT,
- @UseKeyConnector BIT = 0,
- @UseScim BIT = 0,
- @UseSecretsManager BIT = 0
-AS
-BEGIN
- SET NOCOUNT ON
-
- UPDATE
- [dbo].[Organization]
- SET
- [Identifier] = @Identifier,
- [Name] = @Name,
- [BusinessName] = @BusinessName,
- [BusinessAddress1] = @BusinessAddress1,
- [BusinessAddress2] = @BusinessAddress2,
- [BusinessAddress3] = @BusinessAddress3,
- [BusinessCountry] = @BusinessCountry,
- [BusinessTaxNumber] = @BusinessTaxNumber,
- [BillingEmail] = @BillingEmail,
- [Plan] = @Plan,
- [PlanType] = @PlanType,
- [Seats] = @Seats,
- [MaxCollections] = @MaxCollections,
- [UsePolicies] = @UsePolicies,
- [UseSso] = @UseSso,
- [UseGroups] = @UseGroups,
- [UseDirectory] = @UseDirectory,
- [UseEvents] = @UseEvents,
- [UseTotp] = @UseTotp,
- [Use2fa] = @Use2fa,
- [UseApi] = @UseApi,
- [UseResetPassword] = @UseResetPassword,
- [SelfHost] = @SelfHost,
- [UsersGetPremium] = @UsersGetPremium,
- [Storage] = @Storage,
- [MaxStorageGb] = @MaxStorageGb,
- [Gateway] = @Gateway,
- [GatewayCustomerId] = @GatewayCustomerId,
- [GatewaySubscriptionId] = @GatewaySubscriptionId,
- [ReferenceData] = @ReferenceData,
- [Enabled] = @Enabled,
- [LicenseKey] = @LicenseKey,
- [PublicKey] = @PublicKey,
- [PrivateKey] = @PrivateKey,
- [TwoFactorProviders] = @TwoFactorProviders,
- [ExpirationDate] = @ExpirationDate,
- [CreationDate] = @CreationDate,
- [RevisionDate] = @RevisionDate,
- [OwnersNotifiedOfAutoscaling] = @OwnersNotifiedOfAutoscaling,
- [MaxAutoscaleSeats] = @MaxAutoscaleSeats,
- [UseKeyConnector] = @UseKeyConnector,
- [UseScim] = @UseScim,
- [UseSecretsManager] = @UseSecretsManager
- WHERE
- [Id] = @Id
-END
-GO
-
-IF OBJECT_ID('[dbo].[OrganizationView]') IS NOT NULL
- BEGIN
- EXECUTE sp_refreshview N'[dbo].[OrganizationView]';
- END
-GO
-
-CREATE OR ALTER VIEW [dbo].[OrganizationUserOrganizationDetailsView]
-AS
-SELECT
- OU.[UserId],
- OU.[OrganizationId],
- O.[Name],
- O.[Enabled],
- O.[PlanType],
- O.[UsePolicies],
- O.[UseSso],
- O.[UseKeyConnector],
- O.[UseScim],
- O.[UseGroups],
- O.[UseDirectory],
- O.[UseEvents],
- O.[UseTotp],
- O.[Use2fa],
- O.[UseApi],
- O.[UseResetPassword],
- O.[UseSecretsManager],
- O.[SelfHost],
- O.[UsersGetPremium],
- O.[Seats],
- O.[MaxCollections],
- O.[MaxStorageGb],
- O.[Identifier],
- OU.[Key],
- OU.[ResetPasswordKey],
- O.[PublicKey],
- O.[PrivateKey],
- OU.[Status],
- OU.[Type],
- SU.[ExternalId] SsoExternalId,
- OU.[Permissions],
- PO.[ProviderId],
- P.[Name] ProviderName,
- SS.[Data] SsoConfig,
- OS.[FriendlyName] FamilySponsorshipFriendlyName,
- OS.[LastSyncDate] FamilySponsorshipLastSyncDate,
- OS.[ToDelete] FamilySponsorshipToDelete,
- OS.[ValidUntil] FamilySponsorshipValidUntil
-FROM
- [dbo].[OrganizationUser] OU
-LEFT JOIN
- [dbo].[Organization] O ON O.[Id] = OU.[OrganizationId]
-LEFT JOIN
- [dbo].[SsoUser] SU ON SU.[UserId] = OU.[UserId] AND SU.[OrganizationId] = OU.[OrganizationId]
-LEFT JOIN
- [dbo].[ProviderOrganization] PO ON PO.[OrganizationId] = O.[Id]
-LEFT JOIN
- [dbo].[Provider] P ON P.[Id] = PO.[ProviderId]
-LEFT JOIN
- [dbo].[SsoConfig] SS ON SS.[OrganizationId] = OU.[OrganizationId]
-LEFT JOIN
- [dbo].[OrganizationSponsorship] OS ON OS.[SponsoringOrganizationUserID] = OU.[Id]
diff --git a/util/Migrator/DbScripts/2022-11-29_00_ApiKey_Never_Expire.sql b/util/Migrator/DbScripts/2022-11-29_00_ApiKey_Never_Expire.sql
deleted file mode 100644
index 80fa099aa261..000000000000
--- a/util/Migrator/DbScripts/2022-11-29_00_ApiKey_Never_Expire.sql
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE [dbo].[ApiKey] ALTER COLUMN [ExpireAt] DATETIME2(7) NULL;
diff --git a/util/Migrator/DbScripts/2023-01-06_00_SecretsManager.sql b/util/Migrator/DbScripts/2023-01-06_00_SecretsManager.sql
new file mode 100644
index 000000000000..6a178e37525e
--- /dev/null
+++ b/util/Migrator/DbScripts/2023-01-06_00_SecretsManager.sql
@@ -0,0 +1,807 @@
+IF COL_LENGTH('[dbo].[Organization]', 'UseSecretsManager') IS NULL
+BEGIN
+ ALTER TABLE
+ [dbo].[Organization]
+ ADD
+ [UseSecretsManager] BIT NOT NULL CONSTRAINT [DF_Organization_UseSecretsManager] DEFAULT (0)
+END
+GO
+
+CREATE OR ALTER VIEW [dbo].[OrganizationUserOrganizationDetailsView]
+AS
+SELECT
+ OU.[UserId],
+ OU.[OrganizationId],
+ O.[Name],
+ O.[Enabled],
+ O.[PlanType],
+ O.[UsePolicies],
+ O.[UseSso],
+ O.[UseKeyConnector],
+ O.[UseScim],
+ O.[UseGroups],
+ O.[UseDirectory],
+ O.[UseEvents],
+ O.[UseTotp],
+ O.[Use2fa],
+ O.[UseApi],
+ O.[UseResetPassword],
+ O.[SelfHost],
+ O.[UsersGetPremium],
+ O.[UseCustomPermissions],
+ O.[UseSecretsManager],
+ O.[Seats],
+ O.[MaxCollections],
+ O.[MaxStorageGb],
+ O.[Identifier],
+ OU.[Key],
+ OU.[ResetPasswordKey],
+ O.[PublicKey],
+ O.[PrivateKey],
+ OU.[Status],
+ OU.[Type],
+ SU.[ExternalId] SsoExternalId,
+ OU.[Permissions],
+ PO.[ProviderId],
+ P.[Name] ProviderName,
+ SS.[Data] SsoConfig,
+ OS.[FriendlyName] FamilySponsorshipFriendlyName,
+ OS.[LastSyncDate] FamilySponsorshipLastSyncDate,
+ OS.[ToDelete] FamilySponsorshipToDelete,
+ OS.[ValidUntil] FamilySponsorshipValidUntil
+FROM
+ [dbo].[OrganizationUser] OU
+LEFT JOIN
+ [dbo].[Organization] O ON O.[Id] = OU.[OrganizationId]
+LEFT JOIN
+ [dbo].[SsoUser] SU ON SU.[UserId] = OU.[UserId] AND SU.[OrganizationId] = OU.[OrganizationId]
+LEFT JOIN
+ [dbo].[ProviderOrganization] PO ON PO.[OrganizationId] = O.[Id]
+LEFT JOIN
+ [dbo].[Provider] P ON P.[Id] = PO.[ProviderId]
+LEFT JOIN
+ [dbo].[SsoConfig] SS ON SS.[OrganizationId] = OU.[OrganizationId]
+LEFT JOIN
+ [dbo].[OrganizationSponsorship] OS ON OS.[SponsoringOrganizationUserID] = OU.[Id]
+GO
+
+CREATE OR ALTER PROCEDURE [dbo].[Organization_Create]
+ @Id UNIQUEIDENTIFIER OUTPUT,
+ @Identifier NVARCHAR(50),
+ @Name NVARCHAR(50),
+ @BusinessName NVARCHAR(50),
+ @BusinessAddress1 NVARCHAR(50),
+ @BusinessAddress2 NVARCHAR(50),
+ @BusinessAddress3 NVARCHAR(50),
+ @BusinessCountry VARCHAR(2),
+ @BusinessTaxNumber NVARCHAR(30),
+ @BillingEmail NVARCHAR(256),
+ @Plan NVARCHAR(50),
+ @PlanType TINYINT,
+ @Seats INT,
+ @MaxCollections SMALLINT,
+ @UsePolicies BIT,
+ @UseSso BIT,
+ @UseGroups BIT,
+ @UseDirectory BIT,
+ @UseEvents BIT,
+ @UseTotp BIT,
+ @Use2fa BIT,
+ @UseApi BIT,
+ @UseResetPassword BIT,
+ @SelfHost BIT,
+ @UsersGetPremium BIT,
+ @Storage BIGINT,
+ @MaxStorageGb SMALLINT,
+ @Gateway TINYINT,
+ @GatewayCustomerId VARCHAR(50),
+ @GatewaySubscriptionId VARCHAR(50),
+ @ReferenceData VARCHAR(MAX),
+ @Enabled BIT,
+ @LicenseKey VARCHAR(100),
+ @PublicKey VARCHAR(MAX),
+ @PrivateKey VARCHAR(MAX),
+ @TwoFactorProviders NVARCHAR(MAX),
+ @ExpirationDate DATETIME2(7),
+ @CreationDate DATETIME2(7),
+ @RevisionDate DATETIME2(7),
+ @OwnersNotifiedOfAutoscaling DATETIME2(7),
+ @MaxAutoscaleSeats INT,
+ @UseKeyConnector BIT = 0,
+ @UseScim BIT = 0,
+ @UseCustomPermissions BIT = 0,
+ @UseSecretsManager BIT = 0
+AS
+BEGIN
+ SET NOCOUNT ON
+
+ INSERT INTO [dbo].[Organization]
+ (
+ [Id],
+ [Identifier],
+ [Name],
+ [BusinessName],
+ [BusinessAddress1],
+ [BusinessAddress2],
+ [BusinessAddress3],
+ [BusinessCountry],
+ [BusinessTaxNumber],
+ [BillingEmail],
+ [Plan],
+ [PlanType],
+ [Seats],
+ [MaxCollections],
+ [UsePolicies],
+ [UseSso],
+ [UseGroups],
+ [UseDirectory],
+ [UseEvents],
+ [UseTotp],
+ [Use2fa],
+ [UseApi],
+ [UseResetPassword],
+ [SelfHost],
+ [UsersGetPremium],
+ [Storage],
+ [MaxStorageGb],
+ [Gateway],
+ [GatewayCustomerId],
+ [GatewaySubscriptionId],
+ [ReferenceData],
+ [Enabled],
+ [LicenseKey],
+ [PublicKey],
+ [PrivateKey],
+ [TwoFactorProviders],
+ [ExpirationDate],
+ [CreationDate],
+ [RevisionDate],
+ [OwnersNotifiedOfAutoscaling],
+ [MaxAutoscaleSeats],
+ [UseKeyConnector],
+ [UseScim],
+ [UseCustomPermissions],
+ [UseSecretsManager]
+ )
+ VALUES
+ (
+ @Id,
+ @Identifier,
+ @Name,
+ @BusinessName,
+ @BusinessAddress1,
+ @BusinessAddress2,
+ @BusinessAddress3,
+ @BusinessCountry,
+ @BusinessTaxNumber,
+ @BillingEmail,
+ @Plan,
+ @PlanType,
+ @Seats,
+ @MaxCollections,
+ @UsePolicies,
+ @UseSso,
+ @UseGroups,
+ @UseDirectory,
+ @UseEvents,
+ @UseTotp,
+ @Use2fa,
+ @UseApi,
+ @UseResetPassword,
+ @SelfHost,
+ @UsersGetPremium,
+ @Storage,
+ @MaxStorageGb,
+ @Gateway,
+ @GatewayCustomerId,
+ @GatewaySubscriptionId,
+ @ReferenceData,
+ @Enabled,
+ @LicenseKey,
+ @PublicKey,
+ @PrivateKey,
+ @TwoFactorProviders,
+ @ExpirationDate,
+ @CreationDate,
+ @RevisionDate,
+ @OwnersNotifiedOfAutoscaling,
+ @MaxAutoscaleSeats,
+ @UseKeyConnector,
+ @UseScim,
+ @UseCustomPermissions,
+ @UseSecretsManager
+ )
+END
+GO
+
+CREATE OR ALTER PROCEDURE [dbo].[Organization_Update]
+ @Id UNIQUEIDENTIFIER,
+ @Identifier NVARCHAR(50),
+ @Name NVARCHAR(50),
+ @BusinessName NVARCHAR(50),
+ @BusinessAddress1 NVARCHAR(50),
+ @BusinessAddress2 NVARCHAR(50),
+ @BusinessAddress3 NVARCHAR(50),
+ @BusinessCountry VARCHAR(2),
+ @BusinessTaxNumber NVARCHAR(30),
+ @BillingEmail NVARCHAR(256),
+ @Plan NVARCHAR(50),
+ @PlanType TINYINT,
+ @Seats INT,
+ @MaxCollections SMALLINT,
+ @UsePolicies BIT,
+ @UseSso BIT,
+ @UseGroups BIT,
+ @UseDirectory BIT,
+ @UseEvents BIT,
+ @UseTotp BIT,
+ @Use2fa BIT,
+ @UseApi BIT,
+ @UseResetPassword BIT,
+ @SelfHost BIT,
+ @UsersGetPremium BIT,
+ @Storage BIGINT,
+ @MaxStorageGb SMALLINT,
+ @Gateway TINYINT,
+ @GatewayCustomerId VARCHAR(50),
+ @GatewaySubscriptionId VARCHAR(50),
+ @ReferenceData VARCHAR(MAX),
+ @Enabled BIT,
+ @LicenseKey VARCHAR(100),
+ @PublicKey VARCHAR(MAX),
+ @PrivateKey VARCHAR(MAX),
+ @TwoFactorProviders NVARCHAR(MAX),
+ @ExpirationDate DATETIME2(7),
+ @CreationDate DATETIME2(7),
+ @RevisionDate DATETIME2(7),
+ @OwnersNotifiedOfAutoscaling DATETIME2(7),
+ @MaxAutoscaleSeats INT,
+ @UseKeyConnector BIT = 0,
+ @UseScim BIT = 0,
+ @UseCustomPermissions BIT = 0,
+ @UseSecretsManager BIT = 0
+AS
+BEGIN
+ SET NOCOUNT ON
+
+ UPDATE
+ [dbo].[Organization]
+ SET
+ [Identifier] = @Identifier,
+ [Name] = @Name,
+ [BusinessName] = @BusinessName,
+ [BusinessAddress1] = @BusinessAddress1,
+ [BusinessAddress2] = @BusinessAddress2,
+ [BusinessAddress3] = @BusinessAddress3,
+ [BusinessCountry] = @BusinessCountry,
+ [BusinessTaxNumber] = @BusinessTaxNumber,
+ [BillingEmail] = @BillingEmail,
+ [Plan] = @Plan,
+ [PlanType] = @PlanType,
+ [Seats] = @Seats,
+ [MaxCollections] = @MaxCollections,
+ [UsePolicies] = @UsePolicies,
+ [UseSso] = @UseSso,
+ [UseGroups] = @UseGroups,
+ [UseDirectory] = @UseDirectory,
+ [UseEvents] = @UseEvents,
+ [UseTotp] = @UseTotp,
+ [Use2fa] = @Use2fa,
+ [UseApi] = @UseApi,
+ [UseResetPassword] = @UseResetPassword,
+ [SelfHost] = @SelfHost,
+ [UsersGetPremium] = @UsersGetPremium,
+ [Storage] = @Storage,
+ [MaxStorageGb] = @MaxStorageGb,
+ [Gateway] = @Gateway,
+ [GatewayCustomerId] = @GatewayCustomerId,
+ [GatewaySubscriptionId] = @GatewaySubscriptionId,
+ [ReferenceData] = @ReferenceData,
+ [Enabled] = @Enabled,
+ [LicenseKey] = @LicenseKey,
+ [PublicKey] = @PublicKey,
+ [PrivateKey] = @PrivateKey,
+ [TwoFactorProviders] = @TwoFactorProviders,
+ [ExpirationDate] = @ExpirationDate,
+ [CreationDate] = @CreationDate,
+ [RevisionDate] = @RevisionDate,
+ [OwnersNotifiedOfAutoscaling] = @OwnersNotifiedOfAutoscaling,
+ [MaxAutoscaleSeats] = @MaxAutoscaleSeats,
+ [UseKeyConnector] = @UseKeyConnector,
+ [UseScim] = @UseScim,
+ [UseCustomPermissions] = @UseCustomPermissions,
+ [UseSecretsManager] = @UseSecretsManager
+ WHERE
+ [Id] = @Id
+END
+GO
+
+IF OBJECT_ID('[dbo].[Secret]') IS NULL
+BEGIN
+ CREATE TABLE [dbo].[Secret]
+ (
+ [Id] UNIQUEIDENTIFIER NOT NULL,
+ [OrganizationId] UNIQUEIDENTIFIER NOT NULL,
+ [Key] NVARCHAR(MAX) NULL,
+ [Value] NVARCHAR(MAX) NULL,
+ [Note] NVARCHAR(MAX) NULL,
+ [CreationDate] DATETIME2(7) NOT NULL,
+ [RevisionDate] DATETIME2(7) NOT NULL,
+ [DeletedDate] DATETIME2(7) NULL,
+ CONSTRAINT [PK_Secret] PRIMARY KEY CLUSTERED ([Id] ASC),
+ CONSTRAINT [FK_Secret_OrganizationId] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization]([Id])
+ );
+
+ CREATE NONCLUSTERED INDEX [IX_Secret_OrganizationId] ON [dbo].[Secret] ([OrganizationId] ASC);
+
+ CREATE NONCLUSTERED INDEX [IX_Secret_DeletedDate] ON [dbo].[Secret] ([DeletedDate] ASC);
+END
+GO
+
+IF OBJECT_ID('[dbo].[Project]') IS NULL
+BEGIN
+ CREATE TABLE [dbo].[Project] (
+ [Id] UNIQUEIDENTIFIER NOT NULL,
+ [OrganizationId] UNIQUEIDENTIFIER NOT NULL,
+ [Name] NVARCHAR(MAX) NULL,
+ [CreationDate] DATETIME2 (7),
+ [RevisionDate] DATETIME2 (7),
+ [DeletedDate] DATETIME2 (7) NULL,
+ CONSTRAINT [PK_Project] PRIMARY KEY CLUSTERED ([Id] ASC),
+ CONSTRAINT [FK_Project_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
+ );
+
+ CREATE NONCLUSTERED INDEX [IX_Project_OrganizationId] ON [dbo].[Project] ([OrganizationId] ASC);
+
+ CREATE NONCLUSTERED INDEX [IX_Project_DeletedDate] ON [dbo].[Project] ([DeletedDate] ASC);
+END
+GO
+
+IF OBJECT_ID('[dbo].[ProjectSecret]') IS NULL
+BEGIN
+ CREATE TABLE [dbo].[ProjectSecret] (
+ [ProjectsId] uniqueidentifier NOT NULL,
+ [SecretsId] uniqueidentifier NOT NULL,
+ CONSTRAINT [PK_ProjectSecret] PRIMARY KEY ([ProjectsId], [SecretsId]),
+ CONSTRAINT [FK_ProjectSecret_Project_ProjectsId] FOREIGN KEY ([ProjectsId]) REFERENCES [Project] ([Id]) ON DELETE CASCADE,
+ CONSTRAINT [FK_ProjectSecret_Secret_SecretsId] FOREIGN KEY ([SecretsId]) REFERENCES [Secret] ([Id]) ON DELETE CASCADE
+ );
+
+ CREATE NONCLUSTERED INDEX [IX_ProjectSecret_SecretsId] ON [ProjectSecret] ([SecretsId]);
+END
+GO
+
+IF OBJECT_ID('[dbo].[ServiceAccount]') IS NULL
+BEGIN
+ CREATE TABLE [dbo].[ServiceAccount]
+ (
+ [Id] UNIQUEIDENTIFIER NOT NULL,
+ [OrganizationId] UNIQUEIDENTIFIER NOT NULL,
+ [Name] NVARCHAR(MAX) NULL,
+ [CreationDate] DATETIME2(7) NOT NULL,
+ [RevisionDate] DATETIME2(7) NOT NULL,
+ CONSTRAINT [PK_ServiceAccount] PRIMARY KEY CLUSTERED ([Id] ASC),
+ CONSTRAINT [FK_ServiceAccount_OrganizationId] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization]([Id])
+ );
+
+ CREATE NONCLUSTERED INDEX [IX_ServiceAccount_OrganizationId] ON [dbo].[ServiceAccount] ([OrganizationId] ASC);
+END
+GO
+
+IF OBJECT_ID('[dbo].[ApiKey]') IS NULL
+BEGIN
+ CREATE TABLE [dbo].[ApiKey] (
+ [Id] UNIQUEIDENTIFIER,
+ [ServiceAccountId] UNIQUEIDENTIFIER NULL,
+ [Name] VARCHAR(200) NOT NULL,
+ [ClientSecret] VARCHAR(30) NOT NULL,
+ [Scope] NVARCHAR (4000) NOT NULL,
+ [EncryptedPayload] NVARCHAR (4000) NOT NULL,
+ [Key] VARCHAR (MAX) NOT NULL,
+ [ExpireAt] DATETIME2(7) NULL,
+ [CreationDate] DATETIME2(7) NOT NULL,
+ [RevisionDate] DATETIME2(7) NOT NULL,
+ CONSTRAINT [PK_ApiKey] PRIMARY KEY CLUSTERED ([Id] ASC),
+ CONSTRAINT [FK_ApiKey_ServiceAccountId] FOREIGN KEY ([ServiceAccountId]) REFERENCES [dbo].[ServiceAccount] ([Id])
+ );
+
+ CREATE NONCLUSTERED INDEX [IX_ApiKey_ServiceAccountId]
+ ON [dbo].[ApiKey]([ServiceAccountId] ASC);
+END
+GO
+
+CREATE OR ALTER VIEW [dbo].[ApiKeyDetailsView]
+AS
+SELECT
+ AK.*,
+ SA.[OrganizationId] ServiceAccountOrganizationId
+FROM
+ [dbo].[ApiKey] AS AK
+LEFT JOIN
+ [dbo].[ServiceAccount] SA ON SA.[Id] = AK.[ServiceAccountId]
+GO
+
+CREATE OR ALTER VIEW [dbo].[ApiKeyView]
+AS
+SELECT
+ *
+FROM
+ [dbo].[ApiKey]
+GO
+
+CREATE OR ALTER PROCEDURE [dbo].[ApiKey_Create]
+ @Id UNIQUEIDENTIFIER OUTPUT,
+ @ServiceAccountId UNIQUEIDENTIFIER,
+ @Name VARCHAR(200),
+ @ClientSecret VARCHAR(30),
+ @Scope NVARCHAR(4000),
+ @EncryptedPayload NVARCHAR(4000),
+ @Key VARCHAR(MAX),
+ @ExpireAt DATETIME2(7),
+ @CreationDate DATETIME2(7),
+ @RevisionDate DATETIME2(7)
+AS
+BEGIN
+ SET NOCOUNT ON
+
+ INSERT INTO [dbo].[ApiKey]
+ (
+ [Id],
+ [ServiceAccountId],
+ [Name],
+ [ClientSecret],
+ [Scope],
+ [EncryptedPayload],
+ [Key],
+ [ExpireAt],
+ [CreationDate],
+ [RevisionDate]
+ )
+ VALUES
+ (
+ @Id,
+ @ServiceAccountId,
+ @Name,
+ @ClientSecret,
+ @Scope,
+ @EncryptedPayload,
+ @Key,
+ @ExpireAt,
+ @CreationDate,
+ @RevisionDate
+ )
+END
+GO
+
+CREATE OR ALTER PROCEDURE [dbo].[ApiKey_ReadByServiceAccountId]
+ @ServiceAccountId UNIQUEIDENTIFIER
+AS
+BEGIN
+ SET NOCOUNT ON
+
+ SELECT
+ *
+ FROM
+ [dbo].[ApiKeyView]
+ WHERE
+ [ServiceAccountId] = @ServiceAccountId
+END
+GO
+
+CREATE OR ALTER PROCEDURE [dbo].[ApiKeyDetails_ReadById]
+ @Id UNIQUEIDENTIFIER
+AS
+BEGIN
+ SET NOCOUNT ON
+
+ SELECT
+ *
+ FROM
+ [dbo].[ApiKeyDetailsView]
+ WHERE
+ [Id] = @Id
+END
+GO
+
+IF OBJECT_ID('[dbo].[AccessPolicy]') IS NULL
+BEGIN
+ CREATE TABLE [AccessPolicy] (
+ [Id] UNIQUEIDENTIFIER NOT NULL,
+ [Discriminator] NVARCHAR(50) NOT NULL,
+ [OrganizationUserId] UNIQUEIDENTIFIER NULL,
+ [GroupId] UNIQUEIDENTIFIER NULL,
+ [ServiceAccountId] UNIQUEIDENTIFIER NULL,
+ [GrantedProjectId] UNIQUEIDENTIFIER NULL,
+ [GrantedServiceAccountId] UNIQUEIDENTIFIER NULL,
+ [Read] BIT NOT NULL,
+ [Write] BIT NOT NULL,
+ [CreationDate] DATETIME2 NOT NULL,
+ [RevisionDate] DATETIME2 NOT NULL,
+ CONSTRAINT [PK_AccessPolicy] PRIMARY KEY CLUSTERED ([Id]),
+ CONSTRAINT [FK_AccessPolicy_Group_GroupId] FOREIGN KEY ([GroupId]) REFERENCES [Group] ([Id]) ON DELETE CASCADE,
+ CONSTRAINT [FK_AccessPolicy_OrganizationUser_OrganizationUserId] FOREIGN KEY ([OrganizationUserId]) REFERENCES [OrganizationUser] ([Id]),
+ CONSTRAINT [FK_AccessPolicy_Project_GrantedProjectId] FOREIGN KEY ([GrantedProjectId]) REFERENCES [Project] ([Id]) ON DELETE CASCADE,
+ CONSTRAINT [FK_AccessPolicy_ServiceAccount_GrantedServiceAccountId] FOREIGN KEY ([GrantedServiceAccountId]) REFERENCES [ServiceAccount] ([Id]),
+ CONSTRAINT [FK_AccessPolicy_ServiceAccount_ServiceAccountId] FOREIGN KEY ([ServiceAccountId]) REFERENCES [ServiceAccount] ([Id])
+ );
+
+ CREATE NONCLUSTERED INDEX [IX_AccessPolicy_GroupId] ON [AccessPolicy] ([GroupId]);
+
+ CREATE NONCLUSTERED INDEX [IX_AccessPolicy_OrganizationUserId] ON [AccessPolicy] ([OrganizationUserId]);
+
+ CREATE NONCLUSTERED INDEX [IX_AccessPolicy_GrantedProjectId] ON [AccessPolicy] ([GrantedProjectId]);
+
+ CREATE NONCLUSTERED INDEX [IX_AccessPolicy_ServiceAccountId] ON [AccessPolicy] ([ServiceAccountId]);
+
+ CREATE NONCLUSTERED INDEX [IX_AccessPolicy_GrantedServiceAccountId] ON [AccessPolicy] ([GrantedServiceAccountId]);
+END
+GO
+
+CREATE OR ALTER PROCEDURE [dbo].[User_DeleteById]
+ @Id UNIQUEIDENTIFIER
+WITH RECOMPILE
+AS
+BEGIN
+ SET NOCOUNT ON
+ DECLARE @BatchSize INT = 100
+
+ -- Delete ciphers
+ WHILE @BatchSize > 0
+ BEGIN
+ BEGIN TRANSACTION User_DeleteById_Ciphers
+
+ DELETE TOP(@BatchSize)
+ FROM
+ [dbo].[Cipher]
+ WHERE
+ [UserId] = @Id
+
+ SET @BatchSize = @@ROWCOUNT
+
+ COMMIT TRANSACTION User_DeleteById_Ciphers
+ END
+
+ BEGIN TRANSACTION User_DeleteById
+
+ -- Delete folders
+ DELETE
+ FROM
+ [dbo].[Folder]
+ WHERE
+ [UserId] = @Id
+
+ -- Delete devices
+ DELETE
+ FROM
+ [dbo].[Device]
+ WHERE
+ [UserId] = @Id
+
+ -- Delete collection users
+ DELETE
+ CU
+ FROM
+ [dbo].[CollectionUser] CU
+ INNER JOIN
+ [dbo].[OrganizationUser] OU ON OU.[Id] = CU.[OrganizationUserId]
+ WHERE
+ OU.[UserId] = @Id
+
+ -- Delete group users
+ DELETE
+ GU
+ FROM
+ [dbo].[GroupUser] GU
+ INNER JOIN
+ [dbo].[OrganizationUser] OU ON OU.[Id] = GU.[OrganizationUserId]
+ WHERE
+ OU.[UserId] = @Id
+
+ -- Delete AccessPolicy
+ DELETE
+ AP
+ FROM
+ [dbo].[AccessPolicy] AP
+ INNER JOIN
+ [dbo].[OrganizationUser] OU ON OU.[Id] = AP.[OrganizationUserId]
+ WHERE
+ [UserId] = @Id
+
+ -- Delete organization users
+ DELETE
+ FROM
+ [dbo].[OrganizationUser]
+ WHERE
+ [UserId] = @Id
+
+ -- Delete provider users
+ DELETE
+ FROM
+ [dbo].[ProviderUser]
+ WHERE
+ [UserId] = @Id
+
+ -- Delete SSO Users
+ DELETE
+ FROM
+ [dbo].[SsoUser]
+ WHERE
+ [UserId] = @Id
+
+ -- Delete Emergency Accesses
+ DELETE
+ FROM
+ [dbo].[EmergencyAccess]
+ WHERE
+ [GrantorId] = @Id
+ OR
+ [GranteeId] = @Id
+
+ -- Delete Sends
+ DELETE
+ FROM
+ [dbo].[Send]
+ WHERE
+ [UserId] = @Id
+
+ -- Finally, delete the user
+ DELETE
+ FROM
+ [dbo].[User]
+ WHERE
+ [Id] = @Id
+
+ COMMIT TRANSACTION User_DeleteById
+END
+GO
+
+CREATE OR ALTER PROCEDURE [dbo].[Organization_DeleteById]
+ @Id UNIQUEIDENTIFIER
+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].[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
+ 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
+
+ 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
+ FROM
+ [dbo].[ServiceAccount]
+ WHERE
+ [OrganizationId] = @Id
+
+ DELETE
+ FROM
+ [dbo].[Organization]
+ WHERE
+ [Id] = @Id
+
+ COMMIT TRANSACTION Organization_DeleteById
+END
+GO
+
+CREATE OR ALTER PROCEDURE [dbo].[OrganizationUser_DeleteById]
+ @Id UNIQUEIDENTIFIER
+AS
+BEGIN
+ SET NOCOUNT ON
+
+ EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @Id
+
+ DECLARE @OrganizationId UNIQUEIDENTIFIER
+ DECLARE @UserId UNIQUEIDENTIFIER
+
+ SELECT
+ @OrganizationId = [OrganizationId],
+ @UserId = [UserId]
+ FROM
+ [dbo].[OrganizationUser]
+ WHERE
+ [Id] = @Id
+
+ IF @OrganizationId IS NOT NULL AND @UserId IS NOT NULL
+ BEGIN
+ EXEC [dbo].[SsoUser_Delete] @UserId, @OrganizationId
+ END
+
+ DELETE
+ FROM
+ [dbo].[CollectionUser]
+ WHERE
+ [OrganizationUserId] = @Id
+
+ DELETE
+ FROM
+ [dbo].[GroupUser]
+ WHERE
+ [OrganizationUserId] = @Id
+
+ DELETE
+ FROM
+ [dbo].[AccessPolicy]
+ WHERE
+ [OrganizationUserId] = @Id
+
+ EXEC [dbo].[OrganizationSponsorship_OrganizationUserDeleted] @Id
+
+ DELETE
+ FROM
+ [dbo].[OrganizationUser]
+ WHERE
+ [Id] = @Id
+END
+GO
diff --git a/util/MySqlMigrations/Migrations/20220720222516_CreateSecretTable.Designer.cs b/util/MySqlMigrations/Migrations/20220720222516_CreateSecretTable.Designer.cs
deleted file mode 100644
index cce26bfa366e..000000000000
--- a/util/MySqlMigrations/Migrations/20220720222516_CreateSecretTable.Designer.cs
+++ /dev/null
@@ -1,1643 +0,0 @@
-//
-using System;
-using Bit.Infrastructure.EntityFramework.Repositories;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-
-#nullable disable
-
-namespace Bit.MySqlMigrations.Migrations
-{
- [DbContext(typeof(DatabaseContext))]
- [Migration("20220720222516_CreateSecretTable")]
- partial class CreateSecretTable
- {
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "6.0.4")
- .HasAnnotation("Relational:MaxIdentifierLength", 64);
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Cipher", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("Attachments")
- .HasColumnType("longtext");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Data")
- .HasColumnType("longtext");
-
- b.Property("DeletedDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Favorites")
- .HasColumnType("longtext");
-
- b.Property("Folders")
- .HasColumnType("longtext");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("Reprompt")
- .HasColumnType("tinyint unsigned");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Type")
- .HasColumnType("tinyint unsigned");
-
- b.Property("UserId")
- .HasColumnType("char(36)");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.HasIndex("UserId");
-
- b.ToTable("Cipher", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Collection", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("ExternalId")
- .HasMaxLength(300)
- .HasColumnType("varchar(300)");
-
- b.Property("Name")
- .HasColumnType("longtext");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.ToTable("Collection", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.CollectionCipher", b =>
- {
- b.Property("CollectionId")
- .HasColumnType("char(36)");
-
- b.Property("CipherId")
- .HasColumnType("char(36)");
-
- b.HasKey("CollectionId", "CipherId");
-
- b.HasIndex("CipherId");
-
- b.ToTable("CollectionCipher", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.CollectionGroup", b =>
- {
- b.Property("CollectionId")
- .HasColumnType("char(36)");
-
- b.Property("GroupId")
- .HasColumnType("char(36)");
-
- b.Property("HidePasswords")
- .HasColumnType("tinyint(1)");
-
- b.Property("ReadOnly")
- .HasColumnType("tinyint(1)");
-
- b.HasKey("CollectionId", "GroupId");
-
- b.HasIndex("GroupId");
-
- b.ToTable("CollectionGroups");
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.CollectionUser", b =>
- {
- b.Property("CollectionId")
- .HasColumnType("char(36)");
-
- b.Property("OrganizationUserId")
- .HasColumnType("char(36)");
-
- b.Property("HidePasswords")
- .HasColumnType("tinyint(1)");
-
- b.Property("ReadOnly")
- .HasColumnType("tinyint(1)");
-
- b.Property("UserId")
- .HasColumnType("char(36)");
-
- b.HasKey("CollectionId", "OrganizationUserId");
-
- b.HasIndex("OrganizationUserId");
-
- b.HasIndex("UserId");
-
- b.ToTable("CollectionUsers");
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Device", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("char(36)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Identifier")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("Name")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("PushToken")
- .HasMaxLength(255)
- .HasColumnType("varchar(255)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Type")
- .HasColumnType("tinyint unsigned");
-
- b.Property("UserId")
- .HasColumnType("char(36)");
-
- b.HasKey("Id");
-
- b.HasIndex("UserId");
-
- b.ToTable("Device", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.EmergencyAccess", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Email")
- .HasMaxLength(256)
- .HasColumnType("varchar(256)");
-
- b.Property("GranteeId")
- .HasColumnType("char(36)");
-
- b.Property("GrantorId")
- .HasColumnType("char(36)");
-
- b.Property("KeyEncrypted")
- .HasColumnType("longtext");
-
- b.Property("LastNotificationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("RecoveryInitiatedDate")
- .HasColumnType("datetime(6)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Status")
- .HasColumnType("tinyint unsigned");
-
- b.Property("Type")
- .HasColumnType("tinyint unsigned");
-
- b.Property("WaitTimeDays")
- .HasColumnType("int");
-
- b.HasKey("Id");
-
- b.HasIndex("GranteeId");
-
- b.HasIndex("GrantorId");
-
- b.ToTable("EmergencyAccess", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Event", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("ActingUserId")
- .HasColumnType("char(36)");
-
- b.Property("CipherId")
- .HasColumnType("char(36)");
-
- b.Property("CollectionId")
- .HasColumnType("char(36)");
-
- b.Property("Date")
- .HasColumnType("datetime(6)");
-
- b.Property("DeviceType")
- .HasColumnType("tinyint unsigned");
-
- b.Property("GroupId")
- .HasColumnType("char(36)");
-
- b.Property("InstallationId")
- .HasColumnType("char(36)");
-
- b.Property("IpAddress")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("OrganizationUserId")
- .HasColumnType("char(36)");
-
- b.Property("PolicyId")
- .HasColumnType("char(36)");
-
- b.Property("ProviderId")
- .HasColumnType("char(36)");
-
- b.Property("ProviderOrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("ProviderUserId")
- .HasColumnType("char(36)");
-
- b.Property("Type")
- .HasColumnType("int");
-
- b.Property("UserId")
- .HasColumnType("char(36)");
-
- b.HasKey("Id");
-
- b.ToTable("Event", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Folder", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Name")
- .HasColumnType("longtext");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("UserId")
- .HasColumnType("char(36)");
-
- b.HasKey("Id");
-
- b.HasIndex("UserId");
-
- b.ToTable("Folder", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Grant", b =>
- {
- b.Property("Key")
- .HasMaxLength(200)
- .HasColumnType("varchar(200)");
-
- b.Property("ClientId")
- .HasMaxLength(200)
- .HasColumnType("varchar(200)");
-
- b.Property("ConsumedDate")
- .HasColumnType("datetime(6)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Data")
- .HasColumnType("longtext");
-
- b.Property("Description")
- .HasMaxLength(200)
- .HasColumnType("varchar(200)");
-
- b.Property("ExpirationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("SessionId")
- .HasMaxLength(100)
- .HasColumnType("varchar(100)");
-
- b.Property("SubjectId")
- .HasMaxLength(200)
- .HasColumnType("varchar(200)");
-
- b.Property("Type")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.HasKey("Key");
-
- b.ToTable("Grant", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Group", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("AccessAll")
- .HasColumnType("tinyint(1)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("ExternalId")
- .HasMaxLength(300)
- .HasColumnType("varchar(300)");
-
- b.Property("Name")
- .HasMaxLength(100)
- .HasColumnType("varchar(100)");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.ToTable("Group", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.GroupUser", b =>
- {
- b.Property("GroupId")
- .HasColumnType("char(36)");
-
- b.Property("OrganizationUserId")
- .HasColumnType("char(36)");
-
- b.Property("UserId")
- .HasColumnType("char(36)");
-
- b.HasKey("GroupId", "OrganizationUserId");
-
- b.HasIndex("OrganizationUserId");
-
- b.HasIndex("UserId");
-
- b.ToTable("GroupUser", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Installation", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Email")
- .HasMaxLength(256)
- .HasColumnType("varchar(256)");
-
- b.Property("Enabled")
- .HasColumnType("tinyint(1)");
-
- b.Property("Key")
- .HasMaxLength(150)
- .HasColumnType("varchar(150)");
-
- b.HasKey("Id");
-
- b.ToTable("Installation", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Organization", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("BillingEmail")
- .HasMaxLength(256)
- .HasColumnType("varchar(256)");
-
- b.Property("BusinessAddress1")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("BusinessAddress2")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("BusinessAddress3")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("BusinessCountry")
- .HasMaxLength(2)
- .HasColumnType("varchar(2)");
-
- b.Property("BusinessName")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("BusinessTaxNumber")
- .HasMaxLength(30)
- .HasColumnType("varchar(30)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Enabled")
- .HasColumnType("tinyint(1)");
-
- b.Property("ExpirationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Gateway")
- .HasColumnType("tinyint unsigned");
-
- b.Property("GatewayCustomerId")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("GatewaySubscriptionId")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("Identifier")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("LicenseKey")
- .HasMaxLength(100)
- .HasColumnType("varchar(100)");
-
- b.Property("MaxAutoscaleSeats")
- .HasColumnType("int");
-
- b.Property("MaxCollections")
- .HasColumnType("smallint");
-
- b.Property("MaxStorageGb")
- .HasColumnType("smallint");
-
- b.Property("Name")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("OwnersNotifiedOfAutoscaling")
- .HasColumnType("datetime(6)");
-
- b.Property("Plan")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("PlanType")
- .HasColumnType("tinyint unsigned");
-
- b.Property("PrivateKey")
- .HasColumnType("longtext");
-
- b.Property("PublicKey")
- .HasColumnType("longtext");
-
- b.Property("ReferenceData")
- .HasColumnType("longtext");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Seats")
- .HasColumnType("int");
-
- b.Property("SelfHost")
- .HasColumnType("tinyint(1)");
-
- b.Property("Storage")
- .HasColumnType("bigint");
-
- b.Property("TwoFactorProviders")
- .HasColumnType("longtext");
-
- b.Property("Use2fa")
- .HasColumnType("tinyint(1)");
-
- b.Property("UseApi")
- .HasColumnType("tinyint(1)");
-
- b.Property("UseDirectory")
- .HasColumnType("tinyint(1)");
-
- b.Property("UseEvents")
- .HasColumnType("tinyint(1)");
-
- b.Property("UseGroups")
- .HasColumnType("tinyint(1)");
-
- b.Property("UseKeyConnector")
- .HasColumnType("tinyint(1)");
-
- b.Property("UsePolicies")
- .HasColumnType("tinyint(1)");
-
- b.Property("UseResetPassword")
- .HasColumnType("tinyint(1)");
-
- b.Property("UseScim")
- .HasColumnType("tinyint(1)");
-
- b.Property("UseSso")
- .HasColumnType("tinyint(1)");
-
- b.Property("UseTotp")
- .HasColumnType("tinyint(1)");
-
- b.Property("UsersGetPremium")
- .HasColumnType("tinyint(1)");
-
- b.HasKey("Id");
-
- b.ToTable("Organization", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.OrganizationApiKey", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("ApiKey")
- .HasMaxLength(30)
- .HasColumnType("varchar(30)");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Type")
- .HasColumnType("tinyint unsigned");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.ToTable("OrganizationApiKey", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.OrganizationConnection", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("Config")
- .HasColumnType("longtext");
-
- b.Property("Enabled")
- .HasColumnType("tinyint(1)");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("Type")
- .HasColumnType("tinyint unsigned");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.ToTable("OrganizationConnection", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.OrganizationSponsorship", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("FriendlyName")
- .HasMaxLength(256)
- .HasColumnType("varchar(256)");
-
- b.Property("LastSyncDate")
- .HasColumnType("datetime(6)");
-
- b.Property("OfferedToEmail")
- .HasMaxLength(256)
- .HasColumnType("varchar(256)");
-
- b.Property("PlanSponsorshipType")
- .HasColumnType("tinyint unsigned");
-
- b.Property("SponsoredOrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("SponsoringOrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("SponsoringOrganizationUserId")
- .HasColumnType("char(36)");
-
- b.Property("ToDelete")
- .HasColumnType("tinyint(1)");
-
- b.Property("ValidUntil")
- .HasColumnType("datetime(6)");
-
- b.HasKey("Id");
-
- b.HasIndex("SponsoredOrganizationId");
-
- b.HasIndex("SponsoringOrganizationId");
-
- b.ToTable("OrganizationSponsorship", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.OrganizationUser", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("AccessAll")
- .HasColumnType("tinyint(1)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Email")
- .HasMaxLength(256)
- .HasColumnType("varchar(256)");
-
- b.Property("ExternalId")
- .HasMaxLength(300)
- .HasColumnType("varchar(300)");
-
- b.Property("Key")
- .HasColumnType("longtext");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("Permissions")
- .HasColumnType("longtext");
-
- b.Property("ResetPasswordKey")
- .HasColumnType("longtext");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Status")
- .HasColumnType("smallint");
-
- b.Property("Type")
- .HasColumnType("tinyint unsigned");
-
- b.Property("UserId")
- .HasColumnType("char(36)");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.HasIndex("UserId");
-
- b.ToTable("OrganizationUser", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Policy", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Data")
- .HasColumnType("longtext");
-
- b.Property("Enabled")
- .HasColumnType("tinyint(1)");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Type")
- .HasColumnType("tinyint unsigned");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.ToTable("Policy", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Provider", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("BillingEmail")
- .HasColumnType("longtext");
-
- b.Property("BusinessAddress1")
- .HasColumnType("longtext");
-
- b.Property("BusinessAddress2")
- .HasColumnType("longtext");
-
- b.Property("BusinessAddress3")
- .HasColumnType("longtext");
-
- b.Property("BusinessCountry")
- .HasColumnType("longtext");
-
- b.Property("BusinessName")
- .HasColumnType("longtext");
-
- b.Property("BusinessTaxNumber")
- .HasColumnType("longtext");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Enabled")
- .HasColumnType("tinyint(1)");
-
- b.Property("Name")
- .HasColumnType("longtext");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Status")
- .HasColumnType("tinyint unsigned");
-
- b.Property("UseEvents")
- .HasColumnType("tinyint(1)");
-
- b.HasKey("Id");
-
- b.ToTable("Provider", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.ProviderOrganization", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Key")
- .HasColumnType("longtext");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("ProviderId")
- .HasColumnType("char(36)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Settings")
- .HasColumnType("longtext");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.HasIndex("ProviderId");
-
- b.ToTable("ProviderOrganization", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.ProviderUser", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Email")
- .HasColumnType("longtext");
-
- b.Property("Key")
- .HasColumnType("longtext");
-
- b.Property("Permissions")
- .HasColumnType("longtext");
-
- b.Property("ProviderId")
- .HasColumnType("char(36)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Status")
- .HasColumnType("tinyint unsigned");
-
- b.Property("Type")
- .HasColumnType("tinyint unsigned");
-
- b.Property("UserId")
- .HasColumnType("char(36)");
-
- b.HasKey("Id");
-
- b.HasIndex("ProviderId");
-
- b.HasIndex("UserId");
-
- b.ToTable("ProviderUser", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Secret", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("DeletedDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Key")
- .HasColumnType("longtext");
-
- b.Property("Note")
- .HasColumnType("longtext");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Value")
- .HasColumnType("longtext");
-
- b.HasKey("Id");
-
- b.HasIndex("DeletedDate")
- .HasAnnotation("SqlServer:Clustered", false);
-
- b.HasIndex("OrganizationId");
-
- b.ToTable("Secret", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("AccessCount")
- .HasColumnType("int");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Data")
- .HasColumnType("longtext");
-
- b.Property("DeletionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Disabled")
- .HasColumnType("tinyint(1)");
-
- b.Property("ExpirationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("HideEmail")
- .HasColumnType("tinyint(1)");
-
- b.Property("Key")
- .HasColumnType("longtext");
-
- b.Property("MaxAccessCount")
- .HasColumnType("int");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("Password")
- .HasMaxLength(300)
- .HasColumnType("varchar(300)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Type")
- .HasColumnType("tinyint unsigned");
-
- b.Property("UserId")
- .HasColumnType("char(36)");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.HasIndex("UserId");
-
- b.ToTable("Send", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.SsoConfig", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("bigint");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Data")
- .HasColumnType("longtext");
-
- b.Property("Enabled")
- .HasColumnType("tinyint(1)");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("RevisionDate")
- .HasColumnType("datetime(6)");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.ToTable("SsoConfig", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.SsoUser", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("bigint");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("ExternalId")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("OrganizationId")
- .HasColumnType("char(36)");
-
- b.Property("UserId")
- .HasColumnType("char(36)");
-
- b.HasKey("Id");
-
- b.HasIndex("OrganizationId");
-
- b.HasIndex("UserId");
-
- b.ToTable("SsoUser", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.TaxRate", b =>
- {
- b.Property("Id")
- .HasMaxLength(40)
- .HasColumnType("varchar(40)");
-
- b.Property("Active")
- .HasColumnType("tinyint(1)");
-
- b.Property("Country")
- .HasMaxLength(50)
- .HasColumnType("varchar(50)");
-
- b.Property("PostalCode")
- .HasMaxLength(10)
- .HasColumnType("varchar(10)");
-
- b.Property("Rate")
- .HasColumnType("decimal(65,30)");
-
- b.Property("State")
- .HasMaxLength(2)
- .HasColumnType("varchar(2)");
-
- b.HasKey("Id");
-
- b.ToTable("TaxRate", (string)null);
- });
-
- modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Transaction", b =>
- {
- b.Property("Id")
- .HasColumnType("char(36)");
-
- b.Property("Amount")
- .HasColumnType("decimal(65,30)");
-
- b.Property("CreationDate")
- .HasColumnType("datetime(6)");
-
- b.Property("Details")
- .HasMaxLength(100)
- .HasColumnType("varchar(100)");
-
- b.Property