using System; using System.Text.Json; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Tiku.Infrastructure.Persistence.Migrations { /// public partial class AddAuthAndTenantOperationsPersistence : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "role_template_id", table: "tenant_memberships", type: "uuid", nullable: true); migrationBuilder.CreateTable( name: "auth_login_events", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), tenant_id = table.Column(type: "uuid", nullable: false), user_id = table.Column(type: "uuid", nullable: true), provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), identifier = table.Column(type: "character varying(320)", maxLength: 320, nullable: true), result = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), failure_code = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), ip_address = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), user_agent = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true), metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()") }, constraints: table => { table.PrimaryKey("pk_auth_login_events", x => x.id); table.UniqueConstraint("ak_auth_login_events_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_auth_login_events_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_auth_login_events_users_user_id", column: x => x.user_id, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "auth_sessions", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), user_id = table.Column(type: "uuid", nullable: false), token_hash = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), expires_at = table.Column(type: "timestamp with time zone", nullable: false), revoked_at = table.Column(type: "timestamp with time zone", nullable: true), ip_address = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), user_agent = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true), metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), tenant_id = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()") }, constraints: table => { table.PrimaryKey("pk_auth_sessions", x => x.id); table.UniqueConstraint("ak_auth_sessions_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_auth_sessions_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_auth_sessions_users_user_id", column: x => x.user_id, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "sms_send_rate_limits", columns: table => new { tenant_id = table.Column(type: "uuid", nullable: false), dimension = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), scope_hash = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), bucket_start = table.Column(type: "timestamp with time zone", nullable: false), request_count = table.Column(type: "integer", nullable: false, defaultValue: 0), updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()") }, constraints: table => { table.PrimaryKey("pk_sms_send_rate_limits", x => new { x.tenant_id, x.dimension, x.scope_hash, x.bucket_start }); table.CheckConstraint("ck_sms_send_rate_limits_request_count", "request_count >= 0"); table.ForeignKey( name: "fk_sms_send_rate_limits_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "sms_verification_codes", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), tenant_id = table.Column(type: "uuid", nullable: false), phone = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), purpose = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), code_hash = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), attempts = table.Column(type: "integer", 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(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_sms_verification_codes", x => x.id); table.UniqueConstraint("ak_sms_verification_codes_tenant_id_id", x => new { x.tenant_id, x.id }); table.CheckConstraint("ck_sms_verification_codes_attempts", "attempts >= 0"); table.ForeignKey( name: "fk_sms_verification_codes_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "tenant_auth_providers", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), display_name = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), config_public = 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_auth_providers", x => x.id); table.UniqueConstraint("ak_tenant_auth_providers_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_tenant_auth_providers_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "tenant_classes", 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), code = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), description = table.Column(type: "text", nullable: true), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), sort_order = table.Column(type: "integer", nullable: false), metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), created_by = table.Column(type: "uuid", nullable: true), 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_classes", x => x.id); table.UniqueConstraint("ak_tenant_classes_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_tenant_classes_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_tenant_classes_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_classes_users_created_by", column: x => x.created_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_tenant_classes_users_updated_by", column: x => x.updated_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "tenant_role_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), base_role = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), permissions = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), menu_permissions = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), module_permissions = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), field_permissions = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), data_scope = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), is_system = table.Column(type: "boolean", nullable: false), sort_order = table.Column(type: "integer", nullable: false), created_by = table.Column(type: "uuid", nullable: true), 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_role_templates", x => x.id); table.UniqueConstraint("ak_tenant_role_templates_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_tenant_role_templates_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_role_templates_users_created_by", column: x => x.created_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_tenant_role_templates_users_updated_by", column: x => x.updated_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "tenant_student_notes", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), student_user_id = table.Column(type: "uuid", nullable: false), note_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), content = table.Column(type: "text", nullable: false), visibility = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), is_pinned = table.Column(type: "boolean", nullable: false), metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), created_by = table.Column(type: "uuid", nullable: true), 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_student_notes", x => x.id); table.UniqueConstraint("ak_tenant_student_notes_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_tenant_student_notes_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_student_notes_users_created_by", column: x => x.created_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_tenant_student_notes_users_student_user_id", column: x => x.student_user_id, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_student_notes_users_updated_by", column: x => x.updated_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "tenant_class_members", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), class_id = table.Column(type: "uuid", nullable: false), user_id = table.Column(type: "uuid", nullable: false), member_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), joined_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), left_at = table.Column(type: "timestamp with time zone", nullable: true), metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), created_by = table.Column(type: "uuid", nullable: true), 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_class_members", x => x.id); table.UniqueConstraint("ak_tenant_class_members_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_tenant_class_members_tenant_classes_tenant_id_class_id", columns: x => new { x.tenant_id, x.class_id }, principalTable: "tenant_classes", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_class_members_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_class_members_users_user_id", column: x => x.user_id, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "tenant_student_followups", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), student_user_id = table.Column(type: "uuid", nullable: false), assigned_to_user_id = table.Column(type: "uuid", nullable: true), class_id = table.Column(type: "uuid", nullable: true), title = table.Column(type: "character varying(300)", maxLength: 300, nullable: false), description = table.Column(type: "text", nullable: true), followup_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), priority = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), due_at = table.Column(type: "timestamp with time zone", nullable: true), completed_at = table.Column(type: "timestamp with time zone", nullable: true), completed_by = table.Column(type: "uuid", nullable: true), metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), created_by = table.Column(type: "uuid", nullable: true), 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_student_followups", x => x.id); table.UniqueConstraint("ak_tenant_student_followups_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_tenant_student_followups_tenant_classes_tenant_id_class_id", columns: x => new { x.tenant_id, x.class_id }, principalTable: "tenant_classes", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_tenant_student_followups_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "fk_tenant_student_followups_users_assigned_to_user_id", column: x => x.assigned_to_user_id, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_tenant_student_followups_users_completed_by", column: x => x.completed_by, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "fk_tenant_student_followups_users_student_user_id", column: x => x.student_user_id, principalTable: "users", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "ix_tenant_memberships_tenant_id_role_template_id", table: "tenant_memberships", columns: new[] { "tenant_id", "role_template_id" }); migrationBuilder.CreateIndex( name: "ix_auth_login_events_tenant_id_user_id_created_at", table: "auth_login_events", columns: new[] { "tenant_id", "user_id", "created_at" }); migrationBuilder.CreateIndex( name: "ix_auth_login_events_user_id", table: "auth_login_events", column: "user_id"); migrationBuilder.CreateIndex( name: "ix_auth_sessions_tenant_id_user_id_expires_at", table: "auth_sessions", columns: new[] { "tenant_id", "user_id", "expires_at" }, filter: "revoked_at is null"); migrationBuilder.CreateIndex( name: "ix_auth_sessions_token_hash", table: "auth_sessions", column: "token_hash", unique: true); migrationBuilder.CreateIndex( name: "ix_auth_sessions_user_id", table: "auth_sessions", column: "user_id"); migrationBuilder.CreateIndex( name: "ix_sms_send_rate_limits_updated_at", table: "sms_send_rate_limits", column: "updated_at"); migrationBuilder.CreateIndex( name: "ix_sms_verification_codes_tenant_id_phone_purpose", table: "sms_verification_codes", columns: new[] { "tenant_id", "phone", "purpose" }, unique: true, filter: "consumed_at is null and status in ('pending', 'sent')"); migrationBuilder.CreateIndex( name: "ix_sms_verification_codes_tenant_id_phone_purpose_created_at", table: "sms_verification_codes", columns: new[] { "tenant_id", "phone", "purpose", "created_at" }, filter: "consumed_at is null and status in ('pending', 'sent')"); migrationBuilder.CreateIndex( name: "ix_sms_verification_codes_tenant_id_phone_purpose_expires_at", table: "sms_verification_codes", columns: new[] { "tenant_id", "phone", "purpose", "expires_at" }); migrationBuilder.CreateIndex( name: "ix_tenant_auth_providers_tenant_id_provider", table: "tenant_auth_providers", columns: new[] { "tenant_id", "provider" }, unique: true); migrationBuilder.CreateIndex( name: "ix_tenant_auth_providers_tenant_id_provider_status", table: "tenant_auth_providers", columns: new[] { "tenant_id", "provider", "status" }); migrationBuilder.CreateIndex( name: "ix_tenant_class_members_tenant_id_class_id_status_member_type", table: "tenant_class_members", columns: new[] { "tenant_id", "class_id", "status", "member_type" }); migrationBuilder.CreateIndex( name: "ix_tenant_class_members_tenant_id_class_id_user_id_member_type", table: "tenant_class_members", columns: new[] { "tenant_id", "class_id", "user_id", "member_type" }, unique: true); migrationBuilder.CreateIndex( name: "ix_tenant_class_members_tenant_id_user_id_status_member_type", table: "tenant_class_members", columns: new[] { "tenant_id", "user_id", "status", "member_type" }); migrationBuilder.CreateIndex( name: "ix_tenant_class_members_user_id", table: "tenant_class_members", column: "user_id"); migrationBuilder.CreateIndex( name: "ix_tenant_classes_created_by", table: "tenant_classes", column: "created_by"); migrationBuilder.CreateIndex( name: "ix_tenant_classes_tenant_id_code", table: "tenant_classes", columns: new[] { "tenant_id", "code" }, unique: true, filter: "code is not null and code <> ''"); migrationBuilder.CreateIndex( name: "ix_tenant_classes_tenant_id_legacy_id", table: "tenant_classes", columns: new[] { "tenant_id", "legacy_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_tenant_classes_tenant_id_region_id", table: "tenant_classes", columns: new[] { "tenant_id", "region_id" }, filter: "region_id is not null"); migrationBuilder.CreateIndex( name: "ix_tenant_classes_tenant_id_status_sort_order_created_at", table: "tenant_classes", columns: new[] { "tenant_id", "status", "sort_order", "created_at" }); migrationBuilder.CreateIndex( name: "ix_tenant_classes_updated_by", table: "tenant_classes", column: "updated_by"); migrationBuilder.CreateIndex( name: "ix_tenant_role_templates_created_by", table: "tenant_role_templates", column: "created_by"); migrationBuilder.CreateIndex( name: "ix_tenant_role_templates_tenant_id_code", table: "tenant_role_templates", columns: new[] { "tenant_id", "code" }, unique: true); migrationBuilder.CreateIndex( name: "ix_tenant_role_templates_tenant_id_status_sort_order", table: "tenant_role_templates", columns: new[] { "tenant_id", "status", "sort_order" }); migrationBuilder.CreateIndex( name: "ix_tenant_role_templates_updated_by", table: "tenant_role_templates", column: "updated_by"); migrationBuilder.CreateIndex( name: "ix_tenant_student_followups_assigned_to_user_id", table: "tenant_student_followups", column: "assigned_to_user_id"); migrationBuilder.CreateIndex( name: "ix_tenant_student_followups_completed_by", table: "tenant_student_followups", column: "completed_by"); migrationBuilder.CreateIndex( name: "ix_tenant_student_followups_student_user_id", table: "tenant_student_followups", column: "student_user_id"); migrationBuilder.CreateIndex( name: "ix_tenant_student_followups_tenant_id_assigned_to_user_id_stat~", table: "tenant_student_followups", columns: new[] { "tenant_id", "assigned_to_user_id", "status", "due_at" }, filter: "assigned_to_user_id is not null"); migrationBuilder.CreateIndex( name: "ix_tenant_student_followups_tenant_id_class_id_status_due_at", table: "tenant_student_followups", columns: new[] { "tenant_id", "class_id", "status", "due_at" }, filter: "class_id is not null"); migrationBuilder.CreateIndex( name: "ix_tenant_student_followups_tenant_id_student_user_id_status_d~", table: "tenant_student_followups", columns: new[] { "tenant_id", "student_user_id", "status", "due_at", "created_at" }); migrationBuilder.CreateIndex( name: "ix_tenant_student_notes_created_by", table: "tenant_student_notes", column: "created_by"); migrationBuilder.CreateIndex( name: "ix_tenant_student_notes_student_user_id", table: "tenant_student_notes", column: "student_user_id"); migrationBuilder.CreateIndex( name: "ix_tenant_student_notes_tenant_id_created_by_created_at", table: "tenant_student_notes", columns: new[] { "tenant_id", "created_by", "created_at" }, filter: "created_by is not null"); migrationBuilder.CreateIndex( name: "ix_tenant_student_notes_tenant_id_student_user_id_is_pinned_cr~", table: "tenant_student_notes", columns: new[] { "tenant_id", "student_user_id", "is_pinned", "created_at" }); migrationBuilder.CreateIndex( name: "ix_tenant_student_notes_updated_by", table: "tenant_student_notes", column: "updated_by"); migrationBuilder.AddForeignKey( name: "fk_tenant_memberships_tenant_role_templates_tenant_id_role_tem~", table: "tenant_memberships", columns: new[] { "tenant_id", "role_template_id" }, principalTable: "tenant_role_templates", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Restrict); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "fk_tenant_memberships_tenant_role_templates_tenant_id_role_tem~", table: "tenant_memberships"); migrationBuilder.DropTable( name: "auth_login_events"); migrationBuilder.DropTable( name: "auth_sessions"); migrationBuilder.DropTable( name: "sms_send_rate_limits"); migrationBuilder.DropTable( name: "sms_verification_codes"); migrationBuilder.DropTable( name: "tenant_auth_providers"); migrationBuilder.DropTable( name: "tenant_class_members"); migrationBuilder.DropTable( name: "tenant_role_templates"); migrationBuilder.DropTable( name: "tenant_student_followups"); migrationBuilder.DropTable( name: "tenant_student_notes"); migrationBuilder.DropTable( name: "tenant_classes"); migrationBuilder.DropIndex( name: "ix_tenant_memberships_tenant_id_role_template_id", table: "tenant_memberships"); migrationBuilder.DropColumn( name: "role_template_id", table: "tenant_memberships"); } } }