using System; using System.Text.Json; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Tiku.Infrastructure.Persistence.Migrations { /// public partial class AddOperationsContentAndAuditPersistence : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { 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: "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: "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: "banners", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), region_id = table.Column(type: "uuid", nullable: true), legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), title = table.Column(type: "character varying(300)", maxLength: 300, nullable: true), subtitle = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), content = table.Column(type: "text", nullable: true), button_text = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), button_link = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), background_color = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), border_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_banners", x => x.id); table.UniqueConstraint("ak_banners_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_banners_regions_tenant_id_region_id", columns: x => new { x.tenant_id, x.region_id }, principalTable: "regions", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "fk_banners_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "faqs", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), region_id = table.Column(type: "uuid", nullable: true), legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), question = table.Column(type: "text", nullable: true), answer = table.Column(type: "text", 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_faqs", x => x.id); table.UniqueConstraint("ak_faqs_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_faqs_regions_tenant_id_region_id", columns: x => new { x.tenant_id, x.region_id }, principalTable: "regions", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "fk_faqs_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "tenant_content_notifications", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), adoption_id = table.Column(type: "uuid", nullable: true), source_question_bank_id = table.Column(type: "uuid", nullable: true), created_by = table.Column(type: "uuid", nullable: true), read_by = table.Column(type: "uuid", nullable: true), notification_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), severity = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), title = table.Column(type: "character varying(300)", maxLength: 300, nullable: false), message = table.Column(type: "text", nullable: false), action_label = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), action_path = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), dedupe_key = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), read_at = table.Column(type: "timestamp with time zone", nullable: true), resolved_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_content_notifications", x => x.id); table.UniqueConstraint("ak_tenant_content_notifications_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_tenant_content_notifications_question_banks_tenant_id_sourc~", columns: x => new { x.tenant_id, x.source_question_bank_id }, principalTable: "question_banks", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_content_notifications_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_content_notifications_users_created_by", column: x => x.created_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_tenant_content_notifications_users_read_by", column: x => x.read_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); }); 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: "user_notifications", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), user_id = table.Column(type: "uuid", nullable: false), source_id = table.Column(type: "uuid", nullable: true), created_by = table.Column(type: "uuid", nullable: true), notification_type = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), severity = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), title = table.Column(type: "character varying(300)", maxLength: 300, nullable: false), message = table.Column(type: "text", nullable: false), action_label = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), action_path = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), source_type = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), dedupe_key = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), read_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_user_notifications", x => x.id); table.UniqueConstraint("ak_user_notifications_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_user_notifications_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_user_notifications_users_created_by", column: x => x.created_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_user_notifications_users_user_id", column: x => x.user_id, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "user_badges", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), user_id = table.Column(type: "uuid", nullable: true), badge_id = table.Column(type: "uuid", nullable: true), granted_by = table.Column(type: "uuid", nullable: true), legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), note = table.Column(type: "text", nullable: true), granted_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_user_badges", x => x.id); table.UniqueConstraint("ak_user_badges_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_user_badges_badges_tenant_id_badge_id", columns: x => new { x.tenant_id, x.badge_id }, principalTable: "badges", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_user_badges_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_user_badges_users_granted_by", column: x => x.granted_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_user_badges_users_user_id", column: x => x.user_id, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "tenant_theme_configs", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), active_template_code = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), active_theme = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), active_public_assets = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), draft_template_code = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), draft_theme = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), draft_public_assets = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), published_at = table.Column(type: "timestamp with time zone", nullable: true), published_by = table.Column(type: "uuid", nullable: true), draft_updated_by = table.Column(type: "uuid", 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_theme_configs", x => x.id); table.UniqueConstraint("ak_tenant_theme_configs_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_tenant_theme_configs_tenant_theme_templates_active_template~", column: x => x.active_template_code, principalTable: "tenant_theme_templates", principalColumn: "code", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_tenant_theme_configs_tenant_theme_templates_draft_template_~", column: x => x.draft_template_code, principalTable: "tenant_theme_templates", principalColumn: "code", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_tenant_theme_configs_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_theme_configs_users_draft_updated_by", column: x => x.draft_updated_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_tenant_theme_configs_users_published_by", column: x => x.published_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateIndex( name: "ix_announcements_tenant_id_is_active_sort_order", table: "announcements", columns: new[] { "tenant_id", "is_active", "sort_order" }); migrationBuilder.CreateIndex( name: "ix_announcements_tenant_id_legacy_id", table: "announcements", columns: new[] { "tenant_id", "legacy_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_audit_logs_actor_user_id", table: "audit_logs", column: "actor_user_id"); migrationBuilder.CreateIndex( name: "ix_audit_logs_tenant_id_created_at", table: "audit_logs", columns: new[] { "tenant_id", "created_at" }); migrationBuilder.CreateIndex( name: "ix_audit_logs_tenant_id_target_type_target_id_created_at", table: "audit_logs", columns: new[] { "tenant_id", "target_type", "target_id", "created_at" }); migrationBuilder.CreateIndex( name: "ix_badges_tenant_id_category_is_active_sort_order", table: "badges", columns: new[] { "tenant_id", "category", "is_active", "sort_order" }); migrationBuilder.CreateIndex( name: "ix_badges_tenant_id_legacy_id", table: "badges", columns: new[] { "tenant_id", "legacy_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_banners_tenant_id_legacy_id", table: "banners", columns: new[] { "tenant_id", "legacy_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_banners_tenant_id_region_id_is_active_sort_order", table: "banners", columns: new[] { "tenant_id", "region_id", "is_active", "sort_order" }); migrationBuilder.CreateIndex( name: "ix_faqs_tenant_id_legacy_id", table: "faqs", columns: new[] { "tenant_id", "legacy_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_faqs_tenant_id_region_id_is_active_sort_order", table: "faqs", columns: new[] { "tenant_id", "region_id", "is_active", "sort_order" }); migrationBuilder.CreateIndex( name: "ix_tenant_content_notifications_created_by", table: "tenant_content_notifications", column: "created_by"); migrationBuilder.CreateIndex( name: "ix_tenant_content_notifications_read_by", table: "tenant_content_notifications", column: "read_by"); migrationBuilder.CreateIndex( name: "ix_tenant_content_notifications_tenant_id_adoption_id_notifica~", table: "tenant_content_notifications", columns: new[] { "tenant_id", "adoption_id", "notification_type", "status" }); migrationBuilder.CreateIndex( name: "ix_tenant_content_notifications_tenant_id_notification_type_de~", table: "tenant_content_notifications", columns: new[] { "tenant_id", "notification_type", "dedupe_key" }, unique: true, filter: "dedupe_key is not null"); migrationBuilder.CreateIndex( name: "ix_tenant_content_notifications_tenant_id_source_question_bank~", table: "tenant_content_notifications", columns: new[] { "tenant_id", "source_question_bank_id" }); migrationBuilder.CreateIndex( name: "ix_tenant_content_notifications_tenant_id_status_created_at", table: "tenant_content_notifications", columns: new[] { "tenant_id", "status", "created_at" }); migrationBuilder.CreateIndex( name: "ix_tenant_theme_configs_active_template_code", table: "tenant_theme_configs", column: "active_template_code"); migrationBuilder.CreateIndex( name: "ix_tenant_theme_configs_draft_template_code", table: "tenant_theme_configs", column: "draft_template_code"); migrationBuilder.CreateIndex( name: "ix_tenant_theme_configs_draft_updated_by", table: "tenant_theme_configs", column: "draft_updated_by"); migrationBuilder.CreateIndex( name: "ix_tenant_theme_configs_published_by", table: "tenant_theme_configs", column: "published_by"); migrationBuilder.CreateIndex( name: "ix_tenant_theme_configs_tenant_id", table: "tenant_theme_configs", column: "tenant_id", unique: true); migrationBuilder.CreateIndex( name: "ix_tenant_theme_templates_code", table: "tenant_theme_templates", column: "code", unique: true); migrationBuilder.CreateIndex( name: "ix_tenant_theme_templates_status_sort_order_code", table: "tenant_theme_templates", columns: new[] { "status", "sort_order", "code" }); migrationBuilder.CreateIndex( name: "ix_user_badges_granted_by", table: "user_badges", column: "granted_by"); migrationBuilder.CreateIndex( name: "ix_user_badges_tenant_id_badge_id", table: "user_badges", columns: new[] { "tenant_id", "badge_id" }); migrationBuilder.CreateIndex( name: "ix_user_badges_tenant_id_legacy_id", table: "user_badges", columns: new[] { "tenant_id", "legacy_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_user_badges_tenant_id_user_id_badge_id", table: "user_badges", columns: new[] { "tenant_id", "user_id", "badge_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_user_badges_user_id", table: "user_badges", column: "user_id"); migrationBuilder.CreateIndex( name: "ix_user_notifications_created_by", table: "user_notifications", column: "created_by"); migrationBuilder.CreateIndex( name: "ix_user_notifications_tenant_id_source_type_source_id", table: "user_notifications", columns: new[] { "tenant_id", "source_type", "source_id" }); migrationBuilder.CreateIndex( name: "ix_user_notifications_tenant_id_user_id_notification_type_dedu~", table: "user_notifications", columns: new[] { "tenant_id", "user_id", "notification_type", "dedupe_key" }, unique: true, filter: "dedupe_key is not null"); migrationBuilder.CreateIndex( name: "ix_user_notifications_tenant_id_user_id_status_created_at", table: "user_notifications", columns: new[] { "tenant_id", "user_id", "status", "created_at" }); migrationBuilder.CreateIndex( name: "ix_user_notifications_user_id", table: "user_notifications", column: "user_id"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "announcements"); migrationBuilder.DropTable( name: "audit_logs"); migrationBuilder.DropTable( name: "banners"); migrationBuilder.DropTable( name: "faqs"); migrationBuilder.DropTable( name: "tenant_content_notifications"); migrationBuilder.DropTable( name: "tenant_theme_configs"); migrationBuilder.DropTable( name: "user_badges"); migrationBuilder.DropTable( name: "user_notifications"); migrationBuilder.DropTable( name: "tenant_theme_templates"); migrationBuilder.DropTable( name: "badges"); } } }