159 lines
7.1 KiB
C#
159 lines
7.1 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace ApplicationHub.Data.EF.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitDB : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Groups",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
Name = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Groups", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Rights",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
Name = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Rights", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Users",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
UserName = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
|
|
Email = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
|
|
PasswordHash = table.Column<string>(type: "TEXT", maxLength: 255, nullable: true),
|
|
Active = table.Column<bool>(type: "INTEGER", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Users", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "GroupEntityRightEntity",
|
|
columns: table => new
|
|
{
|
|
GroupsId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
RightsId = table.Column<Guid>(type: "TEXT", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_GroupEntityRightEntity", x => new { x.GroupsId, x.RightsId });
|
|
table.ForeignKey(
|
|
name: "FK_GroupEntityRightEntity_Groups_GroupsId",
|
|
column: x => x.GroupsId,
|
|
principalTable: "Groups",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_GroupEntityRightEntity_Rights_RightsId",
|
|
column: x => x.RightsId,
|
|
principalTable: "Rights",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "GroupEntityUserEntity",
|
|
columns: table => new
|
|
{
|
|
GroupsId = table.Column<Guid>(type: "TEXT", nullable: false),
|
|
UsersId = table.Column<Guid>(type: "TEXT", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_GroupEntityUserEntity", x => new { x.GroupsId, x.UsersId });
|
|
table.ForeignKey(
|
|
name: "FK_GroupEntityUserEntity_Groups_GroupsId",
|
|
column: x => x.GroupsId,
|
|
principalTable: "Groups",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_GroupEntityUserEntity_Users_UsersId",
|
|
column: x => x.UsersId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_GroupEntityRightEntity_RightsId",
|
|
table: "GroupEntityRightEntity",
|
|
column: "RightsId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_GroupEntityUserEntity_UsersId",
|
|
table: "GroupEntityUserEntity",
|
|
column: "UsersId");
|
|
|
|
var userAdminId = Guid.NewGuid();
|
|
var groupAdminId = Guid.NewGuid();
|
|
var groupUserId = Guid.NewGuid();
|
|
var groupGuestId = Guid.NewGuid();
|
|
var readRightId = Guid.NewGuid();
|
|
var writeRightId = Guid.NewGuid();
|
|
var deleteRightId = Guid.NewGuid();
|
|
|
|
migrationBuilder.InsertData("Rights", ["Id", "Name"], [readRightId, "READ"]);
|
|
migrationBuilder.InsertData("Rights", ["Id", "Name"], [writeRightId, "WRITE"]);
|
|
migrationBuilder.InsertData("Rights", ["Id", "Name"], [deleteRightId, "DELETE"]);
|
|
|
|
migrationBuilder.InsertData("Groups", ["Id", "Name"], [groupAdminId, "Group_Name_Administrator"]);
|
|
migrationBuilder.InsertData("Groups", ["Id", "Name"], [groupUserId, "Group_Name_User"]);
|
|
migrationBuilder.InsertData("Groups", ["Id", "Name"], [groupGuestId, "Group_Name_Guest"]);
|
|
|
|
migrationBuilder.InsertData("Users", ["Id", "UserName", "Email", "PasswordHash", "Active"], [userAdminId, "admin", "admin@example.de", "AQAAAAIAAYagAAAAEFTsFQQz1Yp6d2zw5iQ4AzNhQQ7QuvdhK3Y2kN/7wp97OXgB2fTrabYqGDYdFSMMkQ==", true]);
|
|
|
|
migrationBuilder.InsertData("GroupEntityRightEntity", ["GroupsId", "RightsId"], [groupAdminId, readRightId]);
|
|
migrationBuilder.InsertData("GroupEntityRightEntity", ["GroupsId", "RightsId"], [groupAdminId, writeRightId]);
|
|
migrationBuilder.InsertData("GroupEntityRightEntity", ["GroupsId", "RightsId"], [groupAdminId, deleteRightId]);
|
|
migrationBuilder.InsertData("GroupEntityRightEntity", ["GroupsId", "RightsId"], [groupUserId, readRightId]);
|
|
migrationBuilder.InsertData("GroupEntityRightEntity", ["GroupsId", "RightsId"], [groupUserId, writeRightId]);
|
|
migrationBuilder.InsertData("GroupEntityRightEntity", ["GroupsId", "RightsId"], [groupGuestId, readRightId]);
|
|
|
|
migrationBuilder.InsertData("GroupEntityUserEntity", ["GroupsId", "UsersId"], [groupAdminId, userAdminId]);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "GroupEntityRightEntity");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "GroupEntityUserEntity");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Rights");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Groups");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Users");
|
|
}
|
|
}
|
|
}
|