diff --git a/src/Sql/dbo/Stored Procedures/SsoConfig_ReadByIdentifier.sql b/src/Sql/dbo/Stored Procedures/SsoConfig_ReadByIdentifier.sql index bcbd01f7ea..470c28e0de 100644 --- a/src/Sql/dbo/Stored Procedures/SsoConfig_ReadByIdentifier.sql +++ b/src/Sql/dbo/Stored Procedures/SsoConfig_ReadByIdentifier.sql @@ -5,9 +5,10 @@ BEGIN SET NOCOUNT ON SELECT TOP 1 - * + SSO.* FROM - [dbo].[SsoConfigView] - WHERE - [Identifier] = @Identifier + [dbo].[SsoConfigView] SSO + INNER JOIN + [dbo].[Organization] O ON O.[Id] = SSO.[OrganizationId] + AND O.[Identifier] = @Identifier END diff --git a/src/Sql/dbo/Tables/Organization.sql b/src/Sql/dbo/Tables/Organization.sql index 226335de70..d013eeccb1 100644 --- a/src/Sql/dbo/Tables/Organization.sql +++ b/src/Sql/dbo/Tables/Organization.sql @@ -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,8 @@ CREATE NONCLUSTERED INDEX [IX_Organization_Enabled] ON [dbo].[Organization]([Id] ASC, [Enabled] ASC) INCLUDE ([UseTotp]); +GO +CREATE UNIQUE NONCLUSTERED INDEX [IX_Organization_Identifier] + ON [dbo].[Organization]([Identifier] ASC) + WHERE [Identifier] IS NOT NULL; + diff --git a/src/Sql/dbo/Tables/SsoConfig.sql b/src/Sql/dbo/Tables/SsoConfig.sql index 2c0ecfeb7d..e425300eb9 100644 --- a/src/Sql/dbo/Tables/SsoConfig.sql +++ b/src/Sql/dbo/Tables/SsoConfig.sql @@ -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]) ); diff --git a/util/Migrator/DbScripts/2020-06-23_00_OrgIdentifier.sql b/util/Migrator/DbScripts/2020-06-23_00_OrgIdentifier.sql new file mode 100644 index 0000000000..04ed6b7089 --- /dev/null +++ b/util/Migrator/DbScripts/2020-06-23_00_OrgIdentifier.sql @@ -0,0 +1,19 @@ +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 UNIQUE NONCLUSTERED INDEX [IX_Organization_Identifier] + ON [dbo].[Organization]([Identifier] ASC) + WHERE [Identifier] IS NOT NULL; +END +GO diff --git a/util/Migrator/DbScripts/2020-06-16_00_OrgSso.sql b/util/Migrator/DbScripts/2020-06-23_01_SsoConfig.sql similarity index 79% rename from util/Migrator/DbScripts/2020-06-16_00_OrgSso.sql rename to util/Migrator/DbScripts/2020-06-23_01_SsoConfig.sql index a3ba8442da..9e3b9a48b8 100644 --- a/util/Migrator/DbScripts/2020-06-16_00_OrgSso.sql +++ b/util/Migrator/DbScripts/2020-06-23_01_SsoConfig.sql @@ -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 @@ -23,7 +26,6 @@ SELECT * FROM [dbo].[SsoConfig] -GO IF OBJECT_ID('[dbo].[SsoConfig_ReadByIdentifier]') IS NOT NULL BEGIN @@ -42,7 +44,7 @@ BEGIN FROM [dbo].[SsoConfigView] WHERE - [Identifier] = @Identifier + [Identifier] = @Identifier END GO @@ -63,6 +65,6 @@ BEGIN FROM [dbo].[SsoConfigView] WHERE - [OrganizationId] = @OrganizationId + [OrganizationId] = @OrganizationId END GO