﻿IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL
BEGIN
    CREATE TABLE [__EFMigrationsHistory] (
        [MigrationId] nvarchar(150) NOT NULL,
        [ProductVersion] nvarchar(32) NOT NULL,
        CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
    );
END;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    IF SCHEMA_ID(N'mig_id') IS NULL EXEC(N'CREATE SCHEMA [mig_id];');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    IF SCHEMA_ID(N'mig_portal') IS NULL EXEC(N'CREATE SCHEMA [mig_portal];');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_id].[DeviceCode] (
        [UserCode] nvarchar(200) NOT NULL,
        [DeviceCode] nvarchar(200) NOT NULL,
        [SubjectId] nvarchar(200) NULL,
        [SessionId] nvarchar(100) NULL,
        [ClientId] nvarchar(200) NOT NULL,
        [Description] nvarchar(200) NULL,
        [CreationTime] datetime2 NOT NULL,
        [Expiration] datetime2 NOT NULL,
        [Data] nvarchar(max) NOT NULL,
        CONSTRAINT [PK_DeviceCode] PRIMARY KEY ([UserCode])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_portal].[Language] (
        [LanguageCode] nvarchar(2) NOT NULL,
        [LanguageName] nvarchar(50) NOT NULL,
        [Supported] bit NOT NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_Language] PRIMARY KEY ([LanguageCode])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_id].[PersistedGrant] (
        [Key] nvarchar(200) NOT NULL,
        [Type] nvarchar(50) NOT NULL,
        [SubjectId] nvarchar(200) NULL,
        [SessionId] nvarchar(100) NULL,
        [ClientId] nvarchar(200) NOT NULL,
        [Description] nvarchar(200) NULL,
        [CreationTime] datetime2 NOT NULL,
        [Expiration] datetime2 NULL,
        [ConsumedTime] datetime2 NULL,
        [Data] nvarchar(max) NOT NULL,
        CONSTRAINT [PK_PersistedGrant] PRIMARY KEY ([Key])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_id].[Role] (
        [Id] int NOT NULL IDENTITY,
        [Name] nvarchar(256) NULL,
        [NormalizedName] nvarchar(256) NULL,
        [ConcurrencyStamp] nvarchar(max) NULL,
        CONSTRAINT [PK_Role] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_id].[User] (
        [Id] int NOT NULL IDENTITY,
        [UserName] nvarchar(256) NULL,
        [NormalizedUserName] nvarchar(256) NULL,
        [Email] nvarchar(256) NULL,
        [NormalizedEmail] nvarchar(256) NULL,
        [EmailConfirmed] bit NOT NULL,
        [PasswordHash] nvarchar(max) NULL,
        [SecurityStamp] nvarchar(max) NULL,
        [ConcurrencyStamp] nvarchar(max) NULL,
        [PhoneNumber] nvarchar(max) NULL,
        [PhoneNumberConfirmed] bit NOT NULL,
        [TwoFactorEnabled] bit NOT NULL,
        [LockoutEnd] datetimeoffset NULL,
        [LockoutEnabled] bit NOT NULL,
        [AccessFailedCount] int NOT NULL,
        CONSTRAINT [PK_User] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_portal].[Project] (
        [ProjectID] uniqueidentifier NOT NULL,
        [Name] nvarchar(50) NOT NULL,
        [DefaultLanguageCode] nvarchar(2) NOT NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        [DeletedBy] nvarchar(50) NULL,
        [DeletedAt] datetime2 NULL,
        CONSTRAINT [PK_Project] PRIMARY KEY ([ProjectID]),
        CONSTRAINT [FK_DefaultLanguage] FOREIGN KEY ([DefaultLanguageCode]) REFERENCES [mig_portal].[Language] ([LanguageCode])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_id].[RoleClaim] (
        [Id] int NOT NULL IDENTITY,
        [RoleId] int NOT NULL,
        [ClaimType] nvarchar(max) NULL,
        [ClaimValue] nvarchar(max) NULL,
        CONSTRAINT [PK_RoleClaim] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_RoleClaim_Role_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [mig_id].[Role] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_id].[UserClaim] (
        [Id] int NOT NULL IDENTITY,
        [UserId] int NOT NULL,
        [ClaimType] nvarchar(max) NULL,
        [ClaimValue] nvarchar(max) NULL,
        CONSTRAINT [PK_UserClaim] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_UserClaim_User_UserId] FOREIGN KEY ([UserId]) REFERENCES [mig_id].[User] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_id].[UserLogin] (
        [LoginProvider] nvarchar(450) NOT NULL,
        [ProviderKey] nvarchar(450) NOT NULL,
        [ProviderDisplayName] nvarchar(max) NULL,
        [UserId] int NOT NULL,
        CONSTRAINT [PK_UserLogin] PRIMARY KEY ([LoginProvider], [ProviderKey]),
        CONSTRAINT [FK_UserLogin_User_UserId] FOREIGN KEY ([UserId]) REFERENCES [mig_id].[User] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_id].[UserRole] (
        [UserId] int NOT NULL,
        [RoleId] int NOT NULL,
        CONSTRAINT [PK_UserRole] PRIMARY KEY ([UserId], [RoleId]),
        CONSTRAINT [FK_UserRole_Role_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [mig_id].[Role] ([Id]) ON DELETE CASCADE,
        CONSTRAINT [FK_UserRole_User_UserId] FOREIGN KEY ([UserId]) REFERENCES [mig_id].[User] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_id].[UserToken] (
        [UserId] int NOT NULL,
        [LoginProvider] nvarchar(450) NOT NULL,
        [Name] nvarchar(450) NOT NULL,
        [Value] nvarchar(max) NULL,
        CONSTRAINT [PK_UserToken] PRIMARY KEY ([UserId], [LoginProvider], [Name]),
        CONSTRAINT [FK_UserToken_User_UserId] FOREIGN KEY ([UserId]) REFERENCES [mig_id].[User] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE TABLE [mig_portal].[Partition] (
        [PartitionId] int NOT NULL IDENTITY,
        [ProjectID] uniqueidentifier NOT NULL,
        [PartitionValue] nvarchar(50) NOT NULL,
        [Label] nvarchar(50) NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_Partition] PRIMARY KEY ([PartitionId]),
        CONSTRAINT [FK_Project] FOREIGN KEY ([ProjectID]) REFERENCES [mig_portal].[Project] ([ProjectID]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE UNIQUE INDEX [IX_DeviceCode_DeviceCode] ON [mig_id].[DeviceCode] ([DeviceCode]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE INDEX [IX_DeviceCode_Expiration] ON [mig_id].[DeviceCode] ([Expiration]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE UNIQUE INDEX [UX_Partition] ON [mig_portal].[Partition] ([ProjectID], [PartitionValue]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE INDEX [IX_PersistedGrant_Expiration] ON [mig_id].[PersistedGrant] ([Expiration]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE INDEX [IX_PersistedGrant_SubjectId_ClientId_Type] ON [mig_id].[PersistedGrant] ([SubjectId], [ClientId], [Type]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE INDEX [IX_PersistedGrant_SubjectId_SessionId_Type] ON [mig_id].[PersistedGrant] ([SubjectId], [SessionId], [Type]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE INDEX [IX_Project_DefaultLanguageCode] ON [mig_portal].[Project] ([DefaultLanguageCode]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE UNIQUE INDEX [UX_Project_Name] ON [mig_portal].[Project] ([Name]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [RoleNameIndex] ON [mig_id].[Role] ([NormalizedName]) WHERE [NormalizedName] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE INDEX [IX_RoleClaim_RoleId] ON [mig_id].[RoleClaim] ([RoleId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE INDEX [EmailIndex] ON [mig_id].[User] ([NormalizedEmail]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [UserNameIndex] ON [mig_id].[User] ([NormalizedUserName]) WHERE [NormalizedUserName] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE INDEX [IX_UserClaim_UserId] ON [mig_id].[UserClaim] ([UserId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE INDEX [IX_UserLogin_UserId] ON [mig_id].[UserLogin] ([UserId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    CREATE INDEX [IX_UserRole_RoleId] ON [mig_id].[UserRole] ([RoleId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20201216130248_Initial'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20201216130248_Initial', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210215110416_ProjectTagsAndProperties'
)
BEGIN
    ALTER TABLE [mig_portal].[Project] ADD [Properties] nvarchar(max) NOT NULL DEFAULT N'[]';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210215110416_ProjectTagsAndProperties'
)
BEGIN
    ALTER TABLE [mig_portal].[Project] ADD [Tags] nvarchar(max) NOT NULL DEFAULT N'[]';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210215110416_ProjectTagsAndProperties'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210215110416_ProjectTagsAndProperties', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210311145043_Net5_0_201_IdSrvUpdate'
)
BEGIN
    				ALTER TABLE [mig_id].[UserToken] DROP CONSTRAINT [PK_UserToken]
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210311145043_Net5_0_201_IdSrvUpdate'
)
BEGIN
    				ALTER TABLE [mig_id].[UserLogin] DROP CONSTRAINT [PK_UserLogin]
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210311145043_Net5_0_201_IdSrvUpdate'
)
BEGIN
    DECLARE @var0 sysname;
    SELECT @var0 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_id].[UserToken]') AND [c].[name] = N'Name');
    IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [mig_id].[UserToken] DROP CONSTRAINT [' + @var0 + '];');
    ALTER TABLE [mig_id].[UserToken] ALTER COLUMN [Name] nvarchar(128) NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210311145043_Net5_0_201_IdSrvUpdate'
)
BEGIN
    DECLARE @var1 sysname;
    SELECT @var1 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_id].[UserToken]') AND [c].[name] = N'LoginProvider');
    IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [mig_id].[UserToken] DROP CONSTRAINT [' + @var1 + '];');
    ALTER TABLE [mig_id].[UserToken] ALTER COLUMN [LoginProvider] nvarchar(128) NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210311145043_Net5_0_201_IdSrvUpdate'
)
BEGIN
    DECLARE @var2 sysname;
    SELECT @var2 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_id].[UserLogin]') AND [c].[name] = N'ProviderKey');
    IF @var2 IS NOT NULL EXEC(N'ALTER TABLE [mig_id].[UserLogin] DROP CONSTRAINT [' + @var2 + '];');
    ALTER TABLE [mig_id].[UserLogin] ALTER COLUMN [ProviderKey] nvarchar(128) NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210311145043_Net5_0_201_IdSrvUpdate'
)
BEGIN
    DECLARE @var3 sysname;
    SELECT @var3 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_id].[UserLogin]') AND [c].[name] = N'LoginProvider');
    IF @var3 IS NOT NULL EXEC(N'ALTER TABLE [mig_id].[UserLogin] DROP CONSTRAINT [' + @var3 + '];');
    ALTER TABLE [mig_id].[UserLogin] ALTER COLUMN [LoginProvider] nvarchar(128) NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210311145043_Net5_0_201_IdSrvUpdate'
)
BEGIN
    				ALTER TABLE [mig_id].[UserToken] ADD  CONSTRAINT [PK_UserToken] PRIMARY KEY CLUSTERED 
    				(
    					[UserId] ASC,
    					[LoginProvider] ASC,
    					[Name] ASC
    				)
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210311145043_Net5_0_201_IdSrvUpdate'
)
BEGIN
    				ALTER TABLE [mig_id].[UserLogin] ADD  CONSTRAINT [PK_UserLogin] PRIMARY KEY CLUSTERED 
    				(
    					[LoginProvider] ASC,
    					[ProviderKey] ASC
    				)
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210311145043_Net5_0_201_IdSrvUpdate'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210311145043_Net5_0_201_IdSrvUpdate', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210315152645_AddUserAndBlob'
)
BEGIN
    CREATE TABLE [mig_portal].[Blob] (
        [Id] int NOT NULL IDENTITY,
        [Encoding] nvarchar(50) NULL,
        [Binary] varbinary(max) NOT NULL,
        [Hash] char(8) NULL,
        [ContentType] nvarchar(50) NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_Blob] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210315152645_AddUserAndBlob'
)
BEGIN
    CREATE TABLE [mig_portal].[User] (
        [Id] int NOT NULL,
        [UserName] nvarchar(50) NOT NULL,
        [DisplayName] nvarchar(50) NOT NULL,
        [Email] nvarchar(50) NULL,
        [AvatarBlobId] int NULL,
        [ProfilePictureBlobId] int NULL,
        [ProfileJson] nvarchar(max) NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_User] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Avatar] FOREIGN KEY ([AvatarBlobId]) REFERENCES [mig_portal].[Blob] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_ProfilePicture] FOREIGN KEY ([ProfilePictureBlobId]) REFERENCES [mig_portal].[Blob] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210315152645_AddUserAndBlob'
)
BEGIN
    CREATE INDEX [IX_User_AvatarBlobId] ON [mig_portal].[User] ([AvatarBlobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210315152645_AddUserAndBlob'
)
BEGIN
    CREATE INDEX [IX_User_ProfilePictureBlobId] ON [mig_portal].[User] ([ProfilePictureBlobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210315152645_AddUserAndBlob'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210315152645_AddUserAndBlob', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210316203707_MakeUserBlobIdsNotNullable'
)
BEGIN
    DROP INDEX [IX_User_ProfilePictureBlobId] ON [mig_portal].[User];
    DECLARE @var4 sysname;
    SELECT @var4 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_portal].[User]') AND [c].[name] = N'ProfilePictureBlobId');
    IF @var4 IS NOT NULL EXEC(N'ALTER TABLE [mig_portal].[User] DROP CONSTRAINT [' + @var4 + '];');
    EXEC(N'UPDATE [mig_portal].[User] SET [ProfilePictureBlobId] = 0 WHERE [ProfilePictureBlobId] IS NULL');
    ALTER TABLE [mig_portal].[User] ALTER COLUMN [ProfilePictureBlobId] int NOT NULL;
    ALTER TABLE [mig_portal].[User] ADD DEFAULT 0 FOR [ProfilePictureBlobId];
    CREATE INDEX [IX_User_ProfilePictureBlobId] ON [mig_portal].[User] ([ProfilePictureBlobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210316203707_MakeUserBlobIdsNotNullable'
)
BEGIN
    DROP INDEX [IX_User_AvatarBlobId] ON [mig_portal].[User];
    DECLARE @var5 sysname;
    SELECT @var5 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_portal].[User]') AND [c].[name] = N'AvatarBlobId');
    IF @var5 IS NOT NULL EXEC(N'ALTER TABLE [mig_portal].[User] DROP CONSTRAINT [' + @var5 + '];');
    EXEC(N'UPDATE [mig_portal].[User] SET [AvatarBlobId] = 0 WHERE [AvatarBlobId] IS NULL');
    ALTER TABLE [mig_portal].[User] ALTER COLUMN [AvatarBlobId] int NOT NULL;
    ALTER TABLE [mig_portal].[User] ADD DEFAULT 0 FOR [AvatarBlobId];
    CREATE INDEX [IX_User_AvatarBlobId] ON [mig_portal].[User] ([AvatarBlobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210316203707_MakeUserBlobIdsNotNullable'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210316203707_MakeUserBlobIdsNotNullable', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210317213648_AddIdentityNavProperties'
)
BEGIN
    ALTER TABLE [mig_portal].[User] ADD CONSTRAINT [FK_User_User_Id] FOREIGN KEY ([Id]) REFERENCES [mig_id].[User] ([Id]) ON DELETE CASCADE;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210317213648_AddIdentityNavProperties'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210317213648_AddIdentityNavProperties', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210324135329_AddProjectState'
)
BEGIN
    ALTER TABLE [mig_portal].[Project] ADD [State] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210324135329_AddProjectState'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210324135329_AddProjectState', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210325164256_AddProjectPartitionLabel'
)
BEGIN
    ALTER TABLE [mig_portal].[Project] ADD [PartitionLabel] nvarchar(50) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210325164256_AddProjectPartitionLabel'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210325164256_AddProjectPartitionLabel', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210411181300_DecoupleUserProfile'
)
BEGIN
    ALTER TABLE [mig_portal].[User] DROP CONSTRAINT [FK_Avatar];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210411181300_DecoupleUserProfile'
)
BEGIN
    ALTER TABLE [mig_portal].[User] DROP CONSTRAINT [FK_ProfilePicture];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210411181300_DecoupleUserProfile'
)
BEGIN
    CREATE TABLE [mig_portal].[UserProfile] (
        [UserName] nvarchar(256) NOT NULL,
        [DisplayName] nvarchar(50) NOT NULL,
        [Email] nvarchar(50) NULL,
        [AvatarBlobId] int NOT NULL,
        [ProfilePictureBlobId] int NOT NULL,
        [ProfileJson] nvarchar(max) NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_UserProfile] PRIMARY KEY ([UserName]),
        CONSTRAINT [FK_Avatar] FOREIGN KEY ([AvatarBlobId]) REFERENCES [mig_portal].[Blob] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_ProfilePicture] FOREIGN KEY ([ProfilePictureBlobId]) REFERENCES [mig_portal].[Blob] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210411181300_DecoupleUserProfile'
)
BEGIN
    insert [mig_portal].[UserProfile] (
    	[UserName]
    ,	[DisplayName]
    ,	[Email]
    ,	[AvatarBlobId]
    ,	[ProfilePictureBlobId]
    ,	[ProfileJson]
    ,	[CreatedBy]
    ,	[CreatedAt]
    ,	[ModifiedBy]
    ,	[ModifiedAt]
    )
    select 
    	[UserName]
    ,	[DisplayName]
    ,	[Email]
    ,	[AvatarBlobId]
    ,	[ProfilePictureBlobId]
    ,	[ProfileJson]
    ,	[CreatedBy]
    ,	[CreatedAt]
    ,	[ModifiedBy]
    ,	[ModifiedAt]
    from [mig_portal].[User]
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210411181300_DecoupleUserProfile'
)
BEGIN
    DROP TABLE [mig_portal].[User];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210411181300_DecoupleUserProfile'
)
BEGIN
    CREATE INDEX [IX_User_UserName] ON [mig_id].[User] ([UserName]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210411181300_DecoupleUserProfile'
)
BEGIN
    CREATE INDEX [IX_UserProfile_AvatarBlobId] ON [mig_portal].[UserProfile] ([AvatarBlobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210411181300_DecoupleUserProfile'
)
BEGIN
    CREATE INDEX [IX_UserProfile_ProfilePictureBlobId] ON [mig_portal].[UserProfile] ([ProfilePictureBlobId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210411181300_DecoupleUserProfile'
)
BEGIN
    ALTER TABLE [mig_id].[User] ADD CONSTRAINT [FK_UserProfile] FOREIGN KEY ([UserName]) REFERENCES [mig_portal].[UserProfile] ([UserName]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210411181300_DecoupleUserProfile'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210411181300_DecoupleUserProfile', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210417142034_RenameUserProfileJson'
)
BEGIN
    EXEC sp_rename N'[mig_portal].[UserProfile].[ProfileJson]', N'SettingsJson', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210417142034_RenameUserProfileJson'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210417142034_RenameUserProfileJson', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210419150017_LanguageRestructure'
)
BEGIN
    EXEC sp_rename N'[mig_portal].[Language].[Supported]', N'IsDefault', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210419150017_LanguageRestructure'
)
BEGIN
    update [mig_portal].[Language]
    set
    	[IsDefault] = case [LanguageCode] when 'en' then 1 else 0 end
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210419150017_LanguageRestructure'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210419150017_LanguageRestructure', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210720120441_RenameMenuTags'
)
BEGIN
    EXEC sp_rename N'[mig_portal].[Project].[Tags]', N'MenuTags', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210720120441_RenameMenuTags'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210720120441_RenameMenuTags', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210723184220_AddTags'
)
BEGIN
    ALTER TABLE [mig_portal].[Partition] DROP CONSTRAINT [FK_Project];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210723184220_AddTags'
)
BEGIN
    CREATE TABLE [mig_portal].[Tag] (
        [Id] int NOT NULL IDENTITY,
        [Value] nvarchar(50) NOT NULL,
        [ProjectID] uniqueidentifier NOT NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_Tag] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Tag_Project] FOREIGN KEY ([ProjectID]) REFERENCES [mig_portal].[Project] ([ProjectID]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210723184220_AddTags'
)
BEGIN
    CREATE TABLE [mig_portal].[TagUsage] (
        [Id] int NOT NULL IDENTITY,
        [TagId] int NOT NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_TagUsage] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_Tag] FOREIGN KEY ([TagId]) REFERENCES [mig_portal].[Tag] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210723184220_AddTags'
)
BEGIN
    CREATE INDEX [IX_Tag_ProjectID] ON [mig_portal].[Tag] ([ProjectID]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210723184220_AddTags'
)
BEGIN
    CREATE INDEX [IX_TagUsage_TagId] ON [mig_portal].[TagUsage] ([TagId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210723184220_AddTags'
)
BEGIN
    ALTER TABLE [mig_portal].[Partition] ADD CONSTRAINT [FK_Partition_Project] FOREIGN KEY ([ProjectID]) REFERENCES [mig_portal].[Project] ([ProjectID]) ON DELETE CASCADE;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210723184220_AddTags'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210723184220_AddTags', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210826205057_AddPortalTeam'
)
BEGIN
    CREATE TABLE [mig_portal].[ProjectTeam] (
        [ProjectID] uniqueidentifier NOT NULL,
        [UserId] int NOT NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_ProjectTeam] PRIMARY KEY ([ProjectID], [UserId]),
        CONSTRAINT [FK_TeamMembers_Project] FOREIGN KEY ([ProjectID]) REFERENCES [mig_portal].[Project] ([ProjectID]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20210826205057_AddPortalTeam'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20210826205057_AddPortalTeam', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20211230222249_AddOrganization'
)
BEGIN
    ALTER TABLE [mig_portal].[UserProfile] ADD [OrganizationId] int NOT NULL DEFAULT 0;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20211230222249_AddOrganization'
)
BEGIN
    CREATE TABLE [mig_portal].[Organization] (
        [Id] int NOT NULL IDENTITY,
        [Name] nvarchar(250) NOT NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_Organization] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20211230222249_AddOrganization'
)
BEGIN
    CREATE INDEX [IX_UserProfile_OrganizationId] ON [mig_portal].[UserProfile] ([OrganizationId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20211230222249_AddOrganization'
)
BEGIN
    SET IDENTITY_INSERT [mig_portal].[Organization] ON 
    INSERT [mig_portal].[Organization] ([Id], [Name], [CreatedBy], [CreatedAt]) values (0, 'None', 'Seed', sysdatetime())
    SET IDENTITY_INSERT [mig_portal].[Organization] OFF 
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20211230222249_AddOrganization'
)
BEGIN
    ALTER TABLE [mig_portal].[UserProfile] ADD CONSTRAINT [FK_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [mig_portal].[Organization] ([Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20211230222249_AddOrganization'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20211230222249_AddOrganization', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220509084701_Attachments'
)
BEGIN
    CREATE TABLE [mig_portal].[Attachment] (
        [Id] uniqueidentifier NOT NULL,
        [UserName] nvarchar(50) NOT NULL,
        [Time] datetime2 NOT NULL,
        [Title] nvarchar(250) NOT NULL,
        [FileName] nvarchar(250) NOT NULL,
        CONSTRAINT [PK_Attachment] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220509084701_Attachments'
)
BEGIN
    CREATE TABLE [mig_portal].[AttachmentContent] (
        [AttachmentId] uniqueidentifier NOT NULL,
        [MediaType] nvarchar(250) NOT NULL,
        [MediaContent] varbinary(max) NOT NULL,
        CONSTRAINT [PK_AttachmentContent] PRIMARY KEY ([AttachmentId]),
        CONSTRAINT [FK_AttachmentContent_Attachment_AttachmentId] FOREIGN KEY ([AttachmentId]) REFERENCES [mig_portal].[Attachment] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220509084701_Attachments'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20220509084701_Attachments', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220623071857_Links'
)
BEGIN
    CREATE TABLE [mig_portal].[LinkableElement] (
        [Id] int NOT NULL IDENTITY,
        [Module] nvarchar(50) NOT NULL,
        [ElementType] nvarchar(50) NOT NULL,
        [SourceId] int NOT NULL,
        [ProjectID] uniqueidentifier NULL,
        [PartitionId] int NULL,
        CONSTRAINT [PK_LinkableElement] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220623071857_Links'
)
BEGIN
    CREATE TABLE [mig_portal].[Link] (
        [Element1Id] int NOT NULL,
        [Element2Id] int NOT NULL,
        [Type] int NOT NULL,
        [Comment] nvarchar(50) NOT NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_Link] PRIMARY KEY ([Element1Id], [Element2Id]),
        CONSTRAINT [FK_Element1] FOREIGN KEY ([Element1Id]) REFERENCES [mig_portal].[LinkableElement] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_Element2] FOREIGN KEY ([Element2Id]) REFERENCES [mig_portal].[LinkableElement] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220623071857_Links'
)
BEGIN
    CREATE INDEX [IX_Link_Element2Id] ON [mig_portal].[Link] ([Element2Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220623071857_Links'
)
BEGIN
    CREATE UNIQUE INDEX [UX_LinkableElement] ON [mig_portal].[LinkableElement] ([Module], [ElementType], [SourceId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220623071857_Links'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20220623071857_Links', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220704110642_LinkLogs'
)
BEGIN
    CREATE TABLE [mig_portal].[LinkLog] (
        [Id] int NOT NULL IDENTITY,
        [Element1Id] int NOT NULL,
        [Element2Id] int NOT NULL,
        [LinkType] int NOT NULL,
        [LogType] int NOT NULL,
        [Time] datetime2 NOT NULL,
        [UserName] nvarchar(50) NOT NULL,
        [ValueBefore] nvarchar(max) NULL,
        [ValueAfter] nvarchar(max) NULL,
        CONSTRAINT [PK_LinkLog] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_LogElement1] FOREIGN KEY ([Element1Id]) REFERENCES [mig_portal].[LinkableElement] ([Id]) ON DELETE NO ACTION,
        CONSTRAINT [FK_LogElement2] FOREIGN KEY ([Element2Id]) REFERENCES [mig_portal].[LinkableElement] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220704110642_LinkLogs'
)
BEGIN
    CREATE INDEX [IX_LinkLog_Element1Id] ON [mig_portal].[LinkLog] ([Element1Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220704110642_LinkLogs'
)
BEGIN
    CREATE INDEX [IX_LinkLog_Element2Id] ON [mig_portal].[LinkLog] ([Element2Id]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220704110642_LinkLogs'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20220704110642_LinkLogs', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220723220544_NullableOrganizationId'
)
BEGIN
    DECLARE @var6 sysname;
    SELECT @var6 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_portal].[UserProfile]') AND [c].[name] = N'OrganizationId');
    IF @var6 IS NOT NULL EXEC(N'ALTER TABLE [mig_portal].[UserProfile] DROP CONSTRAINT [' + @var6 + '];');
    ALTER TABLE [mig_portal].[UserProfile] ALTER COLUMN [OrganizationId] int NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220723220544_NullableOrganizationId'
)
BEGIN
    update [mig_portal].[UserProfile] set [OrganizationId] = null where [OrganizationId] = 0
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220723220544_NullableOrganizationId'
)
BEGIN
    delete [mig_portal].[Organization] where [Id] = 0
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20220723220544_NullableOrganizationId'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20220723220544_NullableOrganizationId', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20221010111103_Subscriptions'
)
BEGIN
    CREATE TABLE [mig_portal].[Subscription] (
        [ElementId] int NOT NULL,
        [UserName] nvarchar(256) NOT NULL,
        [Comment] nvarchar(50) NOT NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_Subscription] PRIMARY KEY ([ElementId], [UserName]),
        CONSTRAINT [FK_SubscribedElement] FOREIGN KEY ([ElementId]) REFERENCES [mig_portal].[LinkableElement] ([Id]) ON DELETE NO ACTION
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20221010111103_Subscriptions'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20221010111103_Subscriptions', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20221111084825_NullableSubscriptionComment'
)
BEGIN
    DECLARE @var7 sysname;
    SELECT @var7 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_portal].[Subscription]') AND [c].[name] = N'Comment');
    IF @var7 IS NOT NULL EXEC(N'ALTER TABLE [mig_portal].[Subscription] DROP CONSTRAINT [' + @var7 + '];');
    ALTER TABLE [mig_portal].[Subscription] ALTER COLUMN [Comment] nvarchar(256) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20221111084825_NullableSubscriptionComment'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20221111084825_NullableSubscriptionComment', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20221114125405_AddMessageNotification'
)
BEGIN
    CREATE TABLE [mig_portal].[Message] (
        [Id] int NOT NULL IDENTITY,
        [Title] nvarchar(256) NOT NULL,
        [Content] nvarchar(max) NOT NULL,
        [TriggeredAt] datetime2 NOT NULL,
        [TriggeredBy] nvarchar(50) NOT NULL,
        CONSTRAINT [PK_Message] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20221114125405_AddMessageNotification'
)
BEGIN
    CREATE TABLE [mig_portal].[MessageNotification] (
        [MessageId] int NOT NULL,
        [UserName] nvarchar(50) NOT NULL,
        [Comment] nvarchar(256) NULL,
        [IsRead] bit NOT NULL DEFAULT CAST(0 AS bit),
        [IsDeleted] bit NOT NULL DEFAULT CAST(0 AS bit),
        CONSTRAINT [PK_MessageNotification] PRIMARY KEY ([MessageId], [UserName]),
        CONSTRAINT [FK_Message] FOREIGN KEY ([MessageId]) REFERENCES [mig_portal].[Message] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20221114125405_AddMessageNotification'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20221114125405_AddMessageNotification', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230121174304_AddErrorLog'
)
BEGIN
    CREATE TABLE [mig_portal].[ErrorLog] (
        [Id] bigint NOT NULL IDENTITY,
        [UserName] nvarchar(50) NOT NULL,
        [TraceId] nvarchar(250) NULL,
        [Title] nvarchar(max) NOT NULL,
        [Message] nvarchar(max) NOT NULL,
        [Time] datetime2 NOT NULL,
        CONSTRAINT [PK_ErrorLog] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230121174304_AddErrorLog'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20230121174304_AddErrorLog', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    DROP TABLE [mig_id].[DeviceCode];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    DROP TABLE [mig_id].[PersistedGrant];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    IF SCHEMA_ID(N'mig_openiddict') IS NULL EXEC(N'CREATE SCHEMA [mig_openiddict];');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    DECLARE @var8 sysname;
    SELECT @var8 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_id].[UserToken]') AND [c].[name] = N'Name');
    IF @var8 IS NOT NULL EXEC(N'ALTER TABLE [mig_id].[UserToken] DROP CONSTRAINT [' + @var8 + '];');
    ALTER TABLE [mig_id].[UserToken] ALTER COLUMN [Name] nvarchar(450) NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    DECLARE @var9 sysname;
    SELECT @var9 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_id].[UserToken]') AND [c].[name] = N'LoginProvider');
    IF @var9 IS NOT NULL EXEC(N'ALTER TABLE [mig_id].[UserToken] DROP CONSTRAINT [' + @var9 + '];');
    ALTER TABLE [mig_id].[UserToken] ALTER COLUMN [LoginProvider] nvarchar(450) NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    DECLARE @var10 sysname;
    SELECT @var10 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_id].[UserLogin]') AND [c].[name] = N'ProviderKey');
    IF @var10 IS NOT NULL EXEC(N'ALTER TABLE [mig_id].[UserLogin] DROP CONSTRAINT [' + @var10 + '];');
    ALTER TABLE [mig_id].[UserLogin] ALTER COLUMN [ProviderKey] nvarchar(450) NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    DECLARE @var11 sysname;
    SELECT @var11 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_id].[UserLogin]') AND [c].[name] = N'LoginProvider');
    IF @var11 IS NOT NULL EXEC(N'ALTER TABLE [mig_id].[UserLogin] DROP CONSTRAINT [' + @var11 + '];');
    ALTER TABLE [mig_id].[UserLogin] ALTER COLUMN [LoginProvider] nvarchar(450) NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    CREATE TABLE [mig_openiddict].[OpenIddictApplications] (
        [Id] nvarchar(450) NOT NULL,
        [ClientId] nvarchar(100) NULL,
        [ClientSecret] nvarchar(max) NULL,
        [ConcurrencyToken] nvarchar(50) NULL,
        [ConsentType] nvarchar(50) NULL,
        [DisplayName] nvarchar(max) NULL,
        [DisplayNames] nvarchar(max) NULL,
        [Permissions] nvarchar(max) NULL,
        [PostLogoutRedirectUris] nvarchar(max) NULL,
        [Properties] nvarchar(max) NULL,
        [RedirectUris] nvarchar(max) NULL,
        [Requirements] nvarchar(max) NULL,
        [Type] nvarchar(50) NULL,
        CONSTRAINT [PK_OpenIddictApplications] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    CREATE TABLE [mig_openiddict].[OpenIddictScopes] (
        [Id] nvarchar(450) NOT NULL,
        [ConcurrencyToken] nvarchar(50) NULL,
        [Description] nvarchar(max) NULL,
        [Descriptions] nvarchar(max) NULL,
        [DisplayName] nvarchar(max) NULL,
        [DisplayNames] nvarchar(max) NULL,
        [Name] nvarchar(200) NULL,
        [Properties] nvarchar(max) NULL,
        [Resources] nvarchar(max) NULL,
        CONSTRAINT [PK_OpenIddictScopes] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    CREATE TABLE [mig_openiddict].[OpenIddictAuthorizations] (
        [Id] nvarchar(450) NOT NULL,
        [ApplicationId] nvarchar(450) NULL,
        [ConcurrencyToken] nvarchar(50) NULL,
        [CreationDate] datetime2 NULL,
        [Properties] nvarchar(max) NULL,
        [Scopes] nvarchar(max) NULL,
        [Status] nvarchar(50) NULL,
        [Subject] nvarchar(400) NULL,
        [Type] nvarchar(50) NULL,
        CONSTRAINT [PK_OpenIddictAuthorizations] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_OpenIddictAuthorizations_OpenIddictApplications_ApplicationId] FOREIGN KEY ([ApplicationId]) REFERENCES [mig_openiddict].[OpenIddictApplications] ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    CREATE TABLE [mig_openiddict].[OpenIddictTokens] (
        [Id] nvarchar(450) NOT NULL,
        [ApplicationId] nvarchar(450) NULL,
        [AuthorizationId] nvarchar(450) NULL,
        [ConcurrencyToken] nvarchar(50) NULL,
        [CreationDate] datetime2 NULL,
        [ExpirationDate] datetime2 NULL,
        [Payload] nvarchar(max) NULL,
        [Properties] nvarchar(max) NULL,
        [RedemptionDate] datetime2 NULL,
        [ReferenceId] nvarchar(100) NULL,
        [Status] nvarchar(50) NULL,
        [Subject] nvarchar(400) NULL,
        [Type] nvarchar(50) NULL,
        CONSTRAINT [PK_OpenIddictTokens] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_OpenIddictTokens_OpenIddictApplications_ApplicationId] FOREIGN KEY ([ApplicationId]) REFERENCES [mig_openiddict].[OpenIddictApplications] ([Id]),
        CONSTRAINT [FK_OpenIddictTokens_OpenIddictAuthorizations_AuthorizationId] FOREIGN KEY ([AuthorizationId]) REFERENCES [mig_openiddict].[OpenIddictAuthorizations] ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [IX_OpenIddictApplications_ClientId] ON [mig_openiddict].[OpenIddictApplications] ([ClientId]) WHERE [ClientId] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    CREATE INDEX [IX_OpenIddictAuthorizations_ApplicationId_Status_Subject_Type] ON [mig_openiddict].[OpenIddictAuthorizations] ([ApplicationId], [Status], [Subject], [Type]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [IX_OpenIddictScopes_Name] ON [mig_openiddict].[OpenIddictScopes] ([Name]) WHERE [Name] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    CREATE INDEX [IX_OpenIddictTokens_ApplicationId_Status_Subject_Type] ON [mig_openiddict].[OpenIddictTokens] ([ApplicationId], [Status], [Subject], [Type]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    CREATE INDEX [IX_OpenIddictTokens_AuthorizationId] ON [mig_openiddict].[OpenIddictTokens] ([AuthorizationId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [IX_OpenIddictTokens_ReferenceId] ON [mig_openiddict].[OpenIddictTokens] ([ReferenceId]) WHERE [ReferenceId] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230707192016_Openiddict'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20230707192016_Openiddict', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230911153131_UpdateBlobColorToNewDesign'
)
BEGIN
    UPDATE [mig_portal].[Blob]
    	SET
    		[Binary] = CAST(REPLACE(REPLACE(CAST([Binary] AS VARCHAR(MAX)) COLLATE SQL_Latin1_General_CP1_CI_AS, 'fill="#18648B"', 'fill="#B3ACA6"') COLLATE SQL_Latin1_General_CP1_CI_AS, 'fill: white', 'fill: #00463A') AS VARBINARY(MAX)),
    		[Hash] = LOWER(SUBSTRING(CONVERT(varchar(36), NEWID()), 1, 8))
    	WHERE
    		[ContentType] = 'image/svg+xml'
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230911153131_UpdateBlobColorToNewDesign'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20230911153131_UpdateBlobColorToNewDesign', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230928145516_AdjustColorsOnGeneratedBlobs'
)
BEGIN
    UPDATE [mig_portal].[Blob]
    	SET
    		[Binary] = CAST(
    			REPLACE(
    				REPLACE(
    					CAST([Binary] AS VARCHAR(MAX)) 
    					COLLATE SQL_Latin1_General_CP1_CI_AS, 
    					'fill="#B3ACA6"', 
    					'fill="#CFC9C4"'
    				) 
    				COLLATE SQL_Latin1_General_CP1_CI_AS, 
    				'"fill: #00463A; font-family: sans-serif; font-size:2em"', 
    				'"fill: #00463A; font-family: sans-serif; font-size: 2.5em; font-weight: 600;"'
    			) AS VARBINARY(MAX)),
    		[Hash] = LOWER(SUBSTRING(CONVERT(varchar(36), NEWID()), 1, 8))
    	WHERE
    		[ContentType] = 'image/svg+xml'
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20230928145516_AdjustColorsOnGeneratedBlobs'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20230928145516_AdjustColorsOnGeneratedBlobs', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100817_DashboardsInitial'
)
BEGIN
    CREATE TABLE [mig_portal].[Dashboard] (
        [Id] int NOT NULL IDENTITY,
        [ProjectID] uniqueidentifier NULL,
        [Title] nvarchar(200) NOT NULL,
        [Columns] int NOT NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_Dashboard] PRIMARY KEY ([Id])
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100817_DashboardsInitial'
)
BEGIN
    CREATE TABLE [mig_portal].[DashboardPanel] (
        [Id] int NOT NULL IDENTITY,
        [DashboardId] int NOT NULL,
        [Title] nvarchar(200) NOT NULL,
        [WidgetIdentifier] uniqueidentifier NULL,
        [Row] int NOT NULL,
        [Column] int NOT NULL,
        [SizeX] int NOT NULL,
        [SizeY] int NOT NULL,
        [CreatedBy] nvarchar(50) NOT NULL,
        [CreatedAt] datetime2 NOT NULL,
        [ModifiedBy] nvarchar(50) NULL,
        [ModifiedAt] datetime2 NULL,
        [RowVersion] rowversion NOT NULL,
        CONSTRAINT [PK_DashboardPanel] PRIMARY KEY ([Id]),
        CONSTRAINT [FK_DashboardPanel_Dashboard_DashboardId] FOREIGN KEY ([DashboardId]) REFERENCES [mig_portal].[Dashboard] ([Id]) ON DELETE CASCADE
    );
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100817_DashboardsInitial'
)
BEGIN
    EXEC(N'CREATE UNIQUE INDEX [UX_ProjectDashboard] ON [mig_portal].[Dashboard] ([ProjectID], [Title]) WHERE [ProjectID] IS NOT NULL');
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100817_DashboardsInitial'
)
BEGIN
    CREATE INDEX [IX_DashboardPanel_DashboardId] ON [mig_portal].[DashboardPanel] ([DashboardId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100817_DashboardsInitial'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20240123100817_DashboardsInitial', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100917_DashboardsSeedDefault'
)
BEGIN
    SET IDENTITY_INSERT mig_portal.Dashboard ON
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100917_DashboardsSeedDefault'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Id', N'Title', N'Columns', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[Dashboard]'))
        SET IDENTITY_INSERT [mig_portal].[Dashboard] ON;
    EXEC(N'INSERT INTO [mig_portal].[Dashboard] ([Id], [Title], [Columns], [CreatedBy], [CreatedAt])
    VALUES (-1, N''Home Dashboard'', 8, N'''', ''2024-04-22T19:05:26.5008178Z'')');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Id', N'Title', N'Columns', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[Dashboard]'))
        SET IDENTITY_INSERT [mig_portal].[Dashboard] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100917_DashboardsSeedDefault'
)
BEGIN
    SET IDENTITY_INSERT mig_portal.Dashboard OFF
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100917_DashboardsSeedDefault'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] ON;
    EXEC(N'INSERT INTO [mig_portal].[DashboardPanel] ([DashboardId], [Title], [Row], [Column], [SizeX], [SizeY], [WidgetIdentifier], [CreatedBy], [CreatedAt])
    VALUES (-1, N''Timelines'', 2, 0, 6, 2, ''e69e912c-75d9-4f11-88ca-438f0cc4219a'', N'''', ''2024-04-22T19:05:26.5016783Z'')');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100917_DashboardsSeedDefault'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] ON;
    EXEC(N'INSERT INTO [mig_portal].[DashboardPanel] ([DashboardId], [Title], [Row], [Column], [SizeX], [SizeY], [WidgetIdentifier], [CreatedBy], [CreatedAt])
    VALUES (-1, N''Items'', 2, 6, 2, 2, ''c0283750-ee7f-4809-a0ac-9de5344070bd'', N'''', ''2024-04-22T19:05:26.5016812Z'')');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100917_DashboardsSeedDefault'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] ON;
    EXEC(N'INSERT INTO [mig_portal].[DashboardPanel] ([DashboardId], [Title], [Row], [Column], [SizeX], [SizeY], [WidgetIdentifier], [CreatedBy], [CreatedAt])
    VALUES (-1, N''Statistic Chart'', 0, 0, 4, 2, ''ff48dbea-f306-4307-849a-ba605eb1cb81'', N'''', ''2024-04-22T19:05:26.5016840Z'')');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100917_DashboardsSeedDefault'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] ON;
    EXEC(N'INSERT INTO [mig_portal].[DashboardPanel] ([DashboardId], [Title], [Row], [Column], [SizeX], [SizeY], [WidgetIdentifier], [CreatedBy], [CreatedAt])
    VALUES (-1, N''Impact Chart'', 0, 4, 4, 2, ''9f35c7fa-14b6-4239-b0f3-89eb013582c9'', N'''', ''2024-04-22T19:05:26.5016854Z'')');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240123100917_DashboardsSeedDefault'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20240123100917_DashboardsSeedDefault', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240131103049_OpeniddictUpdateNet8'
)
BEGIN
    EXEC sp_rename N'[mig_openiddict].[OpenIddictApplications].[Type]', N'ClientType', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240131103049_OpeniddictUpdateNet8'
)
BEGIN
    ALTER TABLE [mig_openiddict].[OpenIddictApplications] ADD [ApplicationType] nvarchar(50) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240131103049_OpeniddictUpdateNet8'
)
BEGIN
    ALTER TABLE [mig_openiddict].[OpenIddictApplications] ADD [JsonWebKeySet] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240131103049_OpeniddictUpdateNet8'
)
BEGIN
    ALTER TABLE [mig_openiddict].[OpenIddictApplications] ADD [Settings] nvarchar(max) NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240131103049_OpeniddictUpdateNet8'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20240131103049_OpeniddictUpdateNet8', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240306140949_LinkableElementInternalIdString'
)
BEGIN
    DROP INDEX [UX_LinkableElement] ON [mig_portal].[LinkableElement];
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240306140949_LinkableElementInternalIdString'
)
BEGIN
    DECLARE @var12 sysname;
    SELECT @var12 = [d].[name]
    FROM [sys].[default_constraints] [d]
    INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
    WHERE ([d].[parent_object_id] = OBJECT_ID(N'[mig_portal].[LinkableElement]') AND [c].[name] = N'SourceId');
    IF @var12 IS NOT NULL EXEC(N'ALTER TABLE [mig_portal].[LinkableElement] DROP CONSTRAINT [' + @var12 + '];');
    ALTER TABLE [mig_portal].[LinkableElement] ALTER COLUMN [SourceId] nvarchar(200) NOT NULL;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240306140949_LinkableElementInternalIdString'
)
BEGIN
    EXEC sp_rename N'[mig_portal].[LinkableElement].[SourceId]', N'InternalId', N'COLUMN';
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240306140949_LinkableElementInternalIdString'
)
BEGIN
    CREATE UNIQUE INDEX [UX_LinkableElement] ON [mig_portal].[LinkableElement] ([Module], [ElementType], [InternalId]);
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240306140949_LinkableElementInternalIdString'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20240306140949_LinkableElementInternalIdString', N'8.0.2');
END;
GO

COMMIT;
GO

BEGIN TRANSACTION;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240322190315_DefaultDashboardWithJobsAndNotifications'
)
BEGIN
    TRUNCATE TABLE [mig_portal].[DashboardPanel]
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240322190315_DefaultDashboardWithJobsAndNotifications'
)
BEGIN
    DELETE FROM [mig_portal].[Dashboard]
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240322190315_DefaultDashboardWithJobsAndNotifications'
)
BEGIN
    SET IDENTITY_INSERT mig_portal.Dashboard ON
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240322190315_DefaultDashboardWithJobsAndNotifications'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Id', N'Title', N'Columns', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[Dashboard]'))
        SET IDENTITY_INSERT [mig_portal].[Dashboard] ON;
    EXEC(N'INSERT INTO [mig_portal].[Dashboard] ([Id], [Title], [Columns], [CreatedBy], [CreatedAt])
    VALUES (-1, N''Home Dashboard'', 8, N'''', ''2024-04-22T19:05:26.6773781+00:00'')');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Id', N'Title', N'Columns', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[Dashboard]'))
        SET IDENTITY_INSERT [mig_portal].[Dashboard] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240322190315_DefaultDashboardWithJobsAndNotifications'
)
BEGIN
    SET IDENTITY_INSERT mig_portal.Dashboard OFF
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240322190315_DefaultDashboardWithJobsAndNotifications'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] ON;
    EXEC(N'INSERT INTO [mig_portal].[DashboardPanel] ([DashboardId], [Title], [Row], [Column], [SizeX], [SizeY], [WidgetIdentifier], [CreatedBy], [CreatedAt])
    VALUES (-1, N''Notifications'', 2, 0, 4, 2, ''8676f2ce-647a-4097-bb11-a934156e180f'', N'''', ''2024-04-22T19:05:26.6785122+00:00'')');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240322190315_DefaultDashboardWithJobsAndNotifications'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] ON;
    EXEC(N'INSERT INTO [mig_portal].[DashboardPanel] ([DashboardId], [Title], [Row], [Column], [SizeX], [SizeY], [WidgetIdentifier], [CreatedBy], [CreatedAt])
    VALUES (-1, N''Jobs'', 2, 4, 4, 2, ''0466ea83-d4d0-403c-a1a9-12b1550fa755'', N'''', ''2024-04-22T19:05:26.6785149+00:00'')');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240322190315_DefaultDashboardWithJobsAndNotifications'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] ON;
    EXEC(N'INSERT INTO [mig_portal].[DashboardPanel] ([DashboardId], [Title], [Row], [Column], [SizeX], [SizeY], [WidgetIdentifier], [CreatedBy], [CreatedAt])
    VALUES (-1, N''Statistic Chart'', 0, 0, 4, 2, ''ff48dbea-f306-4307-849a-ba605eb1cb81'', N'''', ''2024-04-22T19:05:26.6785159+00:00'')');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240322190315_DefaultDashboardWithJobsAndNotifications'
)
BEGIN
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] ON;
    EXEC(N'INSERT INTO [mig_portal].[DashboardPanel] ([DashboardId], [Title], [Row], [Column], [SizeX], [SizeY], [WidgetIdentifier], [CreatedBy], [CreatedAt])
    VALUES (-1, N''Impact Chart'', 0, 4, 4, 2, ''9f35c7fa-14b6-4239-b0f3-89eb013582c9'', N'''', ''2024-04-22T19:05:26.6785194+00:00'')');
    IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'DashboardId', N'Title', N'Row', N'Column', N'SizeX', N'SizeY', N'WidgetIdentifier', N'CreatedBy', N'CreatedAt') AND [object_id] = OBJECT_ID(N'[mig_portal].[DashboardPanel]'))
        SET IDENTITY_INSERT [mig_portal].[DashboardPanel] OFF;
END;
GO

IF NOT EXISTS (
    SELECT * FROM [__EFMigrationsHistory]
    WHERE [MigrationId] = N'20240322190315_DefaultDashboardWithJobsAndNotifications'
)
BEGIN
    INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
    VALUES (N'20240322190315_DefaultDashboardWithJobsAndNotifications', N'8.0.2');
END;
GO

COMMIT;
GO

