215 lines
9.7 KiB
C#
215 lines
9.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
|
|
#nullable disable
|
|
|
|
namespace Fengling.AuthService.Data.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddTenantAndLogs : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<string>(
|
|
name: "DisplayName",
|
|
table: "AspNetRoles",
|
|
type: "text",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<bool>(
|
|
name: "IsSystem",
|
|
table: "AspNetRoles",
|
|
type: "boolean",
|
|
nullable: false,
|
|
defaultValue: false);
|
|
|
|
migrationBuilder.AddColumn<List<string>>(
|
|
name: "Permissions",
|
|
table: "AspNetRoles",
|
|
type: "text[]",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<long>(
|
|
name: "TenantId",
|
|
table: "AspNetRoles",
|
|
type: "bigint",
|
|
nullable: true);
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "AccessLogs",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
UserName = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
TenantId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
Action = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
Resource = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
|
Method = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true),
|
|
IpAddress = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
UserAgent = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
|
|
Status = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
Duration = table.Column<int>(type: "integer", nullable: false),
|
|
RequestData = table.Column<string>(type: "text", nullable: true),
|
|
ResponseData = table.Column<string>(type: "text", nullable: true),
|
|
ErrorMessage = table.Column<string>(type: "text", nullable: true),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_AccessLogs", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "AuditLogs",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
Operator = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
TenantId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
Operation = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
Action = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
TargetType = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
TargetId = table.Column<long>(type: "bigint", nullable: true),
|
|
TargetName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
IpAddress = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
|
|
OldValue = table.Column<string>(type: "text", nullable: true),
|
|
NewValue = table.Column<string>(type: "text", nullable: true),
|
|
ErrorMessage = table.Column<string>(type: "text", nullable: true),
|
|
Status = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_AuditLogs", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Tenants",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
TenantId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
ContactName = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
ContactEmail = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
ContactPhone = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true),
|
|
MaxUsers = table.Column<int>(type: "integer", nullable: true),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
|
|
Status = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
|
ExpiresAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
|
IsDeleted = table.Column<bool>(type: "boolean", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Tenants", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AccessLogs_Action",
|
|
table: "AccessLogs",
|
|
column: "Action");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AccessLogs_CreatedAt",
|
|
table: "AccessLogs",
|
|
column: "CreatedAt");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AccessLogs_Status",
|
|
table: "AccessLogs",
|
|
column: "Status");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AccessLogs_TenantId",
|
|
table: "AccessLogs",
|
|
column: "TenantId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AccessLogs_UserName",
|
|
table: "AccessLogs",
|
|
column: "UserName");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AuditLogs_Action",
|
|
table: "AuditLogs",
|
|
column: "Action");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AuditLogs_CreatedAt",
|
|
table: "AuditLogs",
|
|
column: "CreatedAt");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AuditLogs_Operation",
|
|
table: "AuditLogs",
|
|
column: "Operation");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AuditLogs_Operator",
|
|
table: "AuditLogs",
|
|
column: "Operator");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_AuditLogs_TenantId",
|
|
table: "AuditLogs",
|
|
column: "TenantId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Tenants_TenantId",
|
|
table: "Tenants",
|
|
column: "TenantId",
|
|
unique: true);
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "FK_AspNetUsers_Tenants_TenantId",
|
|
table: "AspNetUsers",
|
|
column: "TenantId",
|
|
principalTable: "Tenants",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropForeignKey(
|
|
name: "FK_AspNetUsers_Tenants_TenantId",
|
|
table: "AspNetUsers");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "AccessLogs");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "AuditLogs");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Tenants");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "DisplayName",
|
|
table: "AspNetRoles");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "IsSystem",
|
|
table: "AspNetRoles");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "Permissions",
|
|
table: "AspNetRoles");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "TenantId",
|
|
table: "AspNetRoles");
|
|
}
|
|
}
|
|
}
|