text: ﻿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
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20200909112636_CreateTodoItem')
  BEGIN
      CREATE TABLE [TodoItems] (
          [Id] bigint NOT NULL IDENTITY,
          [Name] nvarchar(max) NULL,
          [IsCompleted] bit NOT NULL,
          CONSTRAINT [PK_TodoItems] PRIMARY KEY ([Id])
      );
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20200909112636_CreateTodoItem')
  BEGIN
      INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
      VALUES (N'20200909112636_CreateTodoItem', N'3.1.8');
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20200912110359_AddTimeStamp')
  BEGIN
      ALTER TABLE [TodoItems] ADD [RowVersion] rowversion NULL;
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20200912110359_AddTimeStamp')
  BEGIN
      INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
      VALUES (N'20200912110359_AddTimeStamp', N'3.1.8');
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201001015112_AddCategory')
  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'[TodoItems]') AND [c].[name] = N'Name');
      IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [TodoItems] DROP CONSTRAINT [' + @var0 + '];');
      ALTER TABLE [TodoItems] ALTER COLUMN [Name] nvarchar(max) NOT NULL;
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201001015112_AddCategory')
  BEGIN
      CREATE TABLE [Categories] (
          [Id] bigint NOT NULL IDENTITY,
          [Name] nvarchar(max) NOT NULL,
          [RowVersion] rowversion NULL,
          CONSTRAINT [PK_Categories] PRIMARY KEY ([Id])
      );
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201001015112_AddCategory')
  BEGIN
      INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
      VALUES (N'20201001015112_AddCategory', N'3.1.8');
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201001015409_AddCategoryIdToTodoItem')
  BEGIN
      ALTER TABLE [TodoItems] ADD [CategoryId] bigint NOT NULL DEFAULT CAST(0 AS bigint);
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201001015409_AddCategoryIdToTodoItem')
  BEGIN
      INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
      VALUES (N'20201001015409_AddCategoryIdToTodoItem', N'3.1.8');
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201002072640_AddUserModel')
  BEGIN
      CREATE TABLE [Users] (
          [Id] int NOT NULL IDENTITY,
          [FirstName] nvarchar(max) NULL,
          [LastName] nvarchar(max) NULL,
          [Username] nvarchar(max) NULL,
          [PasswordHash] varbinary(max) NULL,
          [PasswordSalt] varbinary(max) NULL,
          CONSTRAINT [PK_Users] PRIMARY KEY ([Id])
      );
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201002072640_AddUserModel')
  BEGIN
      INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
      VALUES (N'20201002072640_AddUserModel', N'3.1.8');
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201003023340_UpdateCategoryAndTodoItem')
  BEGIN
      ALTER TABLE [TodoItems] ADD [CreatedAt] datetime2 NOT NULL DEFAULT '0001-01-01T00:00:00.0000000';
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201003023340_UpdateCategoryAndTodoItem')
  BEGIN
      ALTER TABLE [TodoItems] ADD [UpdatedAt] datetime2 NOT NULL DEFAULT '0001-01-01T00:00:00.0000000';
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201003023340_UpdateCategoryAndTodoItem')
  BEGIN
      ALTER TABLE [Categories] ADD [BgColor] nvarchar(max) NULL;
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201003023340_UpdateCategoryAndTodoItem')
  BEGIN
      ALTER TABLE [Categories] ADD [CreatedAt] datetime2 NOT NULL DEFAULT '0001-01-01T00:00:00.0000000';
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201003023340_UpdateCategoryAndTodoItem')
  BEGIN
      ALTER TABLE [Categories] ADD [UpdatedAt] datetime2 NOT NULL DEFAULT '0001-01-01T00:00:00.0000000';
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201003023340_UpdateCategoryAndTodoItem')
  BEGIN
      ALTER TABLE [Categories] ADD [UserId] int NOT NULL DEFAULT 0;
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201003023340_UpdateCategoryAndTodoItem')
  BEGIN
      INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
      VALUES (N'20201003023340_UpdateCategoryAndTodoItem', N'3.1.8');
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201005094628_AddFlowAndUpdate')
  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'[TodoItems]') AND [c].[name] = N'CategoryId');
      IF @var1 IS NOT NULL EXEC(N'ALTER TABLE [TodoItems] DROP CONSTRAINT [' + @var1 + '];');
      ALTER TABLE [TodoItems] DROP COLUMN [CategoryId];
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201005094628_AddFlowAndUpdate')
  BEGIN
      ALTER TABLE [TodoItems] ADD [FlowId] bigint NOT NULL DEFAULT CAST(0 AS bigint);
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201005094628_AddFlowAndUpdate')
  BEGIN
      ALTER TABLE [TodoItems] ADD [Pos] bigint NOT NULL DEFAULT CAST(65536 AS bigint);
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201005094628_AddFlowAndUpdate')
  BEGIN
      CREATE TABLE [Flows] (
          [Id] bigint NOT NULL IDENTITY,
          [Name] nvarchar(max) NOT NULL,
          [Pos] bigint NOT NULL DEFAULT CAST(65536 AS bigint),
          [CreatedAt] datetime2 NOT NULL,
          [UpdatedAt] datetime2 NOT NULL,
          [RowVersion] rowversion NULL,
          [CategoryId] bigint NOT NULL,
          CONSTRAINT [PK_Flows] PRIMARY KEY ([Id])
      );
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201005094628_AddFlowAndUpdate')
  BEGIN
      INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
      VALUES (N'20201005094628_AddFlowAndUpdate', N'3.1.8');
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201008065355_AddDescriptionToTodoItem')
  BEGIN
      ALTER TABLE [TodoItems] ADD [Description] nvarchar(max) NULL;
  END;
  
  GO
  
  IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20201008065355_AddDescriptionToTodoItem')
  BEGIN
      INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
      VALUES (N'20201008065355_AddDescriptionToTodoItem', N'3.1.8');
  END;
  
  GO
  
  