137 lines
5.9 KiB
C#
137 lines
5.9 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
|
|
#nullable disable
|
|
|
|
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
|
|
|
|
namespace Infrastructure.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitialCreate : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.EnsureSchema(
|
|
name: "auth");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Roles",
|
|
schema: "auth",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Roles", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Users",
|
|
schema: "auth",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
Username = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false),
|
|
Email = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false),
|
|
Password = table.Column<string>(type: "varchar(250)", maxLength: 250, nullable: false),
|
|
LastLogin = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
RefreshToken = table.Column<string>(type: "text", nullable: true),
|
|
RefreshTokenExpiryTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
|
ResetPasswordToken = table.Column<string>(type: "text", nullable: true),
|
|
ResetPasswordTokenExpiryTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Users", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "UserRoles",
|
|
schema: "auth",
|
|
columns: table => new
|
|
{
|
|
UserId = table.Column<int>(type: "integer", nullable: false),
|
|
RoleId = table.Column<int>(type: "integer", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId });
|
|
table.ForeignKey(
|
|
name: "FK_UserRoles_Roles_RoleId",
|
|
column: x => x.RoleId,
|
|
principalSchema: "auth",
|
|
principalTable: "Roles",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_UserRoles_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalSchema: "auth",
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.InsertData(
|
|
schema: "auth",
|
|
table: "Roles",
|
|
columns: new[] { "Id", "Name" },
|
|
values: new object[,]
|
|
{
|
|
{ 1, "SuperAdmin" },
|
|
{ 2, "Admin" },
|
|
{ 3, "User" }
|
|
});
|
|
|
|
migrationBuilder.InsertData(
|
|
schema: "auth",
|
|
table: "Users",
|
|
columns: new[] { "Id", "Email", "LastLogin", "Password", "RefreshToken", "RefreshTokenExpiryTime", "ResetPasswordToken", "ResetPasswordTokenExpiryTime", "Username" },
|
|
values: new object[,]
|
|
{
|
|
{ 1, "admin@rss.wenske-services-development.de", new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "AQAAAAIAAYagAAAAELBxAsYVTssn5taCQ7CMo+Mzn0i87Jt8ZXJTe7cgG5hfN3wDJzIkQaotyFhM/mQGaQ==", null, null, null, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "Superadmin" },
|
|
{ 2, "info@rss.wenske-services-development.de", new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "AQAAAAIAAYagAAAAEP0NWiTTz20doMf/KL0WkBR+5roc5KTouMrfiHk2MMXOQn+E+C5Q4dqWD7PnNoxUmQ==", null, null, null, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "Admin" }
|
|
});
|
|
|
|
migrationBuilder.InsertData(
|
|
schema: "auth",
|
|
table: "UserRoles",
|
|
columns: new[] { "RoleId", "UserId" },
|
|
values: new object[,]
|
|
{
|
|
{ 1, 1 },
|
|
{ 2, 2 }
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserRoles_RoleId",
|
|
schema: "auth",
|
|
table: "UserRoles",
|
|
column: "RoleId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "UserRoles",
|
|
schema: "auth");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Roles",
|
|
schema: "auth");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Users",
|
|
schema: "auth");
|
|
}
|
|
}
|
|
}
|