using System; using System.Text.Json; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Tiku.Infrastructure.Persistence.Migrations { /// public partial class AddPocketBaseImportAuditPersistence : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "pb_import_runs", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), tenant_id = table.Column(type: "uuid", nullable: false), source_name = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), source_kind = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), stats = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), started_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), finished_at = table.Column(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(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), run_id = table.Column(type: "uuid", nullable: true), tenant_id = table.Column(type: "uuid", nullable: false), collection_name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), legacy_id = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), severity = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), issue_code = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), message = table.Column(type: "text", nullable: false), field_path = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), raw_value_sample = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), created_at = table.Column(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(type: "uuid", nullable: false), collection_name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), legacy_id = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), tenant_id = table.Column(type: "uuid", nullable: false), record = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), normalized = table.Column(type: "boolean", nullable: false), errors = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"), imported_at = table.Column(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" }); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "pb_import_issues"); migrationBuilder.DropTable( name: "pb_raw_records"); migrationBuilder.DropTable( name: "pb_import_runs"); } } }