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: "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: "inbox_state",
columns: table => new
{
id = table.Column(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
message_id = table.Column(type: "uuid", nullable: false),
consumer_id = table.Column(type: "uuid", nullable: false),
lock_id = table.Column(type: "uuid", nullable: false),
row_version = table.Column(type: "bytea", rowVersion: true, nullable: true),
received = table.Column(type: "timestamp with time zone", nullable: false),
receive_count = table.Column(type: "integer", nullable: false),
expiration_time = table.Column(type: "timestamp with time zone", nullable: true),
consumed = table.Column(type: "timestamp with time zone", nullable: true),
delivered = table.Column(type: "timestamp with time zone", nullable: true),
last_sequence_number = table.Column(type: "bigint", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_inbox_state", x => x.id);
table.UniqueConstraint("ak_inbox_state_message_id_consumer_id", x => new { x.message_id, x.consumer_id });
});
migrationBuilder.CreateTable(
name: "outbox_state",
columns: table => new
{
outbox_id = table.Column(type: "uuid", nullable: false),
lock_id = table.Column(type: "uuid", nullable: false),
row_version = table.Column(type: "bytea", rowVersion: true, nullable: true),
created = table.Column(type: "timestamp with time zone", nullable: false),
delivered = table.Column(type: "timestamp with time zone", nullable: true),
last_sequence_number = table.Column(type: "bigint", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_outbox_state", x => x.outbox_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_billing_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_billing_dunning_notification_channels", x => x.id);
table.CheckConstraint("ck_platform_billing_dunning_channels_level", "min_reminder_level between 1 and 20");
table.CheckConstraint("ck_platform_billing_dunning_channels_timeout", "timeout_seconds between 1 and 60");
});
migrationBuilder.CreateTable(
name: "saas_features",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
code = table.Column(type: "character varying(120)", maxLength: 120, nullable: false),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
category = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true),
reference_price_cents = table.Column(type: "integer", nullable: false),
currency = table.Column(type: "character varying(10)", maxLength: 10, nullable: false),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
is_core = 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_saas_features", x => x.id);
table.UniqueConstraint("ak_saas_features_code", x => x.code);
table.CheckConstraint("ck_saas_features_reference_price", "reference_price_cents >= 0");
});
migrationBuilder.CreateTable(
name: "saas_offerings",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
code = table.Column(type: "character varying(120)", maxLength: 120, nullable: false),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true),
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_saas_offerings", x => x.id);
});
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: "outbox_message",
columns: table => new
{
sequence_number = table.Column(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
enqueue_time = table.Column(type: "timestamp with time zone", nullable: true),
sent_time = table.Column(type: "timestamp with time zone", nullable: false),
headers = table.Column(type: "text", nullable: true),
properties = table.Column(type: "text", nullable: true),
inbox_message_id = table.Column(type: "uuid", nullable: true),
inbox_consumer_id = table.Column(type: "uuid", nullable: true),
outbox_id = table.Column(type: "uuid", nullable: true),
message_id = table.Column(type: "uuid", nullable: false),
content_type = table.Column(type: "character varying(256)", maxLength: 256, nullable: false),
message_type = table.Column(type: "text", nullable: false),
body = table.Column(type: "text", nullable: false),
conversation_id = table.Column(type: "uuid", nullable: true),
correlation_id = table.Column(type: "uuid", nullable: true),
initiator_id = table.Column(type: "uuid", nullable: true),
request_id = table.Column(type: "uuid", nullable: true),
source_address = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
destination_address = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
response_address = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
fault_address = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
expiration_time = table.Column(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_outbox_message", x => x.sequence_number);
table.ForeignKey(
name: "fk_outbox_message_inbox_state_inbox_message_id_inbox_consumer_~",
columns: x => new { x.inbox_message_id, x.inbox_consumer_id },
principalTable: "inbox_state",
principalColumns: new[] { "message_id", "consumer_id" });
table.ForeignKey(
name: "fk_outbox_message_outbox_state_outbox_id",
column: x => x.outbox_id,
principalTable: "outbox_state",
principalColumn: "outbox_id");
});
migrationBuilder.CreateTable(
name: "permission_modules",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
code = table.Column(type: "character varying(120)", maxLength: 120, nullable: false),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
area = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
required_feature_code = table.Column(type: "character varying(120)", maxLength: 120, nullable: true),
description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true),
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_permission_modules", x => x.id);
table.UniqueConstraint("ak_permission_modules_code", x => x.code);
table.ForeignKey(
name: "fk_permission_modules_saas_features_required_feature_code",
column: x => x.required_feature_code,
principalTable: "saas_features",
principalColumn: "code",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "saas_feature_limit_definitions",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
metric_code = table.Column(type: "character varying(120)", maxLength: 120, nullable: false),
feature_code = table.Column(type: "character varying(120)", maxLength: 120, nullable: false),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
unit = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
kind = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
warning_percent = table.Column(type: "integer", nullable: false),
is_hard_limit = 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_saas_feature_limit_definitions", x => x.id);
table.UniqueConstraint("ak_saas_feature_limit_definitions_metric_code", x => x.metric_code);
table.CheckConstraint("ck_saas_feature_limit_warning", "warning_percent between 1 and 100");
table.ForeignKey(
name: "fk_saas_feature_limit_definitions_saas_features_feature_code",
column: x => x.feature_code,
principalTable: "saas_features",
principalColumn: "code",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "saas_offering_versions",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
offering_id = table.Column(type: "uuid", nullable: false),
version = table.Column(type: "integer", nullable: false),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
billing_cycle = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
original_amount_cents = table.Column(type: "integer", nullable: false),
amount_cents = table.Column(type: "integer", nullable: false),
currency = table.Column(type: "character varying(10)", maxLength: 10, nullable: false),
effective_at = table.Column(type: "timestamp with time zone", nullable: true),
published_at = table.Column(type: "timestamp with time zone", nullable: true),
retired_at = table.Column(type: "timestamp with time zone", 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_saas_offering_versions", x => x.id);
table.CheckConstraint("ck_saas_offering_versions_amount", "original_amount_cents >= 0 and amount_cents >= 0 and amount_cents <= original_amount_cents");
table.CheckConstraint("ck_saas_offering_versions_version", "version > 0");
table.ForeignKey(
name: "fk_saas_offering_versions_saas_offerings_offering_id",
column: x => x.offering_id,
principalTable: "saas_offerings",
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: "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),
permission_module_code = table.Column(type: "character varying(120)", maxLength: 120, 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);
table.ForeignKey(
name: "fk_backend_permissions_permission_modules_permission_module_co~",
column: x => x.permission_module_code,
principalTable: "permission_modules",
principalColumn: "code",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "saas_offering_version_features",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
offering_version_id = table.Column(type: "uuid", nullable: false),
feature_code = table.Column(type: "character varying(120)", maxLength: 120, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_saas_offering_version_features", x => x.id);
table.ForeignKey(
name: "fk_saas_offering_version_features_saas_features_feature_code",
column: x => x.feature_code,
principalTable: "saas_features",
principalColumn: "code",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_saas_offering_version_features_saas_offering_versions_offer~",
column: x => x.offering_version_id,
principalTable: "saas_offering_versions",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "saas_offering_version_limits",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
offering_version_id = table.Column(type: "uuid", nullable: false),
metric_code = table.Column(type: "character varying(120)", maxLength: 120, nullable: false),
limit_value = table.Column(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_saas_offering_version_limits", x => x.id);
table.CheckConstraint("ck_saas_offering_version_limits_value", "limit_value >= 0");
table.ForeignKey(
name: "fk_saas_offering_version_limits_saas_feature_limit_definitions~",
column: x => x.metric_code,
principalTable: "saas_feature_limit_definitions",
principalColumn: "metric_code",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_saas_offering_version_limits_saas_offering_versions_offerin~",
column: x => x.offering_version_id,
principalTable: "saas_offering_versions",
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_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