83 lines
3.0 KiB
C#
83 lines
3.0 KiB
C#
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Nocr.Users.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitialMigration : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AlterDatabase()
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Users",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
Username = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4")
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Users", x => x.Id);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "UserIdentity",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
Identity = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
UserId = table.Column<long>(type: "bigint", nullable: false),
|
|
Type = table.Column<int>(type: "int", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_UserIdentity", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_UserIdentity_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id");
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserIdentity_UserId",
|
|
table: "UserIdentity",
|
|
column: "UserId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "UX_users_identity_identity_type",
|
|
table: "UserIdentity",
|
|
columns: new[] { "Identity", "Type" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "UX_users_username",
|
|
table: "Users",
|
|
column: "Username",
|
|
unique: true);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "UserIdentity");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Users");
|
|
}
|
|
}
|
|
}
|