using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; namespace app.Data.Migrations { public partial class _2021_03_10 : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "AuthUsers", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), FirstName = table.Column(nullable: true), LastName = table.Column(nullable: true), EMail = table.Column(nullable: true), Password = table.Column(nullable: true), RefreshToken = table.Column(nullable: true), ConfirmationId = table.Column(nullable: true), ForgotPasswordId = table.Column(nullable: true), RefreshTokenExpiryTime = table.Column(nullable: false), CreatedOn = table.Column(nullable: false), LastModifiedOn = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_AuthUsers", x => x.Id); }); migrationBuilder.CreateTable( name: "Domains", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: true), NotifyWhenLogin = table.Column(nullable: false), CreatedOn = table.Column(nullable: false), LastModifiedOn = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Domains", x => x.Id); }); migrationBuilder.CreateTable( name: "OperatingSystems", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: true), CreatedOn = table.Column(nullable: false), LastModifiedOn = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_OperatingSystems", x => x.Id); }); migrationBuilder.CreateTable( name: "Hosts", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: true), IPAddress = table.Column(maxLength: 1400, nullable: true), NotifyWhenLogin = table.Column(nullable: false), DomainId = table.Column(nullable: true), OSId = table.Column(nullable: false), CreatedOn = table.Column(nullable: false), LastModifiedOn = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Hosts", x => x.Id); table.ForeignKey( name: "FK_Hosts_Domains_DomainId", column: x => x.DomainId, principalTable: "Domains", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Hosts_OperatingSystems_OSId", column: x => x.OSId, principalTable: "OperatingSystems", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: true), NotifyWhenLogin = table.Column(nullable: false), CreatedOn = table.Column(nullable: false), LastModifiedOn = table.Column(nullable: false), Discriminator = table.Column(nullable: false), DomainId = table.Column(nullable: true), HostId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); table.ForeignKey( name: "FK_Users_Domains_DomainId", column: x => x.DomainId, principalTable: "Domains", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Users_Hosts_HostId", column: x => x.HostId, principalTable: "Hosts", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Logins", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Time = table.Column(nullable: false), HostId = table.Column(nullable: false), UserId = table.Column(nullable: false), CreatedOn = table.Column(nullable: false), LastModifiedOn = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Logins", x => x.Id); table.ForeignKey( name: "FK_Logins_Hosts_HostId", column: x => x.HostId, principalTable: "Hosts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Logins_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_AuthUsers_ConfirmationId", table: "AuthUsers", column: "ConfirmationId", unique: true); migrationBuilder.CreateIndex( name: "IX_AuthUsers_EMail", table: "AuthUsers", column: "EMail", unique: true); migrationBuilder.CreateIndex( name: "IX_AuthUsers_ForgotPasswordId", table: "AuthUsers", column: "ForgotPasswordId", unique: true); migrationBuilder.CreateIndex( name: "IX_Hosts_DomainId", table: "Hosts", column: "DomainId"); migrationBuilder.CreateIndex( name: "IX_Hosts_OSId", table: "Hosts", column: "OSId"); migrationBuilder.CreateIndex( name: "IX_Hosts_DomainId_Name", table: "Hosts", columns: new[] { "DomainId", "Name" }, unique: true); migrationBuilder.CreateIndex( name: "IX_Hosts_IPAddress_Name", table: "Hosts", columns: new[] { "IPAddress", "Name" }, unique: true); migrationBuilder.CreateIndex( name: "IX_Logins_HostId", table: "Logins", column: "HostId"); migrationBuilder.CreateIndex( name: "IX_Logins_UserId", table: "Logins", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_OperatingSystems_Name", table: "OperatingSystems", column: "Name", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_DomainId", table: "Users", column: "DomainId"); migrationBuilder.CreateIndex( name: "IX_Users_HostId", table: "Users", column: "HostId"); migrationBuilder.CreateIndex( name: "IX_Users_Discriminator_Name", table: "Users", columns: new[] { "Discriminator", "Name" }, unique: true); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "AuthUsers"); migrationBuilder.DropTable( name: "Logins"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Hosts"); migrationBuilder.DropTable( name: "Domains"); migrationBuilder.DropTable( name: "OperatingSystems"); } } }