using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace AMREZ.EOP.Infrastructures.Migrations { /// public partial class InitDatabase : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.EnsureSchema( name: "meta"); migrationBuilder.CreateTable( name: "departments", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), Code = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), ParentDepartmentId = table.Column(type: "uuid", nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_departments", x => x.Id); table.CheckConstraint("ck_departments_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_departments_departments_ParentDepartmentId", column: x => x.ParentDepartmentId, principalTable: "departments", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "permissions", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), Code = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_permissions", x => x.Id); table.CheckConstraint("ck_permissions_tenant_not_null", "tenant_id is not null"); }); migrationBuilder.CreateTable( name: "positions", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), Code = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Title = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Level = table.Column(type: "integer", nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_positions", x => x.Id); table.CheckConstraint("ck_positions_tenant_not_null", "tenant_id is not null"); }); migrationBuilder.CreateTable( name: "roles", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), Code = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_roles", x => x.Id); table.CheckConstraint("ck_roles_tenant_not_null", "tenant_id is not null"); }); migrationBuilder.CreateTable( name: "tenants", schema: "meta", columns: table => new { TenantKey = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), Schema = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), ConnectionString = table.Column(type: "text", nullable: true), Mode = table.Column(type: "integer", nullable: false), IsActive = table.Column(type: "boolean", nullable: false, defaultValue: true), updated_at_utc = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'") }, constraints: table => { table.PrimaryKey("PK_tenants", x => x.TenantKey); }); migrationBuilder.CreateTable( name: "users", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), PasswordHash = table.Column(type: "text", nullable: false), IsActive = table.Column(type: "boolean", nullable: false, defaultValue: true), AccessFailedCount = table.Column(type: "integer", nullable: false, defaultValue: 0), LockoutEndUtc = table.Column(type: "timestamp with time zone", nullable: true), MfaEnabled = table.Column(type: "boolean", nullable: false, defaultValue: false), SecurityStamp = table.Column(type: "text", nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_users", x => x.Id); table.CheckConstraint("ck_users_tenant_not_null", "tenant_id is not null"); }); migrationBuilder.CreateTable( name: "role_permissions", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), RoleId = table.Column(type: "uuid", nullable: false), PermissionId = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_role_permissions", x => x.Id); table.CheckConstraint("ck_role_permissions_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_role_permissions_permissions_PermissionId", column: x => x.PermissionId, principalTable: "permissions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_role_permissions_roles_RoleId", column: x => x.RoleId, principalTable: "roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "tenant_domains", schema: "meta", columns: table => new { Domain = table.Column(type: "character varying(253)", maxLength: 253, nullable: false), TenantKey = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), IsPlatformBaseDomain = table.Column(type: "boolean", nullable: false, defaultValue: false), IsActive = table.Column(type: "boolean", nullable: false, defaultValue: true), updated_at_utc = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'") }, constraints: table => { table.PrimaryKey("PK_tenant_domains", x => x.Domain); table.ForeignKey( name: "FK_tenant_domains_tenants_TenantKey", column: x => x.TenantKey, principalSchema: "meta", principalTable: "tenants", principalColumn: "TenantKey", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "user_external_accounts", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserId = table.Column(type: "uuid", nullable: false), Provider = table.Column(type: "integer", nullable: false), Subject = table.Column(type: "text", nullable: false), Email = table.Column(type: "text", nullable: true), LinkedAt = table.Column(type: "timestamp with time zone", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_user_external_accounts", x => x.Id); table.CheckConstraint("ck_user_external_accounts_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_user_external_accounts_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "user_identities", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserId = table.Column(type: "uuid", nullable: false), Type = table.Column(type: "integer", nullable: false), Identifier = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), IsPrimary = table.Column(type: "boolean", nullable: false, defaultValue: false), VerifiedAt = table.Column(type: "timestamp with time zone", nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_user_identities", x => x.Id); table.CheckConstraint("ck_user_identities_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_user_identities_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "user_mfa_factors", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserId = table.Column(type: "uuid", nullable: false), Type = table.Column(type: "integer", nullable: false), Label = table.Column(type: "text", nullable: true), Secret = table.Column(type: "text", nullable: true), PhoneE164 = table.Column(type: "text", nullable: true), Email = table.Column(type: "text", nullable: true), PublicKey = table.Column(type: "text", nullable: true), CredentialId = table.Column(type: "text", nullable: true), Enabled = table.Column(type: "boolean", nullable: false, defaultValue: true), AddedAt = table.Column(type: "timestamp with time zone", nullable: false), LastUsedAt = table.Column(type: "timestamp with time zone", nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_user_mfa_factors", x => x.Id); table.CheckConstraint("ck_user_mfa_factors_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_user_mfa_factors_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "user_password_histories", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserId = table.Column(type: "uuid", nullable: false), PasswordHash = table.Column(type: "text", nullable: false), ChangedAt = table.Column(type: "timestamp with time zone", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_user_password_histories", x => x.Id); table.CheckConstraint("ck_user_password_histories_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_user_password_histories_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "user_profiles", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserId = table.Column(type: "uuid", nullable: false), FirstName = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), LastName = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), MiddleName = table.Column(type: "text", nullable: true), Nickname = table.Column(type: "text", nullable: true), DateOfBirth = table.Column(type: "timestamp with time zone", nullable: true), Gender = table.Column(type: "integer", nullable: true), DepartmentId = table.Column(type: "uuid", nullable: true), PositionId = table.Column(type: "uuid", nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_user_profiles", x => x.Id); table.CheckConstraint("ck_user_profiles_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_user_profiles_departments_DepartmentId", column: x => x.DepartmentId, principalTable: "departments", principalColumn: "Id"); table.ForeignKey( name: "FK_user_profiles_positions_PositionId", column: x => x.PositionId, principalTable: "positions", principalColumn: "Id"); table.ForeignKey( name: "FK_user_profiles_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "user_roles", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserId = table.Column(type: "uuid", nullable: false), RoleId = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_user_roles", x => x.Id); table.CheckConstraint("ck_user_roles_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_user_roles_roles_RoleId", column: x => x.RoleId, principalTable: "roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_user_roles_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "user_sessions", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserId = table.Column(type: "uuid", nullable: false), RefreshTokenHash = table.Column(type: "text", nullable: false), IssuedAt = table.Column(type: "timestamp with time zone", nullable: false), ExpiresAt = table.Column(type: "timestamp with time zone", nullable: true), RevokedAt = table.Column(type: "timestamp with time zone", nullable: true), DeviceId = table.Column(type: "text", nullable: true), UserAgent = table.Column(type: "text", nullable: true), IpAddress = table.Column(type: "text", nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_user_sessions", x => x.Id); table.CheckConstraint("ck_user_sessions_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_user_sessions_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "emergency_contacts", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserProfileId = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), Relationship = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Phone = table.Column(type: "text", nullable: true), Email = table.Column(type: "text", nullable: true), IsPrimary = table.Column(type: "boolean", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_emergency_contacts", x => x.Id); table.CheckConstraint("ck_emergency_contacts_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_emergency_contacts_user_profiles_UserProfileId", column: x => x.UserProfileId, principalTable: "user_profiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "employee_addresses", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserProfileId = table.Column(type: "uuid", nullable: false), Type = table.Column(type: "integer", nullable: false), Line1 = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Line2 = table.Column(type: "text", nullable: true), City = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), State = table.Column(type: "text", nullable: true), PostalCode = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), Country = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), IsPrimary = table.Column(type: "boolean", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_employee_addresses", x => x.Id); table.CheckConstraint("ck_employee_addresses_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_employee_addresses_user_profiles_UserProfileId", column: x => x.UserProfileId, principalTable: "user_profiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "employee_bank_accounts", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserProfileId = table.Column(type: "uuid", nullable: false), BankName = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), AccountNumber = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), AccountHolder = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), Branch = table.Column(type: "text", nullable: true), Note = table.Column(type: "text", nullable: true), IsPrimary = table.Column(type: "boolean", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_employee_bank_accounts", x => x.Id); table.CheckConstraint("ck_employee_bank_accounts_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_employee_bank_accounts_user_profiles_UserProfileId", column: x => x.UserProfileId, principalTable: "user_profiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "employments", columns: table => new { Id = table.Column(type: "uuid", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"), UserProfileId = table.Column(type: "uuid", nullable: false), EmploymentType = table.Column(type: "integer", nullable: false), StartDate = table.Column(type: "timestamp with time zone", nullable: false), EndDate = table.Column(type: "timestamp with time zone", nullable: true), DepartmentId = table.Column(type: "uuid", nullable: true), PositionId = table.Column(type: "uuid", nullable: true), ManagerUserId = table.Column(type: "uuid", nullable: true), WorkEmail = table.Column(type: "text", nullable: true), WorkPhone = table.Column(type: "text", nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"), created_by = table.Column(type: "text", nullable: true), updated_at = table.Column(type: "timestamp with time zone", nullable: true), updated_by = table.Column(type: "text", nullable: true), is_deleted = table.Column(type: "boolean", nullable: false, defaultValue: false) }, constraints: table => { table.PrimaryKey("PK_employments", x => x.Id); table.CheckConstraint("ck_employments_tenant_not_null", "tenant_id is not null"); table.ForeignKey( name: "FK_employments_departments_DepartmentId", column: x => x.DepartmentId, principalTable: "departments", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_employments_positions_PositionId", column: x => x.PositionId, principalTable: "positions", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_employments_user_profiles_UserProfileId", column: x => x.UserProfileId, principalTable: "user_profiles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_departments_ParentDepartmentId", table: "departments", column: "ParentDepartmentId"); migrationBuilder.CreateIndex( name: "IX_departments_tenant_id", table: "departments", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_departments_tenant_id_Code", table: "departments", columns: new[] { "tenant_id", "Code" }, unique: true); migrationBuilder.CreateIndex( name: "IX_emergency_contacts_tenant_id", table: "emergency_contacts", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_emergency_contacts_tenant_id_UserProfileId_IsPrimary", table: "emergency_contacts", columns: new[] { "tenant_id", "UserProfileId", "IsPrimary" }); migrationBuilder.CreateIndex( name: "IX_emergency_contacts_UserProfileId", table: "emergency_contacts", column: "UserProfileId"); migrationBuilder.CreateIndex( name: "IX_employee_addresses_tenant_id", table: "employee_addresses", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_employee_addresses_tenant_id_UserProfileId_IsPrimary", table: "employee_addresses", columns: new[] { "tenant_id", "UserProfileId", "IsPrimary" }); migrationBuilder.CreateIndex( name: "IX_employee_addresses_UserProfileId", table: "employee_addresses", column: "UserProfileId"); migrationBuilder.CreateIndex( name: "IX_employee_bank_accounts_tenant_id", table: "employee_bank_accounts", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_employee_bank_accounts_tenant_id_UserProfileId_IsPrimary", table: "employee_bank_accounts", columns: new[] { "tenant_id", "UserProfileId", "IsPrimary" }); migrationBuilder.CreateIndex( name: "IX_employee_bank_accounts_UserProfileId", table: "employee_bank_accounts", column: "UserProfileId"); migrationBuilder.CreateIndex( name: "IX_employments_DepartmentId", table: "employments", column: "DepartmentId"); migrationBuilder.CreateIndex( name: "IX_employments_PositionId", table: "employments", column: "PositionId"); migrationBuilder.CreateIndex( name: "IX_employments_tenant_id", table: "employments", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_employments_tenant_id_UserProfileId_StartDate", table: "employments", columns: new[] { "tenant_id", "UserProfileId", "StartDate" }); migrationBuilder.CreateIndex( name: "IX_employments_UserProfileId", table: "employments", column: "UserProfileId"); migrationBuilder.CreateIndex( name: "IX_permissions_tenant_id", table: "permissions", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_permissions_tenant_id_Code", table: "permissions", columns: new[] { "tenant_id", "Code" }, unique: true); migrationBuilder.CreateIndex( name: "IX_positions_tenant_id", table: "positions", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_positions_tenant_id_Code", table: "positions", columns: new[] { "tenant_id", "Code" }, unique: true); migrationBuilder.CreateIndex( name: "IX_role_permissions_PermissionId", table: "role_permissions", column: "PermissionId"); migrationBuilder.CreateIndex( name: "IX_role_permissions_RoleId", table: "role_permissions", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_role_permissions_tenant_id", table: "role_permissions", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_role_permissions_tenant_id_RoleId_PermissionId", table: "role_permissions", columns: new[] { "tenant_id", "RoleId", "PermissionId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_roles_tenant_id", table: "roles", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_roles_tenant_id_Code", table: "roles", columns: new[] { "tenant_id", "Code" }, unique: true); migrationBuilder.CreateIndex( name: "IX_tenant_domains_IsActive", schema: "meta", table: "tenant_domains", column: "IsActive"); migrationBuilder.CreateIndex( name: "IX_tenant_domains_IsPlatformBaseDomain", schema: "meta", table: "tenant_domains", column: "IsPlatformBaseDomain"); migrationBuilder.CreateIndex( name: "IX_tenant_domains_TenantKey", schema: "meta", table: "tenant_domains", column: "TenantKey"); migrationBuilder.CreateIndex( name: "IX_tenants_IsActive", schema: "meta", table: "tenants", column: "IsActive"); migrationBuilder.CreateIndex( name: "IX_user_external_accounts_tenant_id", table: "user_external_accounts", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_user_external_accounts_tenant_id_Provider_Subject", table: "user_external_accounts", columns: new[] { "tenant_id", "Provider", "Subject" }, unique: true); migrationBuilder.CreateIndex( name: "IX_user_external_accounts_UserId", table: "user_external_accounts", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_user_identities_tenant_id", table: "user_identities", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_user_identities_tenant_id_Type_Identifier", table: "user_identities", columns: new[] { "tenant_id", "Type", "Identifier" }, unique: true); migrationBuilder.CreateIndex( name: "IX_user_identities_UserId", table: "user_identities", column: "UserId"); migrationBuilder.CreateIndex( name: "ix_user_identity_primary_per_type", table: "user_identities", columns: new[] { "tenant_id", "UserId", "Type", "IsPrimary" }); migrationBuilder.CreateIndex( name: "IX_user_mfa_factors_tenant_id", table: "user_mfa_factors", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_user_mfa_factors_tenant_id_UserId", table: "user_mfa_factors", columns: new[] { "tenant_id", "UserId" }); migrationBuilder.CreateIndex( name: "IX_user_mfa_factors_UserId", table: "user_mfa_factors", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_user_password_histories_tenant_id", table: "user_password_histories", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_user_password_histories_tenant_id_UserId_ChangedAt", table: "user_password_histories", columns: new[] { "tenant_id", "UserId", "ChangedAt" }); migrationBuilder.CreateIndex( name: "IX_user_password_histories_UserId", table: "user_password_histories", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_user_profiles_DepartmentId", table: "user_profiles", column: "DepartmentId"); migrationBuilder.CreateIndex( name: "IX_user_profiles_PositionId", table: "user_profiles", column: "PositionId"); migrationBuilder.CreateIndex( name: "IX_user_profiles_tenant_id", table: "user_profiles", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_user_profiles_tenant_id_UserId", table: "user_profiles", columns: new[] { "tenant_id", "UserId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_user_profiles_UserId", table: "user_profiles", column: "UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_user_roles_RoleId", table: "user_roles", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_user_roles_tenant_id", table: "user_roles", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_user_roles_tenant_id_UserId_RoleId", table: "user_roles", columns: new[] { "tenant_id", "UserId", "RoleId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_user_roles_UserId", table: "user_roles", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_user_sessions_tenant_id", table: "user_sessions", column: "tenant_id"); migrationBuilder.CreateIndex( name: "IX_user_sessions_tenant_id_DeviceId", table: "user_sessions", columns: new[] { "tenant_id", "DeviceId" }); migrationBuilder.CreateIndex( name: "IX_user_sessions_tenant_id_UserId", table: "user_sessions", columns: new[] { "tenant_id", "UserId" }); migrationBuilder.CreateIndex( name: "IX_user_sessions_UserId", table: "user_sessions", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_users_tenant_id", table: "users", column: "tenant_id"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "emergency_contacts"); migrationBuilder.DropTable( name: "employee_addresses"); migrationBuilder.DropTable( name: "employee_bank_accounts"); migrationBuilder.DropTable( name: "employments"); migrationBuilder.DropTable( name: "role_permissions"); migrationBuilder.DropTable( name: "tenant_domains", schema: "meta"); migrationBuilder.DropTable( name: "user_external_accounts"); migrationBuilder.DropTable( name: "user_identities"); migrationBuilder.DropTable( name: "user_mfa_factors"); migrationBuilder.DropTable( name: "user_password_histories"); migrationBuilder.DropTable( name: "user_roles"); migrationBuilder.DropTable( name: "user_sessions"); migrationBuilder.DropTable( name: "user_profiles"); migrationBuilder.DropTable( name: "permissions"); migrationBuilder.DropTable( name: "tenants", schema: "meta"); migrationBuilder.DropTable( name: "roles"); migrationBuilder.DropTable( name: "departments"); migrationBuilder.DropTable( name: "positions"); migrationBuilder.DropTable( name: "users"); } } }