text: -------------------- SCRIPT TO CHECK OF DbScriptMigrationSystem -------------------------------
  DECLARE @MigrationName AS VARCHAR(1000) = '002_create_user_and_entities_table'
  
  IF EXISTS(SELECT MigrationId FROM [DbScriptMigration] WHERE MigrationName = @MigrationName)
  BEGIN 
      raiserror('MIGRATION ALREADY RUNNED ON THIS DB!!! STOP EXECUTION SCRIPT', 11, 0)
      SET NOEXEC ON
  END
  
  INSERT INTO [DbScriptMigration]
      (MigrationId, MigrationName, MigrationDate)
      VALUES
      (NEWID(), @MigrationName, GETDATE())
  GO
  PRINT 'Insert record into [DbScriptMigration]!'
  -------------------- END SCRIPT TO CHECK OF DbScriptMigrationSystem ---------------------------
  
  -------------------- SCRIPT TO CHECK PREREQUISITES OF DbScriptMigrationSystem -------------------------------
  DECLARE @PrerequisiteMigrationName AS VARCHAR(1000) = '001_create_table_auth'
  IF NOT EXISTS(SELECT MigrationId FROM [DbScriptMigration] WHERE MigrationName = @PrerequisiteMigrationName)
  BEGIN 
      raiserror('YOU HAVET TO RUN SCRIPT %s ON THIS DB!!! STOP EXECUTION SCRIPT ', 11, 0, @PrerequisiteMigrationName)
      SET NOEXEC ON
  END
  -------------------- END SCRIPT TO CHECK PREREQUISITES OF DbScriptMigrationSystem ---------------------------
  
  -- CREATE TABLE Users
  CREATE TABLE [dbo].[Users](
  	[Id] [int] IDENTITY(1,1) NOT NULL,
  	[Username] [nvarchar](50) NOT NULL,
  	[Name] [nvarchar](100) NULL,
  	[Surname] [nvarchar](100) NULL,
  	[TypeId] [int] NOT NULL,
  	[Title] [nvarchar](100) NOT NULL,
  	[Description] [nvarchar](250) NULL,
  	[Properties] [nvarchar](2000) NULL,
  	[CreateDate] [datetime] NOT NULL,
  	[LastAccess] [datetime] NULL,
   CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
  (
  	[Id] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
  ) ON [PRIMARY]
  GO
  
  -- CREATE TABLE EntityTypes
  CREATE TABLE [dbo].[EntityTypes](
  	[Id] [int] IDENTITY(1,1) NOT NULL,
  	[Name] [nvarchar](100) NOT NULL,
  	[Description] [nvarchar](250) NULL,
   CONSTRAINT [PK_EntityTypes] PRIMARY KEY CLUSTERED 
  (
  	[Id] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
  ) ON [PRIMARY]
  GO
  
  -- CREATE TABLE Entities
  CREATE TABLE [dbo].[Entities](
  	[Id] [int] IDENTITY(1,1) NOT NULL,
  	[TypeId] [int] NOT NULL,
  	[Title] [nvarchar](100) NOT NULL,
  	[Description] [nvarchar](250) NULL,
  	[Properties] [nvarchar](2000) NULL,
  	[CreateDate] [datetime] NOT NULL,
   CONSTRAINT [PK_Entities] PRIMARY KEY CLUSTERED 
  (
  	[Id] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
  ) ON [PRIMARY]
  GO
  
  ALTER TABLE [dbo].[Entities]  WITH CHECK ADD  CONSTRAINT [FK_Entities_EntityTypes] FOREIGN KEY([TypeId])
  REFERENCES [dbo].[EntityTypes] ([Id])
  GO
  
  ALTER TABLE [dbo].[Entities] CHECK CONSTRAINT [FK_Entities_EntityTypes]
  GO
  
  -- CREATE TABLE UserAccounts
  CREATE TABLE [dbo].[UserAccounts](
  	[UserId] [int] NOT NULL,
  	[AccountId] [int] NOT NULL,
   CONSTRAINT [PK_UserAccounts] PRIMARY KEY CLUSTERED 
  (
  	[UserId] ASC,
  	[AccountId] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
  ) ON [PRIMARY]
  GO
  
  ALTER TABLE [dbo].[UserAccounts]  WITH CHECK ADD  CONSTRAINT [FK_UserAccounts_Users] FOREIGN KEY([UserId])
  REFERENCES [dbo].[Users] ([Id])
  GO
  
  ALTER TABLE [dbo].[UserAccounts] CHECK CONSTRAINT [FK_UserAccounts_Users]
  GO
  
  ALTER TABLE [dbo].[UserAccounts]  WITH CHECK ADD  CONSTRAINT [FK_UserAccounts_Accounts] FOREIGN KEY([AccountId])
  REFERENCES [dbo].[Accounts] ([Id])
  GO
  
  ALTER TABLE [dbo].[UserAccounts] CHECK CONSTRAINT [FK_UserAccounts_Accounts]
  GO
  
  
  -- CREATE TABLE UserEntities
  CREATE TABLE [dbo].[UserEntities](
  	[UserId] [int] NOT NULL,
  	[EntityId] [int] NOT NULL,
      [IsOwner] [bit] NOT NULL,
  	[CreateDate] [datetime] NOT NULL,
   CONSTRAINT [PK_UserEntities] PRIMARY KEY CLUSTERED 
  (
  	[UserId] ASC,
  	[EntityId] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
  ) ON [PRIMARY]
  GO
  
  ALTER TABLE [dbo].[UserEntities]  WITH CHECK ADD  CONSTRAINT [FK_UserEntities_Users] FOREIGN KEY([UserId])
  REFERENCES [dbo].[Users] ([Id])
  GO
  
  ALTER TABLE [dbo].[UserEntities] CHECK CONSTRAINT [FK_UserEntities_Users]
  GO
  
  ALTER TABLE [dbo].[UserEntities]  WITH CHECK ADD  CONSTRAINT [FK_UserEntities_Entities] FOREIGN KEY([EntityId])
  REFERENCES [dbo].[Entities] ([Id])
  GO
  
  ALTER TABLE [dbo].[UserEntities] CHECK CONSTRAINT [FK_UserEntities_Entities]
  GO
  
  
  ---------------- FOOTER OF DbScriptMigrationSystem : REMEMBER TO INSERT -----------------------
  SET NOEXEC OFF