web-app-template/backend/app/app.Data/Migrations/20210213133159_2021_03_10.cs
2022-02-20 13:57:55 +01:00

250 lines
10 KiB
C#

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<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
FirstName = table.Column<string>(nullable: true),
LastName = table.Column<string>(nullable: true),
EMail = table.Column<string>(nullable: true),
Password = table.Column<string>(nullable: true),
RefreshToken = table.Column<string>(nullable: true),
ConfirmationId = table.Column<string>(nullable: true),
ForgotPasswordId = table.Column<string>(nullable: true),
RefreshTokenExpiryTime = table.Column<DateTime>(nullable: false),
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
LastModifiedOn = table.Column<DateTimeOffset>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AuthUsers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Domains",
columns: table => new
{
Id = table.Column<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(nullable: true),
NotifyWhenLogin = table.Column<bool>(nullable: false),
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
LastModifiedOn = table.Column<DateTimeOffset>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Domains", x => x.Id);
});
migrationBuilder.CreateTable(
name: "OperatingSystems",
columns: table => new
{
Id = table.Column<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(nullable: true),
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
LastModifiedOn = table.Column<DateTimeOffset>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_OperatingSystems", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Hosts",
columns: table => new
{
Id = table.Column<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(nullable: true),
IPAddress = table.Column<byte[]>(maxLength: 1400, nullable: true),
NotifyWhenLogin = table.Column<bool>(nullable: false),
DomainId = table.Column<long>(nullable: true),
OSId = table.Column<long>(nullable: false),
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
LastModifiedOn = table.Column<DateTimeOffset>(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<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(nullable: true),
NotifyWhenLogin = table.Column<bool>(nullable: false),
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
LastModifiedOn = table.Column<DateTimeOffset>(nullable: false),
Discriminator = table.Column<string>(nullable: false),
DomainId = table.Column<long>(nullable: true),
HostId = table.Column<long>(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<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Time = table.Column<DateTimeOffset>(nullable: false),
HostId = table.Column<long>(nullable: false),
UserId = table.Column<long>(nullable: false),
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
LastModifiedOn = table.Column<DateTimeOffset>(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");
}
}
}