1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-10 20:07:56 +01:00

Updates to SSO config DB setup

This commit is contained in:
Matt Portune 2020-06-23 23:54:27 -04:00
parent cf70a5e480
commit 09df3f64d3
5 changed files with 40 additions and 9 deletions

View File

@ -1,5 +1,6 @@
CREATE TABLE [dbo].[Organization] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[Identifier] NVARCHAR (50) NULL,
[Name] NVARCHAR (50) NOT NULL,
[BusinessName] NVARCHAR (50) NULL,
[BusinessAddress1] NVARCHAR (50) NULL,
@ -42,3 +43,6 @@ CREATE NONCLUSTERED INDEX [IX_Organization_Enabled]
ON [dbo].[Organization]([Id] ASC, [Enabled] ASC)
INCLUDE ([UseTotp]);
GO
CREATE NONCLUSTERED INDEX [IX_Organization_Identifier]
ON [dbo].[Organization]([Identifier] ASC)

View File

@ -1,8 +1,11 @@
CREATE TABLE [dbo].[SsoConfig] (
[OrganizationId] UNIQUEIDENTIFIER NULL,
[Id] BIGINT IDENTITY (1, 1) NOT NULL,
[Enabled] BIT NOT NULL,
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
[Identifier] NVARCHAR (50) NULL,
[Data] NVARCHAR (MAX) NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
CONSTRAINT [PK_SsoConfig] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_SsoConfig_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
);

View File

@ -1,6 +1,8 @@
CREATE VIEW [dbo].[SsoConfigView]
AS
SELECT
*
SSO.*
FROM
[dbo].[SsoConfig]
[dbo].[SsoConfig] SSO
INNER JOIN
[dbo].[Organization] O ON O.[Identifier] = SSO.[Identifier]

View File

@ -0,0 +1,18 @@
IF COL_LENGTH('[dbo].[Organization]', 'Identifier') IS NULL
BEGIN
ALTER TABLE
[dbo].[Organization]
ADD
[Identifier] NVARCHAR (50) NULL
END
GO
IF NOT EXISTS (
SELECT * FROM sys.indexes WHERE [Name]='IX_Organization_Identifier'
AND object_id = OBJECT_ID('[dbo].[Organization]')
)
BEGIN
CREATE NONCLUSTERED INDEX [IX_Organization_Identifier]
ON [dbo].[Organization]([Identifier] ASC)
END
GO

View File

@ -1,11 +1,14 @@
IF OBJECT_ID('[dbo].[SsoConfig]') IS NULL
BEGIN
CREATE TABLE [dbo].[SsoConfig] (
[OrganizationId] UNIQUEIDENTIFIER NULL,
[Id] BIGINT IDENTITY (1, 1) NOT NULL,
[Enabled] BIT NOT NULL,
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
[Identifier] NVARCHAR (50) NULL,
[Data] NVARCHAR (MAX) NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
CONSTRAINT [PK_SsoConfig] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_SsoConfig_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
);
END
@ -20,10 +23,11 @@ GO
CREATE VIEW [dbo].[SsoConfigView]
AS
SELECT
*
SSO.*
FROM
[dbo].[SsoConfig]
GO
[dbo].[SsoConfig] SSO
INNER JOIN
[dbo].[Organization] O ON O.[Identifier] = SSO.[Identifier]
IF OBJECT_ID('[dbo].[SsoConfig_ReadByIdentifier]') IS NOT NULL
BEGIN
@ -42,7 +46,7 @@ BEGIN
FROM
[dbo].[SsoConfigView]
WHERE
[Identifier] = @Identifier
[Identifier] = @Identifier
END
GO
@ -63,6 +67,6 @@ BEGIN
FROM
[dbo].[SsoConfigView]
WHERE
[OrganizationId] = @OrganizationId
[OrganizationId] = @OrganizationId
END
GO