using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#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: "backend_permissions",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
code = table.Column(type: "character varying(160)", maxLength: 160, nullable: false),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
area = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
module = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true),
is_system = table.Column(type: "boolean", 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_backend_permissions", x => x.id);
table.UniqueConstraint("ak_backend_permissions_code", x => x.code);
});
migrationBuilder.CreateTable(
name: "data_protection_keys",
columns: table => new
{
id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
friendly_name = table.Column(type: "text", nullable: true),
xml = table.Column(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_data_protection_keys", x => x.id);
});
migrationBuilder.CreateTable(
name: "platform_backend_roles",
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),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
is_system = table.Column(type: "boolean", nullable: false),
description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true),
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_backend_roles", x => x.id);
});
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),
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),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
force_password_change = 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()"),
user_name = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
normalized_user_name = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
email = table.Column(type: "citext", maxLength: 320, nullable: true),
normalized_email = table.Column(type: "character varying(320)", maxLength: 320, nullable: true),
email_confirmed = table.Column(type: "boolean", nullable: false),
password_hash = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
security_stamp = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
concurrency_stamp = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
phone_number = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
phone_number_confirmed = table.Column(type: "boolean", nullable: false),
two_factor_enabled = table.Column(type: "boolean", nullable: false),
lockout_end = table.Column(type: "timestamp with time zone", nullable: true),
lockout_enabled = table.Column(type: "boolean", nullable: false),
access_failed_count = table.Column(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_users", x => x.id);
});
migrationBuilder.CreateTable(
name: "backend_menus",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
code = table.Column(type: "character varying(160)", maxLength: 160, nullable: false),
parent_code = table.Column(type: "character varying(160)", maxLength: 160, nullable: true),
title = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
area = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
path = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
icon = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
permission_code = table.Column(type: "character varying(160)", maxLength: 160, nullable: true),
sort_order = table.Column(type: "integer", nullable: false),
is_active = table.Column(type: "boolean", 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_backend_menus", x => x.id);
table.UniqueConstraint("ak_backend_menus_code", x => x.code);
table.ForeignKey(
name: "fk_backend_menus_backend_permissions_permission_code",
column: x => x.permission_code,
principalTable: "backend_permissions",
principalColumn: "code",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "platform_backend_role_permissions",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
role_id = table.Column(type: "uuid", nullable: false),
permission_code = table.Column(type: "character varying(160)", maxLength: 160, nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_platform_backend_role_permissions", x => x.id);
table.ForeignKey(
name: "fk_platform_backend_role_permissions_backend_permissions_permi~",
column: x => x.permission_code,
principalTable: "backend_permissions",
principalColumn: "code",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_platform_backend_role_permissions_platform_backend_roles_ro~",
column: x => x.role_id,
principalTable: "platform_backend_roles",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "platform_backend_user_roles",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column(type: "uuid", nullable: false),
role_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_platform_backend_user_roles", x => x.id);
table.ForeignKey(
name: "fk_platform_backend_user_roles_platform_backend_roles_role_id",
column: x => x.role_id,
principalTable: "platform_backend_roles",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_platform_backend_user_roles_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
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_claims",
columns: table => new
{
id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
user_id = table.Column(type: "uuid", nullable: false),
claim_type = table.Column(type: "text", nullable: true),
claim_value = table.Column(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_user_claims", x => x.id);
table.ForeignKey(
name: "fk_user_claims_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
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),
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: "user_logins",
columns: table => new
{
login_provider = table.Column(type: "text", nullable: false),
provider_key = table.Column(type: "text", nullable: false),
provider_display_name = table.Column(type: "text", nullable: true),
user_id = table.Column(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_user_logins", x => new { x.login_provider, x.provider_key });
table.ForeignKey(
name: "fk_user_logins_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "user_tokens",
columns: table => new
{
user_id = table.Column(type: "uuid", nullable: false),
login_provider = table.Column(type: "text", nullable: false),
name = table.Column(type: "text", nullable: false),
value = table.Column(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_user_tokens", x => new { x.user_id, x.login_provider, x.name });
table.ForeignKey(
name: "fk_user_tokens_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "platform_backend_role_menus",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
role_id = table.Column(type: "uuid", nullable: false),
menu_code = table.Column(type: "character varying(160)", maxLength: 160, nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_platform_backend_role_menus", x => x.id);
table.ForeignKey(
name: "fk_platform_backend_role_menus_backend_menus_menu_code",
column: x => x.menu_code,
principalTable: "backend_menus",
principalColumn: "code",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_platform_backend_role_menus_platform_backend_roles_role_id",
column: x => x.role_id,
principalTable: "platform_backend_roles",
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: true),
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: true),
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_challenges",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column(type: "uuid", nullable: false),
realm = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
tenant_id = table.Column(type: "uuid", nullable: true),
purpose = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
token_hash = table.Column(type: "character varying(64)", maxLength: 64, nullable: false),
security_stamp = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
expires_at = table.Column(type: "timestamp with time zone", nullable: false),
consumed_at = table.Column(type: "timestamp with time zone", nullable: true),
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_auth_challenges", x => x.id);
table.CheckConstraint("ck_auth_challenges_realm_tenant", "(realm = 'tenant' and tenant_id is not null) or (realm = 'platform' and tenant_id is null)");
table.ForeignKey(
name: "fk_auth_challenges_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_auth_challenges_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
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: true),
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.ForeignKey(
name: "fk_auth_login_events_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
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()"),
realm = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
tenant_id = table.Column(type: "uuid", nullable: true),
user_id = table.Column(type: "uuid", nullable: false),
token_family_id = table.Column(type: "uuid", nullable: false),
parent_session_id = table.Column(type: "uuid", nullable: true),
replaced_by_session_id = table.Column(type: "uuid", nullable: true),
token_hash = table.Column(type: "character varying(256)", maxLength: 256, nullable: false),
security_stamp = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
mfa_satisfied = table.Column(type: "boolean", 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),
revoked_reason = 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()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_auth_sessions", x => x.id);
table.CheckConstraint("ck_auth_sessions_realm_tenant", "(realm = 'tenant' and tenant_id is not null) or (realm = 'platform' and tenant_id is null)");
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