1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-30 18:17:36 +01:00
bitwarden-server/util/Migrator/DbScripts/2020-06-24_00_SsoConfig.sql

140 lines
2.9 KiB
MySQL
Raw Normal View History

2020-06-22 05:35:05 +02:00
IF OBJECT_ID('[dbo].[SsoConfig]') IS NULL
BEGIN
CREATE TABLE [dbo].[SsoConfig] (
2020-06-24 05:54:27 +02:00
[Id] BIGINT IDENTITY (1, 1) NOT NULL,
[Enabled] BIT NOT NULL,
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
2020-06-22 05:35:05 +02:00
[Data] NVARCHAR (MAX) NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
2020-06-24 05:54:27 +02:00
CONSTRAINT [PK_SsoConfig] PRIMARY KEY CLUSTERED ([Id] ASC),
2020-06-22 05:35:05 +02:00
CONSTRAINT [FK_SsoConfig_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
);
END
2020-06-22 05:42:27 +02:00
GO
2020-06-22 15:49:16 +02:00
2020-06-24 21:21:48 +02:00
IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'SsoConfigView')
2020-06-22 16:45:37 +02:00
BEGIN
DROP VIEW [dbo].[SsoConfigView]
END
2020-06-22 15:49:16 +02:00
GO
CREATE VIEW [dbo].[SsoConfigView]
AS
SELECT
2020-06-24 18:24:36 +02:00
*
2020-06-22 15:49:16 +02:00
FROM
2020-06-24 18:24:36 +02:00
[dbo].[SsoConfig]
2020-06-24 21:18:42 +02:00
GO
2020-06-22 15:49:16 +02:00
2020-06-25 22:42:29 +02:00
IF OBJECT_ID('[dbo].[SsoConfig_Create]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[SsoConfig_Create]
END
GO
CREATE PROCEDURE [dbo].[SsoConfig_Create]
2020-06-26 00:06:27 +02:00
@Id BIGINT OUTPUT,
2020-06-25 22:42:29 +02:00
@Enabled BIT,
@OrganizationId UNIQUEIDENTIFIER,
@Data NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[SsoConfig]
(
[Enabled],
[OrganizationId],
[Data],
[CreationDate],
[RevisionDate]
)
VALUES
(
@Enabled,
@OrganizationId,
@Data,
@CreationDate,
@RevisionDate
)
2020-06-26 00:28:08 +02:00
SET @Id = SCOPE_IDENTITY();
2020-06-25 22:42:29 +02:00
END
GO
IF OBJECT_ID('[dbo].[SsoConfig_Update]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[SsoConfig_Update]
END
GO
CREATE PROCEDURE [dbo].[SsoConfig_Update]
@Id BIGINT,
@Enabled BIT,
@OrganizationId UNIQUEIDENTIFIER,
@Data NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[SsoConfig]
SET
[Enabled] = @Enabled,
[OrganizationId] = @OrganizationId,
[Data] = @Data,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE
[Id] = @Id
END
GO
2020-06-22 15:49:16 +02:00
IF OBJECT_ID('[dbo].[SsoConfig_ReadByIdentifier]') IS NOT NULL
2020-06-22 16:45:37 +02:00
BEGIN
DROP PROCEDURE [dbo].[SsoConfig_ReadByIdentifier]
END
2020-06-22 15:49:16 +02:00
GO
CREATE PROCEDURE [dbo].[SsoConfig_ReadByIdentifier]
@Identifier NVARCHAR(50)
AS
BEGIN
SET NOCOUNT ON
SELECT TOP 1
2020-06-24 22:14:59 +02:00
SSO.*
2020-06-22 15:49:16 +02:00
FROM
2020-06-24 22:14:59 +02:00
[dbo].[SsoConfigView] SSO
INNER JOIN
[dbo].[Organization] O ON O.[Id] = SSO.[OrganizationId]
AND O.[Identifier] = @Identifier
2020-06-22 15:49:16 +02:00
END
GO
IF OBJECT_ID('[dbo].[SsoConfig_ReadByOrganizationId]') IS NOT NULL
2020-06-22 16:45:37 +02:00
BEGIN
DROP PROCEDURE [dbo].[SsoConfig_ReadByOrganizationId]
END
2020-06-22 15:49:16 +02:00
GO
CREATE PROCEDURE [dbo].[SsoConfig_ReadByOrganizationId]
@OrganizationId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT TOP 1
*
FROM
[dbo].[SsoConfigView]
WHERE
2020-06-24 05:54:27 +02:00
[OrganizationId] = @OrganizationId
2020-06-22 15:49:16 +02:00
END
GO