using System; using System.Text.Json; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Tiku.Infrastructure.Persistence.Migrations { /// public partial class AddPlatformBillingDunningAndAuditPersistence : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "platform_audit_alert_rules", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), tenant_id = table.Column(type: "uuid", nullable: true), 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), severity = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), action_patterns = table.Column(type: "text[]", nullable: false, defaultValueSql: "'{}'::text[]"), target_types = table.Column(type: "text[]", nullable: false, defaultValueSql: "'{}'::text[]"), conditions = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), 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_audit_alert_rules", x => x.id); table.ForeignKey( name: "fk_platform_audit_alert_rules_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); 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_billing_profiles", columns: table => new { tenant_id = table.Column(type: "uuid", nullable: false), billing_name = table.Column(type: "character varying(300)", maxLength: 300, nullable: true), tax_id = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), contact_name = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), contact_phone = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), contact_email = table.Column(type: "citext", maxLength: 300, nullable: true), billing_address = table.Column(type: "text", nullable: true), invoice_title = table.Column(type: "character varying(300)", maxLength: 300, nullable: true), invoice_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), bank_name = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), bank_account_masked = table.Column(type: "character varying(100)", maxLength: 100, 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_tenant_billing_profiles", x => x.tenant_id); table.ForeignKey( name: "fk_tenant_billing_profiles_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "tenant_invoices", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), created_by = table.Column(type: "uuid", nullable: true), invoice_no = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), invoice_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), currency = table.Column(type: "character varying(10)", maxLength: 10, nullable: false), subtotal_cents = table.Column(type: "integer", nullable: false), discount_cents = table.Column(type: "integer", nullable: false), tax_cents = table.Column(type: "integer", nullable: false), total_cents = table.Column(type: "integer", nullable: false), paid_cents = table.Column(type: "integer", nullable: false), balance_cents = table.Column(type: "integer", nullable: false), billing_period_start = table.Column(type: "date", nullable: true), billing_period_end = table.Column(type: "date", nullable: true), due_date = table.Column(type: "date", nullable: true), issued_at = table.Column(type: "timestamp with time zone", nullable: true), paid_at = table.Column(type: "timestamp with time zone", nullable: true), note = 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_tenant_invoices", x => x.id); table.UniqueConstraint("ak_tenant_invoices_tenant_id_id", x => new { x.tenant_id, x.id }); table.CheckConstraint("ck_tenant_invoices_amounts", "subtotal_cents >= 0 and discount_cents >= 0 and tax_cents >= 0 and total_cents >= 0 and paid_cents >= 0 and balance_cents >= 0"); table.CheckConstraint("ck_tenant_invoices_period", "billing_period_end is null or billing_period_start is null or billing_period_end >= billing_period_start"); table.ForeignKey( name: "fk_tenant_invoices_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_invoices_users_created_by", column: x => x.created_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "platform_audit_alerts", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), rule_id = table.Column(type: "uuid", nullable: false), audit_log_id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: true), acknowledged_by = table.Column(type: "uuid", nullable: true), resolved_by = table.Column(type: "uuid", nullable: true), severity = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), 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), title = table.Column(type: "character varying(300)", maxLength: 300, nullable: false), summary = table.Column(type: "text", nullable: true), details = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), first_seen_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), last_seen_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), acknowledged_at = table.Column(type: "timestamp with time zone", nullable: true), resolved_at = table.Column(type: "timestamp with time zone", nullable: true), resolution_note = table.Column(type: "text", 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_audit_alerts", x => x.id); table.ForeignKey( name: "fk_platform_audit_alerts_audit_logs_audit_log_id", column: x => x.audit_log_id, principalTable: "audit_logs", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_platform_audit_alerts_platform_audit_alert_rules_rule_id", column: x => x.rule_id, principalTable: "platform_audit_alert_rules", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_platform_audit_alerts_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_platform_audit_alerts_users_acknowledged_by", column: x => x.acknowledged_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_platform_audit_alerts_users_resolved_by", column: x => x.resolved_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "tenant_invoice_items", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), tenant_id = table.Column(type: "uuid", nullable: false), invoice_id = table.Column(type: "uuid", nullable: false), item_type = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), item_ref_id = table.Column(type: "uuid", nullable: true), description = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), quantity = table.Column(type: "numeric(12,2)", precision: 12, scale: 2, nullable: false), unit_amount_cents = table.Column(type: "integer", nullable: false), amount_cents = 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()") }, constraints: table => { table.PrimaryKey("pk_tenant_invoice_items", x => x.id); table.UniqueConstraint("ak_tenant_invoice_items_tenant_id_id", x => new { x.tenant_id, x.id }); table.CheckConstraint("ck_tenant_invoice_items_amounts", "unit_amount_cents >= 0 and amount_cents >= 0"); table.CheckConstraint("ck_tenant_invoice_items_quantity", "quantity > 0"); table.ForeignKey( name: "fk_tenant_invoice_items_tenant_invoices_tenant_id_invoice_id", columns: x => new { x.tenant_id, x.invoice_id }, principalTable: "tenant_invoices", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_invoice_items_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "tenant_invoice_payments", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), invoice_id = table.Column(type: "uuid", nullable: false), received_by = table.Column(type: "uuid", nullable: true), payment_no = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), method = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), amount_cents = table.Column(type: "integer", nullable: false), paid_at = table.Column(type: "timestamp with time zone", nullable: true), provider_trade_no = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), raw_payload = 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_tenant_invoice_payments", x => x.id); table.UniqueConstraint("ak_tenant_invoice_payments_tenant_id_id", x => new { x.tenant_id, x.id }); table.CheckConstraint("ck_tenant_invoice_payments_amount", "amount_cents >= 0"); table.ForeignKey( name: "fk_tenant_invoice_payments_tenant_invoices_tenant_id_invoice_id", columns: x => new { x.tenant_id, x.invoice_id }, principalTable: "tenant_invoices", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_invoice_payments_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_invoice_payments_users_received_by", column: x => x.received_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "tenant_invoice_reminders", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), invoice_id = table.Column(type: "uuid", nullable: false), created_by = table.Column(type: "uuid", nullable: true), reminder_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), channel = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), reminder_date = table.Column(type: "date", nullable: false), reminder_level = table.Column(type: "integer", nullable: false), due_date = table.Column(type: "date", nullable: true), balance_cents_snapshot = table.Column(type: "integer", nullable: false), message = table.Column(type: "text", nullable: true), metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), sent_at = table.Column(type: "timestamp with time zone", nullable: true), acknowledged_at = table.Column(type: "timestamp with time zone", 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_tenant_invoice_reminders", x => x.id); table.UniqueConstraint("ak_tenant_invoice_reminders_tenant_id_id", x => new { x.tenant_id, x.id }); table.CheckConstraint("ck_tenant_invoice_reminders_balance", "balance_cents_snapshot >= 0"); table.CheckConstraint("ck_tenant_invoice_reminders_level", "reminder_level between 1 and 20"); table.ForeignKey( name: "fk_tenant_invoice_reminders_tenant_invoices_tenant_id_invoice_~", columns: x => new { x.tenant_id, x.invoice_id }, principalTable: "tenant_invoices", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_invoice_reminders_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_invoice_reminders_users_created_by", column: x => x.created_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "platform_dunning_notification_events", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), channel_id = table.Column(type: "uuid", nullable: false), reminder_id = table.Column(type: "uuid", nullable: false), invoice_id = table.Column(type: "uuid", nullable: false), provider = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), attempts = table.Column(type: "integer", nullable: false), scheduled_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), next_attempt_at = table.Column(type: "timestamp with time zone", nullable: true), last_attempt_at = table.Column(type: "timestamp with time zone", nullable: true), sent_at = table.Column(type: "timestamp with time zone", nullable: true), last_error = table.Column(type: "text", nullable: true), last_http_code = table.Column(type: "integer", nullable: true), last_response_summary = table.Column(type: "text", nullable: true), request_payload = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), 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_platform_dunning_notification_events", x => x.id); table.UniqueConstraint("ak_platform_dunning_notification_events_tenant_id_id", x => new { x.tenant_id, x.id }); table.CheckConstraint("ck_platform_dunning_events_attempts", "attempts >= 0"); table.ForeignKey( name: "fk_platform_dunning_notification_events_platform_dunning_notif~", column: x => x.channel_id, principalTable: "platform_dunning_notification_channels", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_platform_dunning_notification_events_tenant_invoice_reminde~", columns: x => new { x.tenant_id, x.reminder_id }, principalTable: "tenant_invoice_reminders", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_platform_dunning_notification_events_tenant_invoices_tenant~", columns: x => new { x.tenant_id, x.invoice_id }, principalTable: "tenant_invoices", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_platform_dunning_notification_events_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "ix_platform_audit_alert_rules_code", table: "platform_audit_alert_rules", column: "code", unique: true); migrationBuilder.CreateIndex( name: "ix_platform_audit_alert_rules_enabled_severity_code", table: "platform_audit_alert_rules", columns: new[] { "enabled", "severity", "code" }); migrationBuilder.CreateIndex( name: "ix_platform_audit_alert_rules_tenant_id", table: "platform_audit_alert_rules", column: "tenant_id"); migrationBuilder.CreateIndex( name: "ix_platform_audit_alerts_acknowledged_by", table: "platform_audit_alerts", column: "acknowledged_by"); migrationBuilder.CreateIndex( name: "ix_platform_audit_alerts_audit_log_id", table: "platform_audit_alerts", column: "audit_log_id"); migrationBuilder.CreateIndex( name: "ix_platform_audit_alerts_resolved_by", table: "platform_audit_alerts", column: "resolved_by"); migrationBuilder.CreateIndex( name: "ix_platform_audit_alerts_rule_id_audit_log_id", table: "platform_audit_alerts", columns: new[] { "rule_id", "audit_log_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_platform_audit_alerts_status_severity_created_at", table: "platform_audit_alerts", columns: new[] { "status", "severity", "created_at" }); migrationBuilder.CreateIndex( name: "ix_platform_audit_alerts_tenant_id_status_created_at", table: "platform_audit_alerts", columns: new[] { "tenant_id", "status", "created_at" }); migrationBuilder.CreateIndex( name: "ix_platform_dunning_notification_channels_channel_code", table: "platform_dunning_notification_channels", column: "channel_code", unique: true); migrationBuilder.CreateIndex( name: "ix_platform_dunning_notification_channels_enabled_min_reminder~", table: "platform_dunning_notification_channels", columns: new[] { "enabled", "min_reminder_level", "channel_code" }); migrationBuilder.CreateIndex( name: "ix_platform_dunning_notification_events_channel_id_reminder_id", table: "platform_dunning_notification_events", columns: new[] { "channel_id", "reminder_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_platform_dunning_notification_events_invoice_id_status_crea~", table: "platform_dunning_notification_events", columns: new[] { "invoice_id", "status", "created_at" }); migrationBuilder.CreateIndex( name: "ix_platform_dunning_notification_events_reminder_id_status_cre~", table: "platform_dunning_notification_events", columns: new[] { "reminder_id", "status", "created_at" }); migrationBuilder.CreateIndex( name: "ix_platform_dunning_notification_events_status_next_attempt_at~", table: "platform_dunning_notification_events", columns: new[] { "status", "next_attempt_at", "scheduled_at", "created_at" }); migrationBuilder.CreateIndex( name: "ix_platform_dunning_notification_events_tenant_id_invoice_id", table: "platform_dunning_notification_events", columns: new[] { "tenant_id", "invoice_id" }); migrationBuilder.CreateIndex( name: "ix_platform_dunning_notification_events_tenant_id_reminder_id", table: "platform_dunning_notification_events", columns: new[] { "tenant_id", "reminder_id" }); migrationBuilder.CreateIndex( name: "ix_platform_dunning_notification_events_tenant_id_status_creat~", table: "platform_dunning_notification_events", columns: new[] { "tenant_id", "status", "created_at" }); migrationBuilder.CreateIndex( name: "ix_platform_saas_plans_code", table: "platform_saas_plans", column: "code", unique: true); migrationBuilder.CreateIndex( name: "ix_platform_saas_plans_status_sort_order", table: "platform_saas_plans", columns: new[] { "status", "sort_order" }); migrationBuilder.CreateIndex( name: "ix_tenant_invoice_items_invoice_id", table: "tenant_invoice_items", column: "invoice_id"); migrationBuilder.CreateIndex( name: "ix_tenant_invoice_items_tenant_id_invoice_id", table: "tenant_invoice_items", columns: new[] { "tenant_id", "invoice_id" }); migrationBuilder.CreateIndex( name: "ix_tenant_invoice_payments_invoice_id_status", table: "tenant_invoice_payments", columns: new[] { "invoice_id", "status" }); migrationBuilder.CreateIndex( name: "ix_tenant_invoice_payments_payment_no", table: "tenant_invoice_payments", column: "payment_no", unique: true); migrationBuilder.CreateIndex( name: "ix_tenant_invoice_payments_received_by", table: "tenant_invoice_payments", column: "received_by"); migrationBuilder.CreateIndex( name: "ix_tenant_invoice_payments_tenant_id_invoice_id", table: "tenant_invoice_payments", columns: new[] { "tenant_id", "invoice_id" }); migrationBuilder.CreateIndex( name: "ix_tenant_invoice_reminders_created_by", table: "tenant_invoice_reminders", column: "created_by"); migrationBuilder.CreateIndex( name: "ix_tenant_invoice_reminders_invoice_id_reminder_date", table: "tenant_invoice_reminders", columns: new[] { "invoice_id", "reminder_date" }); migrationBuilder.CreateIndex( name: "ix_tenant_invoice_reminders_tenant_id_invoice_id_reminder_type~", table: "tenant_invoice_reminders", columns: new[] { "tenant_id", "invoice_id", "reminder_type", "channel", "reminder_date" }, unique: true); migrationBuilder.CreateIndex( name: "ix_tenant_invoice_reminders_tenant_id_status_reminder_date", table: "tenant_invoice_reminders", columns: new[] { "tenant_id", "status", "reminder_date" }); migrationBuilder.CreateIndex( name: "ix_tenant_invoices_created_by", table: "tenant_invoices", column: "created_by"); migrationBuilder.CreateIndex( name: "ix_tenant_invoices_invoice_no", table: "tenant_invoices", column: "invoice_no", unique: true); migrationBuilder.CreateIndex( name: "ix_tenant_invoices_tenant_id_billing_period_start_billing_peri~", table: "tenant_invoices", columns: new[] { "tenant_id", "billing_period_start", "billing_period_end" }, unique: true, filter: "invoice_type = 'usage_overage' and status <> 'void' and metadata->>'source' = 'usage_overage_auto'"); migrationBuilder.CreateIndex( name: "ix_tenant_invoices_tenant_id_status_due_date", table: "tenant_invoices", columns: new[] { "tenant_id", "status", "due_date" }); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "platform_audit_alerts"); migrationBuilder.DropTable( name: "platform_dunning_notification_events"); migrationBuilder.DropTable( name: "platform_saas_plans"); migrationBuilder.DropTable( name: "tenant_billing_profiles"); migrationBuilder.DropTable( name: "tenant_invoice_items"); migrationBuilder.DropTable( name: "tenant_invoice_payments"); migrationBuilder.DropTable( name: "platform_audit_alert_rules"); migrationBuilder.DropTable( name: "platform_dunning_notification_channels"); migrationBuilder.DropTable( name: "tenant_invoice_reminders"); migrationBuilder.DropTable( name: "tenant_invoices"); } } }