Files
tiku-backend.net/Tiku.Infrastructure/Persistence/Migrations/20260726122712_AddCommissionSettlementProofs.cs
2026-07-26 20:36:01 +08:00

158 lines
9.0 KiB
C#

using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Tiku.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class AddCommissionSettlementProofs : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "commission_settlement_export_events",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
settlement_id = table.Column<Guid>(type: "uuid", nullable: false),
exported_by = table.Column<Guid>(type: "uuid", nullable: true),
export_format = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
filename = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
row_count = table.Column<int>(type: "integer", nullable: false),
content_sha256 = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_commission_settlement_export_events", x => x.id);
table.CheckConstraint("ck_commission_export_events_rows", "row_count >= 0");
table.ForeignKey(
name: "fk_commission_settlement_export_events_commission_settlements_~",
columns: x => new { x.tenant_id, x.settlement_id },
principalTable: "commission_settlements",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_commission_settlement_export_events_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_commission_settlement_export_events_users_exported_by",
column: x => x.exported_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "commission_settlement_proofs",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
settlement_id = table.Column<Guid>(type: "uuid", nullable: false),
asset_id = table.Column<Guid>(type: "uuid", nullable: true),
submitted_by = table.Column<Guid>(type: "uuid", nullable: true),
reviewed_by = table.Column<Guid>(type: "uuid", nullable: true),
proof_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
title = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
description = table.Column<string>(type: "text", nullable: true),
external_url = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true),
amount_cents = table.Column<int>(type: "integer", nullable: true),
payment_method = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
payment_account = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
paid_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
reviewed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
review_note = table.Column<string>(type: "text", nullable: true),
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_commission_settlement_proofs", x => x.id);
table.UniqueConstraint("ak_commission_settlement_proofs_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_commission_settlement_proofs_amount", "amount_cents is null or amount_cents >= 0");
table.ForeignKey(
name: "fk_commission_settlement_proofs_commission_settlements_tenant_~",
columns: x => new { x.tenant_id, x.settlement_id },
principalTable: "commission_settlements",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_commission_settlement_proofs_content_assets_tenant_id_asset~",
columns: x => new { x.tenant_id, x.asset_id },
principalTable: "content_assets",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "fk_commission_settlement_proofs_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_commission_settlement_proofs_users_reviewed_by",
column: x => x.reviewed_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "fk_commission_settlement_proofs_users_submitted_by",
column: x => x.submitted_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateIndex(
name: "ix_commission_settlement_export_events_exported_by",
table: "commission_settlement_export_events",
column: "exported_by");
migrationBuilder.CreateIndex(
name: "ix_commission_settlement_export_events_tenant_id_settlement_id~",
table: "commission_settlement_export_events",
columns: new[] { "tenant_id", "settlement_id", "created_at" });
migrationBuilder.CreateIndex(
name: "ix_commission_settlement_proofs_reviewed_by",
table: "commission_settlement_proofs",
column: "reviewed_by");
migrationBuilder.CreateIndex(
name: "ix_commission_settlement_proofs_submitted_by",
table: "commission_settlement_proofs",
column: "submitted_by");
migrationBuilder.CreateIndex(
name: "ix_commission_settlement_proofs_tenant_id_asset_id",
table: "commission_settlement_proofs",
columns: new[] { "tenant_id", "asset_id" });
migrationBuilder.CreateIndex(
name: "ix_commission_settlement_proofs_tenant_id_settlement_id_status~",
table: "commission_settlement_proofs",
columns: new[] { "tenant_id", "settlement_id", "status", "created_at" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "commission_settlement_export_events");
migrationBuilder.DropTable(
name: "commission_settlement_proofs");
}
}
}