670 lines
39 KiB
C#
670 lines
39 KiB
C#
using System;
|
|
using System.Text.Json;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Tiku.Infrastructure.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddCommerceRefundAndReconciliationPersistence : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<int>(
|
|
name: "refunded_amount_cents",
|
|
table: "payments",
|
|
type: "integer",
|
|
nullable: false,
|
|
defaultValue: 0);
|
|
|
|
migrationBuilder.AddColumn<int>(
|
|
name: "refunded_amount_cents",
|
|
table: "orders",
|
|
type: "integer",
|
|
nullable: false,
|
|
defaultValue: 0);
|
|
|
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
|
name: "revoked_at",
|
|
table: "entitlements",
|
|
type: "timestamp with time zone",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<Guid>(
|
|
name: "revoked_by",
|
|
table: "entitlements",
|
|
type: "uuid",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<string>(
|
|
name: "revoked_reason",
|
|
table: "entitlements",
|
|
type: "character varying(1000)",
|
|
maxLength: 1000,
|
|
nullable: true);
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "commerce_reconciliation_batches",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
created_by = table.Column<Guid>(type: "uuid", nullable: true),
|
|
provider = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
bill_date = table.Column<DateOnly>(type: "date", nullable: false),
|
|
bill_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
source = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
source_name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
|
|
source_hash = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
total_count = table.Column<int>(type: "integer", nullable: false),
|
|
matched_count = table.Column<int>(type: "integer", nullable: false),
|
|
mismatch_count = table.Column<int>(type: "integer", nullable: false),
|
|
missing_local_count = table.Column<int>(type: "integer", nullable: false),
|
|
missing_provider_count = table.Column<int>(type: "integer", nullable: false),
|
|
duplicate_count = table.Column<int>(type: "integer", nullable: false),
|
|
ignored_count = table.Column<int>(type: "integer", nullable: false),
|
|
amount_cents = table.Column<int>(type: "integer", nullable: false),
|
|
refund_amount_cents = table.Column<int>(type: "integer", nullable: false),
|
|
fee_cents = table.Column<int>(type: "integer", nullable: false),
|
|
completed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
error = 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_commerce_reconciliation_batches", x => x.id);
|
|
table.UniqueConstraint("ak_commerce_reconciliation_batches_tenant_id_id", x => new { x.tenant_id, x.id });
|
|
table.CheckConstraint("ck_commerce_reconciliation_batches_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");
|
|
table.CheckConstraint("ck_commerce_reconciliation_batches_counts", "total_count >= 0 and matched_count >= 0 and mismatch_count >= 0 and missing_local_count >= 0 and missing_provider_count >= 0 and duplicate_count >= 0 and ignored_count >= 0");
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_batches_tenants_tenant_id",
|
|
column: x => x.tenant_id,
|
|
principalTable: "tenants",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_batches_users_created_by",
|
|
column: x => x.created_by,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "commerce_refund_requests",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
order_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
payment_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
requested_by = table.Column<Guid>(type: "uuid", nullable: true),
|
|
reviewed_by = table.Column<Guid>(type: "uuid", nullable: true),
|
|
processed_by = table.Column<Guid>(type: "uuid", nullable: true),
|
|
refund_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
provider = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
provider_refund_no = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
|
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
amount_cents = table.Column<int>(type: "integer", nullable: false),
|
|
reason = table.Column<string>(type: "text", nullable: true),
|
|
entitlement_action = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
requested_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
reviewed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
processed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
succeeded_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
failed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
cancelled_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
failure_reason = 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_commerce_refund_requests", x => x.id);
|
|
table.UniqueConstraint("ak_commerce_refund_requests_tenant_id_id", x => new { x.tenant_id, x.id });
|
|
table.CheckConstraint("ck_commerce_refund_requests_amount", "amount_cents > 0");
|
|
table.ForeignKey(
|
|
name: "fk_commerce_refund_requests_orders_tenant_id_order_id",
|
|
columns: x => new { x.tenant_id, x.order_id },
|
|
principalTable: "orders",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_refund_requests_payments_tenant_id_payment_id",
|
|
columns: x => new { x.tenant_id, x.payment_id },
|
|
principalTable: "payments",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_refund_requests_tenants_tenant_id",
|
|
column: x => x.tenant_id,
|
|
principalTable: "tenants",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_refund_requests_users_processed_by",
|
|
column: x => x.processed_by,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_refund_requests_users_requested_by",
|
|
column: x => x.requested_by,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_refund_requests_users_reviewed_by",
|
|
column: x => x.reviewed_by,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "commerce_reconciliation_items",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
batch_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
order_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
payment_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
refund_request_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
row_no = table.Column<int>(type: "integer", nullable: false),
|
|
provider = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
transaction_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
provider_trade_no = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
|
provider_refund_no = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
|
order_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
refund_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
amount_cents = table.Column<int>(type: "integer", nullable: false),
|
|
refund_amount_cents = table.Column<int>(type: "integer", nullable: false),
|
|
fee_cents = table.Column<int>(type: "integer", nullable: false),
|
|
paid_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
refunded_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
provider_status = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
local_status = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
match_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
severity = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
issue_code = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
details = 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_commerce_reconciliation_items", x => x.id);
|
|
table.UniqueConstraint("ak_commerce_reconciliation_items_tenant_id_id", x => new { x.tenant_id, x.id });
|
|
table.CheckConstraint("ck_commerce_reconciliation_items_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");
|
|
table.CheckConstraint("ck_commerce_reconciliation_items_row", "row_no > 0");
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_items_commerce_reconciliation_batch~",
|
|
columns: x => new { x.tenant_id, x.batch_id },
|
|
principalTable: "commerce_reconciliation_batches",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_items_commerce_refund_requests_tena~",
|
|
columns: x => new { x.tenant_id, x.refund_request_id },
|
|
principalTable: "commerce_refund_requests",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_items_orders_tenant_id_order_id",
|
|
columns: x => new { x.tenant_id, x.order_id },
|
|
principalTable: "orders",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_items_payments_tenant_id_payment_id",
|
|
columns: x => new { x.tenant_id, x.payment_id },
|
|
principalTable: "payments",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_items_tenants_tenant_id",
|
|
column: x => x.tenant_id,
|
|
principalTable: "tenants",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "commerce_refund_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),
|
|
refund_request_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
from_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
to_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
event_type = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
actor_user_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
details = 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_commerce_refund_events", x => x.id);
|
|
table.UniqueConstraint("ak_commerce_refund_events_tenant_id_id", x => new { x.tenant_id, x.id });
|
|
table.ForeignKey(
|
|
name: "fk_commerce_refund_events_commerce_refund_requests_tenant_id_r~",
|
|
columns: x => new { x.tenant_id, x.refund_request_id },
|
|
principalTable: "commerce_refund_requests",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_refund_events_tenants_tenant_id",
|
|
column: x => x.tenant_id,
|
|
principalTable: "tenants",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_refund_events_users_actor_user_id",
|
|
column: x => x.actor_user_id,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "commerce_reconciliation_issues",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
batch_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
item_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
order_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
payment_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
refund_request_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
assigned_to = table.Column<Guid>(type: "uuid", nullable: true),
|
|
created_by = table.Column<Guid>(type: "uuid", nullable: true),
|
|
resolved_by = table.Column<Guid>(type: "uuid", nullable: true),
|
|
issue_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
provider = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
transaction_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
issue_code = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
match_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
severity = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
resolution_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
order_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
refund_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
provider_trade_no = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
|
provider_refund_no = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
|
amount_cents = table.Column<int>(type: "integer", nullable: false),
|
|
refund_amount_cents = table.Column<int>(type: "integer", nullable: false),
|
|
resolved_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
due_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
summary = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
|
|
resolution_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_commerce_reconciliation_issues", x => x.id);
|
|
table.UniqueConstraint("ak_commerce_reconciliation_issues_tenant_id_id", x => new { x.tenant_id, x.id });
|
|
table.CheckConstraint("ck_commerce_reconciliation_issues_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issues_commerce_reconciliation_batc~",
|
|
columns: x => new { x.tenant_id, x.batch_id },
|
|
principalTable: "commerce_reconciliation_batches",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issues_commerce_reconciliation_item~",
|
|
columns: x => new { x.tenant_id, x.item_id },
|
|
principalTable: "commerce_reconciliation_items",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issues_commerce_refund_requests_ten~",
|
|
columns: x => new { x.tenant_id, x.refund_request_id },
|
|
principalTable: "commerce_refund_requests",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issues_orders_tenant_id_order_id",
|
|
columns: x => new { x.tenant_id, x.order_id },
|
|
principalTable: "orders",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issues_payments_tenant_id_payment_id",
|
|
columns: x => new { x.tenant_id, x.payment_id },
|
|
principalTable: "payments",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issues_tenants_tenant_id",
|
|
column: x => x.tenant_id,
|
|
principalTable: "tenants",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issues_users_assigned_to",
|
|
column: x => x.assigned_to,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issues_users_created_by",
|
|
column: x => x.created_by,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issues_users_resolved_by",
|
|
column: x => x.resolved_by,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "commerce_reconciliation_issue_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),
|
|
issue_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
from_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
to_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
event_type = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
actor_user_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
note = table.Column<string>(type: "text", nullable: true),
|
|
details = 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_commerce_reconciliation_issue_events", x => x.id);
|
|
table.UniqueConstraint("ak_commerce_reconciliation_issue_events_tenant_id_id", x => new { x.tenant_id, x.id });
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issue_events_commerce_reconciliatio~",
|
|
columns: x => new { x.tenant_id, x.issue_id },
|
|
principalTable: "commerce_reconciliation_issues",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issue_events_tenants_tenant_id",
|
|
column: x => x.tenant_id,
|
|
principalTable: "tenants",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_commerce_reconciliation_issue_events_users_actor_user_id",
|
|
column: x => x.actor_user_id,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
});
|
|
|
|
migrationBuilder.AddCheckConstraint(
|
|
name: "ck_payments_refunded_amount",
|
|
table: "payments",
|
|
sql: "refunded_amount_cents >= 0");
|
|
|
|
migrationBuilder.AddCheckConstraint(
|
|
name: "ck_orders_refunded_amount",
|
|
table: "orders",
|
|
sql: "refunded_amount_cents >= 0");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_entitlements_revoked_by",
|
|
table: "entitlements",
|
|
column: "revoked_by");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_batches_created_by",
|
|
table: "commerce_reconciliation_batches",
|
|
column: "created_by");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_batches_tenant_id_provider_bill_dat~",
|
|
table: "commerce_reconciliation_batches",
|
|
columns: new[] { "tenant_id", "provider", "bill_date", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_batches_tenant_id_status_created_at",
|
|
table: "commerce_reconciliation_batches",
|
|
columns: new[] { "tenant_id", "status", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issue_events_actor_user_id",
|
|
table: "commerce_reconciliation_issue_events",
|
|
column: "actor_user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issue_events_tenant_id_issue_id_cre~",
|
|
table: "commerce_reconciliation_issue_events",
|
|
columns: new[] { "tenant_id", "issue_id", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_assigned_to",
|
|
table: "commerce_reconciliation_issues",
|
|
column: "assigned_to");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_created_by",
|
|
table: "commerce_reconciliation_issues",
|
|
column: "created_by");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_resolved_by",
|
|
table: "commerce_reconciliation_issues",
|
|
column: "resolved_by");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_tenant_id_assigned_to_status~",
|
|
table: "commerce_reconciliation_issues",
|
|
columns: new[] { "tenant_id", "assigned_to", "status", "due_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_tenant_id_batch_id_status_cr~",
|
|
table: "commerce_reconciliation_issues",
|
|
columns: new[] { "tenant_id", "batch_id", "status", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_tenant_id_issue_no",
|
|
table: "commerce_reconciliation_issues",
|
|
columns: new[] { "tenant_id", "issue_no" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_tenant_id_item_id",
|
|
table: "commerce_reconciliation_issues",
|
|
columns: new[] { "tenant_id", "item_id" },
|
|
unique: true,
|
|
filter: "item_id is not null and status in ('open', 'investigating', 'escalated')");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_tenant_id_order_id",
|
|
table: "commerce_reconciliation_issues",
|
|
columns: new[] { "tenant_id", "order_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_tenant_id_order_no_created_at",
|
|
table: "commerce_reconciliation_issues",
|
|
columns: new[] { "tenant_id", "order_no", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_tenant_id_payment_id_created~",
|
|
table: "commerce_reconciliation_issues",
|
|
columns: new[] { "tenant_id", "payment_id", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_tenant_id_refund_request_id",
|
|
table: "commerce_reconciliation_issues",
|
|
columns: new[] { "tenant_id", "refund_request_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_issues_tenant_id_status_severity_cr~",
|
|
table: "commerce_reconciliation_issues",
|
|
columns: new[] { "tenant_id", "status", "severity", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_items_batch_id_row_no",
|
|
table: "commerce_reconciliation_items",
|
|
columns: new[] { "batch_id", "row_no" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_items_tenant_id_batch_id_match_stat~",
|
|
table: "commerce_reconciliation_items",
|
|
columns: new[] { "tenant_id", "batch_id", "match_status", "row_no" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_items_tenant_id_order_id",
|
|
table: "commerce_reconciliation_items",
|
|
columns: new[] { "tenant_id", "order_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_items_tenant_id_order_no_created_at",
|
|
table: "commerce_reconciliation_items",
|
|
columns: new[] { "tenant_id", "order_no", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_items_tenant_id_payment_id",
|
|
table: "commerce_reconciliation_items",
|
|
columns: new[] { "tenant_id", "payment_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_items_tenant_id_provider_provider_t~",
|
|
table: "commerce_reconciliation_items",
|
|
columns: new[] { "tenant_id", "provider", "provider_trade_no", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_items_tenant_id_refund_no_provider_~",
|
|
table: "commerce_reconciliation_items",
|
|
columns: new[] { "tenant_id", "refund_no", "provider_refund_no", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_reconciliation_items_tenant_id_refund_request_id",
|
|
table: "commerce_reconciliation_items",
|
|
columns: new[] { "tenant_id", "refund_request_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_refund_events_actor_user_id",
|
|
table: "commerce_refund_events",
|
|
column: "actor_user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_refund_events_tenant_id_refund_request_id_created_~",
|
|
table: "commerce_refund_events",
|
|
columns: new[] { "tenant_id", "refund_request_id", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_refund_requests_processed_by",
|
|
table: "commerce_refund_requests",
|
|
column: "processed_by");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_refund_requests_requested_by",
|
|
table: "commerce_refund_requests",
|
|
column: "requested_by");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_refund_requests_reviewed_by",
|
|
table: "commerce_refund_requests",
|
|
column: "reviewed_by");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_refund_requests_tenant_id_order_id_created_at",
|
|
table: "commerce_refund_requests",
|
|
columns: new[] { "tenant_id", "order_id", "created_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_refund_requests_tenant_id_payment_id",
|
|
table: "commerce_refund_requests",
|
|
columns: new[] { "tenant_id", "payment_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_refund_requests_tenant_id_refund_no",
|
|
table: "commerce_refund_requests",
|
|
columns: new[] { "tenant_id", "refund_no" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_commerce_refund_requests_tenant_id_status_created_at",
|
|
table: "commerce_refund_requests",
|
|
columns: new[] { "tenant_id", "status", "created_at" });
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "fk_entitlements_users_revoked_by",
|
|
table: "entitlements",
|
|
column: "revoked_by",
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropForeignKey(
|
|
name: "fk_entitlements_users_revoked_by",
|
|
table: "entitlements");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "commerce_reconciliation_issue_events");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "commerce_refund_events");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "commerce_reconciliation_issues");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "commerce_reconciliation_items");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "commerce_reconciliation_batches");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "commerce_refund_requests");
|
|
|
|
migrationBuilder.DropCheckConstraint(
|
|
name: "ck_payments_refunded_amount",
|
|
table: "payments");
|
|
|
|
migrationBuilder.DropCheckConstraint(
|
|
name: "ck_orders_refunded_amount",
|
|
table: "orders");
|
|
|
|
migrationBuilder.DropIndex(
|
|
name: "ix_entitlements_revoked_by",
|
|
table: "entitlements");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "refunded_amount_cents",
|
|
table: "payments");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "refunded_amount_cents",
|
|
table: "orders");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "revoked_at",
|
|
table: "entitlements");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "revoked_by",
|
|
table: "entitlements");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "revoked_reason",
|
|
table: "entitlements");
|
|
}
|
|
}
|
|
}
|