using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Tiku.Infrastructure.Persistence.Migrations
{
///
public partial class InitialSchema : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:PostgresExtension:citext", ",,")
.Annotation("Npgsql:PostgresExtension:ltree", ",,");
migrationBuilder.CreateTable(
name: "platform_dunning_notification_channels",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
channel_code = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
description = table.Column(type: "text", nullable: true),
enabled = table.Column(type: "boolean", nullable: false),
provider = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
webhook_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false),
secret_ref = table.Column(type: "character varying(300)", maxLength: 300, nullable: true),
reminder_types = table.Column(type: "text[]", nullable: false, defaultValueSql: "array['overdue', 'final_notice']::text[]"),
reminder_channels = table.Column(type: "text[]", nullable: false, defaultValueSql: "array['internal']::text[]"),
min_reminder_level = table.Column(type: "integer", nullable: false),
tenant_ids = table.Column(type: "uuid[]", nullable: false, defaultValueSql: "'{}'::uuid[]"),
timeout_seconds = table.Column(type: "integer", nullable: false),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_platform_dunning_notification_channels", x => x.id);
table.CheckConstraint("ck_platform_dunning_channels_level", "min_reminder_level between 1 and 20");
table.CheckConstraint("ck_platform_dunning_channels_timeout", "timeout_seconds between 1 and 60");
});
migrationBuilder.CreateTable(
name: "platform_saas_plans",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
code = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
description = table.Column(type: "text", nullable: true),
billing_cycle = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
base_amount_cents = table.Column(type: "integer", nullable: false),
currency = table.Column(type: "character varying(10)", maxLength: 10, nullable: false),
included_quotas = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
overage_prices = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
feature_flags = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
sort_order = table.Column(type: "integer", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_platform_saas_plans", x => x.id);
table.CheckConstraint("ck_platform_saas_plans_amount", "base_amount_cents >= 0");
});
migrationBuilder.CreateTable(
name: "tenant_theme_templates",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
code = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
description = table.Column(type: "text", nullable: true),
preview_image_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
theme = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
public_assets = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
sort_order = table.Column(type: "integer", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_tenant_theme_templates", x => x.id);
table.UniqueConstraint("ak_tenant_theme_templates_code", x => x.code);
});
migrationBuilder.CreateTable(
name: "users",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
username = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
email = table.Column(type: "citext", maxLength: 320, nullable: true),
phone = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
avatar_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
primary_role = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
score = table.Column(type: "integer", nullable: false),
last_seen_at = table.Column(type: "timestamp with time zone", nullable: true),
legacy_password_hash = table.Column(type: "character varying(512)", maxLength: 512, nullable: true),
password_migration_required = table.Column(type: "boolean", nullable: false),
raw_profile = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_users", x => x.id);
});
migrationBuilder.CreateTable(
name: "tenants",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
slug = table.Column(type: "citext", maxLength: 100, nullable: false),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
legal_name = table.Column(type: "character varying(300)", maxLength: 300, nullable: true),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
mode = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
billing_status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
owner_user_id = table.Column(type: "uuid", nullable: true),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_tenants", x => x.id);
table.ForeignKey(
name: "fk_tenants_users_owner_user_id",
column: x => x.owner_user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "user_identities",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column(type: "uuid", nullable: false),
provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
provider_subject = table.Column(type: "character varying(255)", maxLength: 255, nullable: false),
union_id = table.Column(type: "character varying(255)", maxLength: 255, nullable: true),
open_id = table.Column(type: "character varying(255)", maxLength: 255, nullable: true),
phone = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
email = table.Column(type: "citext", maxLength: 320, nullable: true),
secret_payload = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_user_identities", x => x.id);
table.ForeignKey(
name: "fk_user_identities_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "announcements",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
content = table.Column(type: "text", nullable: true),
link = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
background_color = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
sort_order = table.Column(type: "integer", nullable: false),
is_active = table.Column(type: "boolean", nullable: false),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_announcements", x => x.id);
table.UniqueConstraint("ak_announcements_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_announcements_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "app_assets",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
asset_key = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
file_name = table.Column(type: "character varying(500)", maxLength: 500, nullable: true),
description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_app_assets", x => x.id);
table.UniqueConstraint("ak_app_assets_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_app_assets_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "audit_logs",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
tenant_id = table.Column(type: "uuid", nullable: true),
actor_user_id = table.Column(type: "uuid", nullable: true),
action = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
target_type = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
target_id = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
details = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
ip_address = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
user_agent = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_audit_logs", x => x.id);
table.ForeignKey(
name: "fk_audit_logs_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_audit_logs_users_actor_user_id",
column: x => x.actor_user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "auth_login_events",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
tenant_id = table.Column(type: "uuid", nullable: false),
user_id = table.Column(type: "uuid", nullable: true),
provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
identifier = table.Column(type: "character varying(320)", maxLength: 320, nullable: true),
result = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
failure_code = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
ip_address = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
user_agent = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_auth_login_events", x => x.id);
table.UniqueConstraint("ak_auth_login_events_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_auth_login_events_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_auth_login_events_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "auth_sessions",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column(type: "uuid", nullable: false),
token_hash = table.Column(type: "character varying(256)", maxLength: 256, nullable: false),
provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
expires_at = table.Column(type: "timestamp with time zone", nullable: false),
revoked_at = table.Column(type: "timestamp with time zone", nullable: true),
ip_address = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
user_agent = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_auth_sessions", x => x.id);
table.UniqueConstraint("ak_auth_sessions_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_auth_sessions_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_auth_sessions_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "badges",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
description = table.Column(type: "text", nullable: true),
category = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
icon_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
level = table.Column(type: "integer", nullable: true),
unlock_type = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
condition_field = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
condition_operator = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
condition_value = table.Column(type: "numeric(18,4)", precision: 18, scale: 4, nullable: true),
condition_extra = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
sort_order = table.Column(type: "integer", nullable: false),
is_active = table.Column(type: "boolean", nullable: false),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_badges", x => x.id);
table.UniqueConstraint("ak_badges_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_badges_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "code_batches",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column(type: "uuid", nullable: true),
created_by = table.Column(type: "uuid", nullable: true),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
sale_type = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
channel = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
campaign_name = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
default_unit_price_cents = table.Column(type: "integer", nullable: false),
cost_price_cents = table.Column(type: "integer", nullable: false),
total_count = table.Column(type: "integer", nullable: false),
days = table.Column(type: "integer", nullable: true),
legacy_region_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
issued_at = table.Column(type: "timestamp with time zone", nullable: true),
remark = table.Column(type: "text", nullable: true),
commission_rate = table.Column(type: "numeric(6,4)", precision: 6, scale: 4, nullable: true),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_code_batches", x => x.id);
table.UniqueConstraint("ak_code_batches_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_code_batches_amounts", "default_unit_price_cents >= 0 and cost_price_cents >= 0");
table.CheckConstraint("ck_code_batches_counts", "total_count >= 0");
table.ForeignKey(
name: "fk_code_batches_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "commerce_reconciliation_batches",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
created_by = table.Column(type: "uuid", nullable: true),
provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
bill_date = table.Column(type: "date", nullable: false),
bill_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
source = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
source_name = table.Column(type: "character varying(300)", maxLength: 300, nullable: true),
source_hash = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
total_count = table.Column(type: "integer", nullable: false),
matched_count = table.Column(type: "integer", nullable: false),
mismatch_count = table.Column(type: "integer", nullable: false),
missing_local_count = table.Column(type: "integer", nullable: false),
missing_provider_count = table.Column(type: "integer", nullable: false),
duplicate_count = table.Column(type: "integer", nullable: false),
ignored_count = table.Column(type: "integer", nullable: false),
amount_cents = table.Column(type: "integer", nullable: false),
refund_amount_cents = table.Column(type: "integer", nullable: false),
fee_cents = table.Column(type: "integer", nullable: false),
completed_at = table.Column(type: "timestamp with time zone", nullable: true),
error = table.Column(type: "text", nullable: true),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(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: "commission_settlements",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
referrer_user_id = table.Column(type: "uuid", nullable: false),
generated_by = table.Column(type: "uuid", nullable: true),
reviewed_by = table.Column(type: "uuid", nullable: true),
paid_by = table.Column(type: "uuid", nullable: true),
settlement_no = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
period_start = table.Column(type: "date", nullable: false),
period_end = table.Column(type: "date", nullable: false),
source_count = table.Column(type: "integer", nullable: false),
paid_user_count = table.Column(type: "integer", nullable: false),
gross_amount_cents = table.Column(type: "integer", nullable: false),
commission_amount_cents = table.Column(type: "integer", nullable: false),
default_rate = table.Column(type: "numeric(6,4)", precision: 6, scale: 4, nullable: false),
effective_rate = table.Column(type: "numeric(6,4)", precision: 6, scale: 4, nullable: true),
reviewed_at = table.Column(type: "timestamp with time zone", nullable: true),
paid_at = table.Column(type: "timestamp with time zone", nullable: true),
payment_method = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
payment_account = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
remark = table.Column(type: "text", nullable: true),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_commission_settlements", x => x.id);
table.UniqueConstraint("ak_commission_settlements_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_commission_settlements_amounts", "gross_amount_cents >= 0 and commission_amount_cents >= 0");
table.CheckConstraint("ck_commission_settlements_counts", "source_count >= 0 and paid_user_count >= 0");
table.CheckConstraint("ck_commission_settlements_period", "period_end >= period_start");
table.CheckConstraint("ck_commission_settlements_rates", "default_rate >= 0 and default_rate <= 1 and (effective_rate is null or (effective_rate >= 0 and effective_rate <= 1))");
table.ForeignKey(
name: "fk_commission_settlements_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_commission_settlements_users_generated_by",
column: x => x.generated_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "fk_commission_settlements_users_paid_by",
column: x => x.paid_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "fk_commission_settlements_users_referrer_user_id",
column: x => x.referrer_user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_commission_settlements_users_reviewed_by",
column: x => x.reviewed_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "crm_config",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
enabled = table.Column(type: "boolean", nullable: false),
url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
secret_ref = table.Column(type: "character varying(300)", maxLength: 300, nullable: true),
form_name = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
exam_type = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
timeout_seconds = table.Column(type: "integer", nullable: true),
delay_seconds = table.Column(type: "integer", nullable: true),
assignment_mode = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
assignment_pool = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
assignment_cursor = table.Column(type: "integer", nullable: false),
assignment_config = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_crm_config", x => x.id);
table.UniqueConstraint("ak_crm_config_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_crm_config_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "crm_webhook_log",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
record_id = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
lead_id = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
http_code = table.Column(type: "integer", nullable: true),
outcome = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
error_message = table.Column(type: "text", nullable: true),
request_body = table.Column(type: "text", nullable: true),
request_payload = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
response_summary = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true),
signed_at = table.Column(type: "timestamp with time zone", nullable: true),
attempt = table.Column(type: "integer", nullable: true),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_crm_webhook_log", x => x.id);
table.UniqueConstraint("ak_crm_webhook_log_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_crm_webhook_log_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "crm_webhook_queue",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
record_id = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
lead_id = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
source = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
provider = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
scheduled_at = table.Column(type: "timestamp with time zone", nullable: true),
attempts = table.Column