using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace HyperBooru.Migrations
{
///
public partial class Security : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Users_Objects_ObjectId",
table: "Users");
migrationBuilder.DropIndex(
name: "IX_Users_Username",
table: "Users");
migrationBuilder.DropColumn(
name: "Username",
table: "Users");
migrationBuilder.CreateTable(
name: "Acls",
columns: table => new
{
ObjectId = table.Column(type: "integer", nullable: false),
SubjectTempId1 = table.Column(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Acls", x => x.ObjectId);
table.ForeignKey(
name: "FK_Acls_Objects_ObjectId",
column: x => x.ObjectId,
principalTable: "Objects",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Principals",
columns: table => new
{
ObjectId = table.Column(type: "integer", nullable: false),
Name = table.Column(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Principals", x => x.ObjectId);
});
migrationBuilder.CreateTable(
name: "AclRules",
columns: table => new
{
ObjectId = table.Column(type: "integer", nullable: false),
PrincipalObjectId = table.Column(type: "integer", nullable: false),
Action = table.Column(type: "integer", nullable: false),
Permissions = table.Column(type: "bigint", nullable: false),
AclObjectId = table.Column(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AclRules", x => x.ObjectId);
table.ForeignKey(
name: "FK_AclRules_Acls_AclObjectId",
column: x => x.AclObjectId,
principalTable: "Acls",
principalColumn: "ObjectId");
table.ForeignKey(
name: "FK_AclRules_Principals_PrincipalObjectId",
column: x => x.PrincipalObjectId,
principalTable: "Principals",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Groups",
columns: table => new
{
ObjectId = table.Column(type: "integer", nullable: false),
HBPrincipalObjectId = table.Column(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Groups", x => x.ObjectId);
table.ForeignKey(
name: "FK_Groups_Principals_HBPrincipalObjectId",
column: x => x.HBPrincipalObjectId,
principalTable: "Principals",
principalColumn: "ObjectId");
});
migrationBuilder.UpdateData(
table: "Objects",
keyColumn: "ObjectId",
keyValue: -3,
column: "Guid",
value: new Guid("8fbbc2e9-0609-460a-ab3a-c3bdd10ab793"));
migrationBuilder.InsertData(
table: "Principals",
columns: new[] { "ObjectId", "Name" },
values: new object[] { -3, "admin" });
migrationBuilder.CreateIndex(
name: "IX_AclRules_AclObjectId",
table: "AclRules",
column: "AclObjectId");
migrationBuilder.CreateIndex(
name: "IX_AclRules_PrincipalObjectId",
table: "AclRules",
column: "PrincipalObjectId");
migrationBuilder.CreateIndex(
name: "IX_Groups_HBPrincipalObjectId",
table: "Groups",
column: "HBPrincipalObjectId");
migrationBuilder.CreateIndex(
name: "IX_Principals_Name",
table: "Principals",
column: "Name");
migrationBuilder.AddForeignKey(
name: "FK_Users_Principals_ObjectId",
table: "Users",
column: "ObjectId",
principalTable: "Principals",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Users_Principals_ObjectId",
table: "Users");
migrationBuilder.DropTable(
name: "AclRules");
migrationBuilder.DropTable(
name: "Groups");
migrationBuilder.DropTable(
name: "Acls");
migrationBuilder.DropTable(
name: "Principals");
migrationBuilder.AddColumn(
name: "Username",
table: "Users",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.UpdateData(
table: "Objects",
keyColumn: "ObjectId",
keyValue: -3,
column: "Guid",
value: new Guid("4fa948f4-7c45-4f81-bb6b-e417491e6c96"));
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "ObjectId",
keyValue: -3,
column: "Username",
value: "admin");
migrationBuilder.CreateIndex(
name: "IX_Users_Username",
table: "Users",
column: "Username");
migrationBuilder.AddForeignKey(
name: "FK_Users_Objects_ObjectId",
table: "Users",
column: "ObjectId",
principalTable: "Objects",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
}
}
}