forked from xiongyuxing/tiku-backend.net
149 lines
7.9 KiB
C#
149 lines
7.9 KiB
C#
using System;
|
|
using System.Text.Json;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Tiku.Infrastructure.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddPocketBaseImportAuditPersistence : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "pb_import_runs",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
source_name = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
|
|
source_kind = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
stats = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
started_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
finished_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_pb_import_runs", x => x.id);
|
|
table.UniqueConstraint("ak_pb_import_runs_tenant_id_id", x => new { x.tenant_id, x.id });
|
|
table.ForeignKey(
|
|
name: "fk_pb_import_runs_tenants_tenant_id",
|
|
column: x => x.tenant_id,
|
|
principalTable: "tenants",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "pb_import_issues",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
run_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
collection_name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
legacy_id = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
severity = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
issue_code = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
message = table.Column<string>(type: "text", nullable: false),
|
|
field_path = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
|
|
raw_value_sample = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_pb_import_issues", x => x.id);
|
|
table.UniqueConstraint("ak_pb_import_issues_tenant_id_id", x => new { x.tenant_id, x.id });
|
|
table.ForeignKey(
|
|
name: "fk_pb_import_issues_pb_import_runs_tenant_id_run_id",
|
|
columns: x => new { x.tenant_id, x.run_id },
|
|
principalTable: "pb_import_runs",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_pb_import_issues_tenants_tenant_id",
|
|
column: x => x.tenant_id,
|
|
principalTable: "tenants",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "pb_raw_records",
|
|
columns: table => new
|
|
{
|
|
run_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
collection_name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
legacy_id = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
record = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
normalized = table.Column<bool>(type: "boolean", nullable: false),
|
|
errors = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
|
|
imported_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_pb_raw_records", x => new { x.run_id, x.collection_name, x.legacy_id });
|
|
table.ForeignKey(
|
|
name: "fk_pb_raw_records_pb_import_runs_tenant_id_run_id",
|
|
columns: x => new { x.tenant_id, x.run_id },
|
|
principalTable: "pb_import_runs",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_pb_raw_records_tenants_tenant_id",
|
|
column: x => x.tenant_id,
|
|
principalTable: "tenants",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_pb_import_issues_run_id_severity_collection_name",
|
|
table: "pb_import_issues",
|
|
columns: new[] { "run_id", "severity", "collection_name" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_pb_import_issues_tenant_id_collection_name_legacy_id",
|
|
table: "pb_import_issues",
|
|
columns: new[] { "tenant_id", "collection_name", "legacy_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_pb_import_issues_tenant_id_run_id",
|
|
table: "pb_import_issues",
|
|
columns: new[] { "tenant_id", "run_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_pb_import_runs_tenant_id_status_started_at",
|
|
table: "pb_import_runs",
|
|
columns: new[] { "tenant_id", "status", "started_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_pb_raw_records_tenant_id_collection_name_legacy_id",
|
|
table: "pb_raw_records",
|
|
columns: new[] { "tenant_id", "collection_name", "legacy_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_pb_raw_records_tenant_id_run_id",
|
|
table: "pb_raw_records",
|
|
columns: new[] { "tenant_id", "run_id" });
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "pb_import_issues");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "pb_raw_records");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "pb_import_runs");
|
|
}
|
|
}
|
|
}
|