gandalf-reborn/Data/Migrations/20240903154112_sus.cs
2025-03-02 12:51:02 +01:00

593 lines
27 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 W542.GandalfReborn.Data.Migrations
{
/// <inheritdoc />
public partial class sus : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "gr");
migrationBuilder.CreateTable(
name: "Authority",
schema: "gr",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Type = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Authority", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Subject",
schema: "gr",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Visibility = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Subject", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SignIn",
schema: "gr",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Method = table.Column<string>(type: "text", nullable: false),
IsLegacy = table.Column<bool>(type: "boolean", nullable: false),
Email = table.Column<string>(type: "text", nullable: true),
PasswordHash = table.Column<string>(type: "text", nullable: true),
Visibility = table.Column<string>(type: "text", nullable: false),
SubjectId = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SignIn", x => x.Id);
table.ForeignKey(
name: "FK_SignIn_Subject_SubjectId",
column: x => x.SubjectId,
principalSchema: "gr",
principalTable: "Subject",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Tenant",
schema: "gr",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Visibility = table.Column<string>(type: "text", nullable: false),
OwnerId = table.Column<long>(type: "bigint", nullable: false),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tenant", x => x.Id);
table.ForeignKey(
name: "FK_Tenant_Subject_OwnerId",
column: x => x.OwnerId,
principalSchema: "gr",
principalTable: "Subject",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AppRelation",
schema: "gr",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Visibility = table.Column<string>(type: "text", nullable: false),
TenantId = table.Column<long>(type: "bigint", nullable: false),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppRelation", x => x.Id);
table.ForeignKey(
name: "FK_AppRelation_Tenant_TenantId",
column: x => x.TenantId,
principalSchema: "gr",
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TenantSubjectRelation",
schema: "gr",
columns: table => new
{
TenantId = table.Column<long>(type: "bigint", nullable: false),
SubjectId = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TenantSubjectRelation", x => new { x.SubjectId, x.TenantId });
table.ForeignKey(
name: "FK_TenantSubjectRelation_Subject_SubjectId",
column: x => x.SubjectId,
principalSchema: "gr",
principalTable: "Subject",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TenantSubjectRelation_Tenant_TenantId",
column: x => x.TenantId,
principalSchema: "gr",
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TenantVersion",
schema: "gr",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
At = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
SuspectId = table.Column<long>(type: "bigint", nullable: false),
Action = table.Column<string>(type: "text", nullable: false),
Visibility = table.Column<string>(type: "text", nullable: false),
OwnerId = table.Column<long>(type: "bigint", nullable: false),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TenantVersion", x => new { x.Id, x.At });
table.ForeignKey(
name: "FK_TenantVersion_Subject_SuspectId",
column: x => x.SuspectId,
principalSchema: "gr",
principalTable: "Subject",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TenantVersion_Tenant_Id",
column: x => x.Id,
principalSchema: "gr",
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AppRelationVersion",
schema: "gr",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
At = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
SuspectId = table.Column<long>(type: "bigint", nullable: false),
Action = table.Column<string>(type: "text", nullable: false),
Visibility = table.Column<string>(type: "text", nullable: false),
TenantId = table.Column<long>(type: "bigint", nullable: false),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppRelationVersion", x => new { x.Id, x.At });
table.ForeignKey(
name: "FK_AppRelationVersion_AppRelation_Id",
column: x => x.Id,
principalSchema: "gr",
principalTable: "AppRelation",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AppRelationVersion_Subject_SuspectId",
column: x => x.SuspectId,
principalSchema: "gr",
principalTable: "Subject",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AppSubjectRelation",
schema: "gr",
columns: table => new
{
AppId = table.Column<long>(type: "bigint", nullable: false),
SubjectId = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppSubjectRelation", x => new { x.SubjectId, x.AppId });
table.ForeignKey(
name: "FK_AppSubjectRelation_AppRelation_AppId",
column: x => x.AppId,
principalSchema: "gr",
principalTable: "AppRelation",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AppSubjectRelation_Subject_SubjectId",
column: x => x.SubjectId,
principalSchema: "gr",
principalTable: "Subject",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TenantSubjectRelationInternalAuthorityRelation",
schema: "gr",
columns: table => new
{
TenantId = table.Column<long>(type: "bigint", nullable: false),
SubjectId = table.Column<long>(type: "bigint", nullable: false),
InternalAuthorityId = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TenantSubjectRelationInternalAuthorityRelation", x => new { x.SubjectId, x.TenantId, x.InternalAuthorityId });
table.ForeignKey(
name: "FK_TenantSubjectRelationInternalAuthorityRelation_Authority_In~",
column: x => x.InternalAuthorityId,
principalSchema: "gr",
principalTable: "Authority",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TenantSubjectRelationInternalAuthorityRelation_TenantSubjec~",
columns: x => new { x.SubjectId, x.TenantId },
principalSchema: "gr",
principalTable: "TenantSubjectRelation",
principalColumns: new[] { "SubjectId", "TenantId" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TenantSubjectRelationVersion",
schema: "gr",
columns: table => new
{
TenantId = table.Column<long>(type: "bigint", nullable: false),
SubjectId = table.Column<long>(type: "bigint", nullable: false),
At = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
SuspectId = table.Column<long>(type: "bigint", nullable: false),
Action = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TenantSubjectRelationVersion", x => new { x.SubjectId, x.TenantId, x.At });
table.ForeignKey(
name: "FK_TenantSubjectRelationVersion_Subject_SuspectId",
column: x => x.SuspectId,
principalSchema: "gr",
principalTable: "Subject",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TenantSubjectRelationVersion_TenantSubjectRelation_SubjectI~",
columns: x => new { x.SubjectId, x.TenantId },
principalSchema: "gr",
principalTable: "TenantSubjectRelation",
principalColumns: new[] { "SubjectId", "TenantId" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AppSubjectRelationInternalAuthorityRelation",
schema: "gr",
columns: table => new
{
AppId = table.Column<long>(type: "bigint", nullable: false),
SubjectId = table.Column<long>(type: "bigint", nullable: false),
InternalAuthorityId = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppSubjectRelationInternalAuthorityRelation", x => new { x.SubjectId, x.AppId, x.InternalAuthorityId });
table.ForeignKey(
name: "FK_AppSubjectRelationInternalAuthorityRelation_AppSubjectRelat~",
columns: x => new { x.SubjectId, x.AppId },
principalSchema: "gr",
principalTable: "AppSubjectRelation",
principalColumns: new[] { "SubjectId", "AppId" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AppSubjectRelationInternalAuthorityRelation_Authority_Inter~",
column: x => x.InternalAuthorityId,
principalSchema: "gr",
principalTable: "Authority",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AppSubjectRelationVersion",
schema: "gr",
columns: table => new
{
AppId = table.Column<long>(type: "bigint", nullable: false),
SubjectId = table.Column<long>(type: "bigint", nullable: false),
At = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
SuspectId = table.Column<long>(type: "bigint", nullable: false),
Action = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppSubjectRelationVersion", x => new { x.SubjectId, x.AppId, x.At });
table.ForeignKey(
name: "FK_AppSubjectRelationVersion_AppSubjectRelation_SubjectId_AppId",
columns: x => new { x.SubjectId, x.AppId },
principalSchema: "gr",
principalTable: "AppSubjectRelation",
principalColumns: new[] { "SubjectId", "AppId" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AppSubjectRelationVersion_Subject_SuspectId",
column: x => x.SuspectId,
principalSchema: "gr",
principalTable: "Subject",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TenantSubjectRelationInternalAuthorityRelationVersion",
schema: "gr",
columns: table => new
{
TenantId = table.Column<long>(type: "bigint", nullable: false),
SubjectId = table.Column<long>(type: "bigint", nullable: false),
InternalAuthorityId = table.Column<long>(type: "bigint", nullable: false),
At = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
SuspectId = table.Column<long>(type: "bigint", nullable: false),
Action = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TenantSubjectRelationInternalAuthorityRelationVersion", x => new { x.SubjectId, x.TenantId, x.InternalAuthorityId, x.At });
table.ForeignKey(
name: "FK_TenantSubjectRelationInternalAuthorityRelationVersion_Subje~",
column: x => x.SuspectId,
principalSchema: "gr",
principalTable: "Subject",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TenantSubjectRelationInternalAuthorityRelationVersion_Tenan~",
columns: x => new { x.SubjectId, x.TenantId, x.InternalAuthorityId },
principalSchema: "gr",
principalTable: "TenantSubjectRelationInternalAuthorityRelation",
principalColumns: new[] { "SubjectId", "TenantId", "InternalAuthorityId" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AppSubjectRelationInternalAuthorityRelationVersion",
schema: "gr",
columns: table => new
{
AppId = table.Column<long>(type: "bigint", nullable: false),
SubjectId = table.Column<long>(type: "bigint", nullable: false),
InternalAuthorityId = table.Column<long>(type: "bigint", nullable: false),
At = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
SuspectId = table.Column<long>(type: "bigint", nullable: false),
Action = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppSubjectRelationInternalAuthorityRelationVersion", x => new { x.SubjectId, x.AppId, x.InternalAuthorityId, x.At });
table.ForeignKey(
name: "FK_AppSubjectRelationInternalAuthorityRelationVersion_AppSubje~",
columns: x => new { x.SubjectId, x.AppId, x.InternalAuthorityId },
principalSchema: "gr",
principalTable: "AppSubjectRelationInternalAuthorityRelation",
principalColumns: new[] { "SubjectId", "AppId", "InternalAuthorityId" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AppSubjectRelationInternalAuthorityRelationVersion_Subject_~",
column: x => x.SuspectId,
principalSchema: "gr",
principalTable: "Subject",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
schema: "gr",
table: "Authority",
columns: new[] { "Id", "Description", "Name", "Type" },
values: new object[,]
{
{ 1L, "Allows users to read tenants", "Tenant_Read", "Tenant" },
{ 2L, "Allows users to read apps", "App_Read", "App" }
});
migrationBuilder.InsertData(
schema: "gr",
table: "Subject",
columns: new[] { "Id", "Name", "Visibility" },
values: new object[] { 1L, "chris", "Active" });
migrationBuilder.CreateIndex(
name: "IX_AppRelation_TenantId",
schema: "gr",
table: "AppRelation",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_AppRelationVersion_SuspectId",
schema: "gr",
table: "AppRelationVersion",
column: "SuspectId");
migrationBuilder.CreateIndex(
name: "IX_AppSubjectRelation_AppId",
schema: "gr",
table: "AppSubjectRelation",
column: "AppId");
migrationBuilder.CreateIndex(
name: "IX_AppSubjectRelationInternalAuthorityRelation_InternalAuthori~",
schema: "gr",
table: "AppSubjectRelationInternalAuthorityRelation",
column: "InternalAuthorityId");
migrationBuilder.CreateIndex(
name: "IX_AppSubjectRelationInternalAuthorityRelationVersion_SuspectId",
schema: "gr",
table: "AppSubjectRelationInternalAuthorityRelationVersion",
column: "SuspectId");
migrationBuilder.CreateIndex(
name: "IX_AppSubjectRelationVersion_SuspectId",
schema: "gr",
table: "AppSubjectRelationVersion",
column: "SuspectId");
migrationBuilder.CreateIndex(
name: "IX_Authority_Name",
schema: "gr",
table: "Authority",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_SignIn_SubjectId",
schema: "gr",
table: "SignIn",
column: "SubjectId");
migrationBuilder.CreateIndex(
name: "IX_Subject_Name",
schema: "gr",
table: "Subject",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Tenant_OwnerId",
schema: "gr",
table: "Tenant",
column: "OwnerId");
migrationBuilder.CreateIndex(
name: "IX_TenantSubjectRelation_TenantId",
schema: "gr",
table: "TenantSubjectRelation",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_TenantSubjectRelationInternalAuthorityRelation_InternalAuth~",
schema: "gr",
table: "TenantSubjectRelationInternalAuthorityRelation",
column: "InternalAuthorityId");
migrationBuilder.CreateIndex(
name: "IX_TenantSubjectRelationInternalAuthorityRelationVersion_Suspe~",
schema: "gr",
table: "TenantSubjectRelationInternalAuthorityRelationVersion",
column: "SuspectId");
migrationBuilder.CreateIndex(
name: "IX_TenantSubjectRelationVersion_SuspectId",
schema: "gr",
table: "TenantSubjectRelationVersion",
column: "SuspectId");
migrationBuilder.CreateIndex(
name: "IX_TenantVersion_SuspectId",
schema: "gr",
table: "TenantVersion",
column: "SuspectId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AppRelationVersion",
schema: "gr");
migrationBuilder.DropTable(
name: "AppSubjectRelationInternalAuthorityRelationVersion",
schema: "gr");
migrationBuilder.DropTable(
name: "AppSubjectRelationVersion",
schema: "gr");
migrationBuilder.DropTable(
name: "SignIn",
schema: "gr");
migrationBuilder.DropTable(
name: "TenantSubjectRelationInternalAuthorityRelationVersion",
schema: "gr");
migrationBuilder.DropTable(
name: "TenantSubjectRelationVersion",
schema: "gr");
migrationBuilder.DropTable(
name: "TenantVersion",
schema: "gr");
migrationBuilder.DropTable(
name: "AppSubjectRelationInternalAuthorityRelation",
schema: "gr");
migrationBuilder.DropTable(
name: "TenantSubjectRelationInternalAuthorityRelation",
schema: "gr");
migrationBuilder.DropTable(
name: "AppSubjectRelation",
schema: "gr");
migrationBuilder.DropTable(
name: "Authority",
schema: "gr");
migrationBuilder.DropTable(
name: "TenantSubjectRelation",
schema: "gr");
migrationBuilder.DropTable(
name: "AppRelation",
schema: "gr");
migrationBuilder.DropTable(
name: "Tenant",
schema: "gr");
migrationBuilder.DropTable(
name: "Subject",
schema: "gr");
}
}
}