Add Login Module

This commit is contained in:
Thanakarn Klangkasame
2025-10-02 11:18:44 +07:00
parent f505e31cfd
commit 563a341a99
52 changed files with 1127 additions and 2036 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,32 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AMREZ.EOP.Infrastructures.Migrations
{
/// <inheritdoc />
public partial class Add_Tenant_Guid : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "TenantId",
schema: "meta",
table: "tenants",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "TenantId",
schema: "meta",
table: "tenants");
}
}
}

View File

@@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace AMREZ.EOP.Infrastructures.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250930101327_Add_Tenant_Guid")]
partial class Add_Tenant_Guid
[Migration("20251002040013_InitDatabase")]
partial class InitDatabase
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -58,10 +58,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("character varying(256)");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -81,6 +79,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("permissions", null, t =>
{
t.HasCheckConstraint("ck_permissions_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_permissions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -117,10 +117,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("character varying(256)");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -140,6 +138,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("roles", null, t =>
{
t.HasCheckConstraint("ck_roles_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_roles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -172,10 +172,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("uuid");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -193,12 +191,16 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("TenantId", "PermissionId");
b.HasIndex("TenantId", "RoleId", "PermissionId")
.IsUnique();
b.ToTable("role_permissions", null, t =>
{
t.HasCheckConstraint("ck_role_permissions_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_role_permissions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -250,10 +252,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -270,6 +270,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("users", null, t =>
{
t.HasCheckConstraint("ck_users_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_users_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -309,10 +311,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -329,7 +329,7 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId");
b.HasIndex("TenantId", "UserId");
b.HasIndex("TenantId", "Provider", "Subject")
.IsUnique();
@@ -337,6 +337,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("user_external_accounts", null, t =>
{
t.HasCheckConstraint("ck_user_external_accounts_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_external_accounts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -373,10 +375,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasDefaultValue(false);
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<int>("Type")
.HasColumnType("integer");
@@ -399,8 +399,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId");
b.HasIndex("TenantId", "Type", "Identifier")
.IsUnique();
@@ -410,6 +408,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("user_identities", null, t =>
{
t.HasCheckConstraint("ck_user_identities_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_identities_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -465,10 +465,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<int>("Type")
.HasColumnType("integer");
@@ -488,13 +486,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId");
b.HasIndex("TenantId", "UserId");
b.ToTable("user_mfa_factors", null, t =>
{
t.HasCheckConstraint("ck_user_mfa_factors_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_mfa_factors_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -528,10 +526,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -548,13 +544,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId");
b.HasIndex("TenantId", "UserId", "ChangedAt");
b.ToTable("user_password_histories", null, t =>
{
t.HasCheckConstraint("ck_user_password_histories_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_password_histories_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -584,10 +580,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("uuid");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -608,12 +602,16 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("UserId");
b.HasIndex("TenantId", "RoleId");
b.HasIndex("TenantId", "UserId", "RoleId")
.IsUnique();
b.ToTable("user_roles", null, t =>
{
t.HasCheckConstraint("ck_user_roles_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_roles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -659,10 +657,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("timestamp with time zone");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -682,8 +678,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId");
b.HasIndex("TenantId", "DeviceId");
b.HasIndex("TenantId", "UserId");
@@ -691,6 +685,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("user_sessions", null, t =>
{
t.HasCheckConstraint("ck_user_sessions_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_sessions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -730,10 +726,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("uuid");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -745,16 +739,18 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasKey("Id");
b.HasIndex("ParentDepartmentId");
b.HasIndex("TenantId");
b.HasIndex("TenantId", "Code")
.IsUnique();
b.HasIndex("TenantId", "ParentDepartmentId");
b.ToTable("departments", null, t =>
{
t.HasCheckConstraint("ck_departments_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_departments_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -800,10 +796,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("character varying(64)");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -820,13 +814,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserProfileId");
b.HasIndex("TenantId", "UserProfileId", "IsPrimary");
b.ToTable("emergency_contacts", null, t =>
{
t.HasCheckConstraint("ck_emergency_contacts_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_emergency_contacts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -882,10 +876,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<int>("Type")
.HasColumnType("integer");
@@ -905,13 +897,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserProfileId");
b.HasIndex("TenantId", "UserProfileId", "IsPrimary");
b.ToTable("employee_addresses", null, t =>
{
t.HasCheckConstraint("ck_employee_addresses_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_employee_addresses_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -962,10 +954,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -982,13 +972,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserProfileId");
b.HasIndex("TenantId", "UserProfileId", "IsPrimary");
b.ToTable("employee_bank_accounts", null, t =>
{
t.HasCheckConstraint("ck_employee_bank_accounts_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_employee_bank_accounts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -1033,10 +1023,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("timestamp with time zone");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -1057,19 +1045,19 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasKey("Id");
b.HasIndex("DepartmentId");
b.HasIndex("PositionId");
b.HasIndex("TenantId");
b.HasIndex("UserProfileId");
b.HasIndex("TenantId", "DepartmentId");
b.HasIndex("TenantId", "PositionId");
b.HasIndex("TenantId", "UserProfileId", "StartDate");
b.ToTable("employments", null, t =>
{
t.HasCheckConstraint("ck_employments_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_employments_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -1104,10 +1092,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("integer");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<string>("Title")
.IsRequired()
@@ -1132,6 +1118,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("positions", null, t =>
{
t.HasCheckConstraint("ck_positions_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_positions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -1186,10 +1174,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("uuid");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -1210,15 +1196,14 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId")
.IsUnique();
b.HasIndex("TenantId", "UserId")
.IsUnique();
b.ToTable("user_profiles", null, t =>
{
t.HasCheckConstraint("ck_user_profiles_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_profiles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -1254,8 +1239,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasKey("TenantKey");
b.HasAlternateKey("TenantId");
b.HasIndex("IsActive");
b.HasIndex("TenantId")
.IsUnique();
b.ToTable("tenants", "meta");
});
@@ -1310,6 +1300,20 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.Permission", null)
.WithMany()
.HasForeignKey("TenantId", "PermissionId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.Role", null)
.WithMany()
.HasForeignKey("TenantId", "RoleId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Permission");
b.Navigation("Role");
@@ -1319,7 +1323,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithMany("ExternalAccounts")
.HasForeignKey("UserId")
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1330,7 +1335,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithMany("Identities")
.HasForeignKey("UserId")
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1341,7 +1347,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithMany("MfaFactors")
.HasForeignKey("UserId")
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1352,7 +1359,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithMany("PasswordHistories")
.HasForeignKey("UserId")
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1373,6 +1381,20 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.Role", null)
.WithMany()
.HasForeignKey("TenantId", "RoleId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", null)
.WithMany()
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Role");
b.Navigation("User");
@@ -1382,7 +1404,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithMany("Sessions")
.HasForeignKey("UserId")
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1393,7 +1416,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.Department", "Parent")
.WithMany("Children")
.HasForeignKey("ParentDepartmentId")
.HasForeignKey("TenantId", "ParentDepartmentId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Parent");
@@ -1403,7 +1427,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "UserProfile")
.WithMany("EmergencyContacts")
.HasForeignKey("UserProfileId")
.HasForeignKey("TenantId", "UserProfileId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1414,7 +1439,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "UserProfile")
.WithMany("Addresses")
.HasForeignKey("UserProfileId")
.HasForeignKey("TenantId", "UserProfileId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1425,7 +1451,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "UserProfile")
.WithMany("BankAccounts")
.HasForeignKey("UserProfileId")
.HasForeignKey("TenantId", "UserProfileId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1436,17 +1463,20 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.Department", "Department")
.WithMany()
.HasForeignKey("DepartmentId")
.HasForeignKey("TenantId", "DepartmentId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.Position", "Position")
.WithMany()
.HasForeignKey("PositionId")
.HasForeignKey("TenantId", "PositionId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "UserProfile")
.WithMany("Employments")
.HasForeignKey("UserProfileId")
.HasForeignKey("TenantId", "UserProfileId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1469,7 +1499,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithOne()
.HasForeignKey("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "UserId")
.HasForeignKey("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "TenantId", "UserId")
.HasPrincipalKey("AMREZ.EOP.Domain.Entities.Authentications.User", "TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

View File

@@ -19,10 +19,10 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
Code = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
ParentDepartmentId = table.Column<Guid>(type: "uuid", nullable: true),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -32,12 +32,14 @@ namespace AMREZ.EOP.Infrastructures.Migrations
constraints: table =>
{
table.PrimaryKey("PK_departments", x => x.Id);
table.UniqueConstraint("AK_departments_tenant_id_Id", x => new { x.tenant_id, x.Id });
table.CheckConstraint("ck_departments_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_departments_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_departments_departments_ParentDepartmentId",
column: x => x.ParentDepartmentId,
name: "FK_departments_departments_tenant_id_ParentDepartmentId",
columns: x => new { x.tenant_id, x.ParentDepartmentId },
principalTable: "departments",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Restrict);
});
@@ -46,9 +48,9 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
Code = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -58,7 +60,9 @@ namespace AMREZ.EOP.Infrastructures.Migrations
constraints: table =>
{
table.PrimaryKey("PK_permissions", x => x.Id);
table.UniqueConstraint("AK_permissions_tenant_id_Id", x => new { x.tenant_id, x.Id });
table.CheckConstraint("ck_permissions_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_permissions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
migrationBuilder.CreateTable(
@@ -66,10 +70,10 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
Code = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
Title = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
Level = table.Column<int>(type: "integer", nullable: true),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -79,7 +83,9 @@ namespace AMREZ.EOP.Infrastructures.Migrations
constraints: table =>
{
table.PrimaryKey("PK_positions", x => x.Id);
table.UniqueConstraint("AK_positions_tenant_id_Id", x => new { x.tenant_id, x.Id });
table.CheckConstraint("ck_positions_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_positions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
migrationBuilder.CreateTable(
@@ -87,9 +93,9 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
Code = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -99,7 +105,9 @@ namespace AMREZ.EOP.Infrastructures.Migrations
constraints: table =>
{
table.PrimaryKey("PK_roles", x => x.Id);
table.UniqueConstraint("AK_roles_tenant_id_Id", x => new { x.tenant_id, x.Id });
table.CheckConstraint("ck_roles_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_roles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
migrationBuilder.CreateTable(
@@ -108,6 +116,7 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
TenantKey = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
TenantId = table.Column<Guid>(type: "uuid", nullable: false),
Schema = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
ConnectionString = table.Column<string>(type: "text", nullable: true),
Mode = table.Column<int>(type: "integer", nullable: false),
@@ -117,6 +126,7 @@ namespace AMREZ.EOP.Infrastructures.Migrations
constraints: table =>
{
table.PrimaryKey("PK_tenants", x => x.TenantKey);
table.UniqueConstraint("AK_tenants_TenantId", x => x.TenantId);
});
migrationBuilder.CreateTable(
@@ -124,13 +134,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
PasswordHash = table.Column<string>(type: "text", nullable: false),
IsActive = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
AccessFailedCount = table.Column<int>(type: "integer", nullable: false, defaultValue: 0),
LockoutEndUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
MfaEnabled = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
SecurityStamp = table.Column<string>(type: "text", nullable: true),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -140,7 +150,9 @@ namespace AMREZ.EOP.Infrastructures.Migrations
constraints: table =>
{
table.PrimaryKey("PK_users", x => x.Id);
table.UniqueConstraint("AK_users_tenant_id_Id", x => new { x.tenant_id, x.Id });
table.CheckConstraint("ck_users_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_users_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
migrationBuilder.CreateTable(
@@ -148,9 +160,9 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
RoleId = table.Column<Guid>(type: "uuid", nullable: false),
PermissionId = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -161,18 +173,31 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_role_permissions", x => x.Id);
table.CheckConstraint("ck_role_permissions_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_role_permissions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
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_permissions_tenant_id_PermissionId",
columns: x => new { x.tenant_id, x.PermissionId },
principalTable: "permissions",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_role_permissions_roles_RoleId",
column: x => x.RoleId,
principalTable: "roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_role_permissions_roles_tenant_id_RoleId",
columns: x => new { x.tenant_id, x.RoleId },
principalTable: "roles",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@@ -203,12 +228,12 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
Provider = table.Column<int>(type: "integer", nullable: false),
Subject = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: true),
LinkedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -219,11 +244,12 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_user_external_accounts", x => x.Id);
table.CheckConstraint("ck_user_external_accounts_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_user_external_accounts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_user_external_accounts_users_UserId",
column: x => x.UserId,
name: "FK_user_external_accounts_users_tenant_id_UserId",
columns: x => new { x.tenant_id, x.UserId },
principalTable: "users",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
@@ -232,12 +258,12 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
Type = table.Column<int>(type: "integer", nullable: false),
Identifier = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
IsPrimary = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
VerifiedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -248,11 +274,12 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_user_identities", x => x.Id);
table.CheckConstraint("ck_user_identities_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_user_identities_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_user_identities_users_UserId",
column: x => x.UserId,
name: "FK_user_identities_users_tenant_id_UserId",
columns: x => new { x.tenant_id, x.UserId },
principalTable: "users",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
@@ -261,7 +288,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
Type = table.Column<int>(type: "integer", nullable: false),
Label = table.Column<string>(type: "text", nullable: true),
@@ -273,6 +299,7 @@ namespace AMREZ.EOP.Infrastructures.Migrations
Enabled = table.Column<bool>(type: "boolean", nullable: false, defaultValue: true),
AddedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
LastUsedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -283,11 +310,12 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_user_mfa_factors", x => x.Id);
table.CheckConstraint("ck_user_mfa_factors_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_user_mfa_factors_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_user_mfa_factors_users_UserId",
column: x => x.UserId,
name: "FK_user_mfa_factors_users_tenant_id_UserId",
columns: x => new { x.tenant_id, x.UserId },
principalTable: "users",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
@@ -296,10 +324,10 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
PasswordHash = table.Column<string>(type: "text", nullable: false),
ChangedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -310,11 +338,12 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_user_password_histories", x => x.Id);
table.CheckConstraint("ck_user_password_histories_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_user_password_histories_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_user_password_histories_users_UserId",
column: x => x.UserId,
name: "FK_user_password_histories_users_tenant_id_UserId",
columns: x => new { x.tenant_id, x.UserId },
principalTable: "users",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
@@ -323,7 +352,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
FirstName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
LastName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
@@ -333,6 +361,7 @@ namespace AMREZ.EOP.Infrastructures.Migrations
Gender = table.Column<int>(type: "integer", nullable: true),
DepartmentId = table.Column<Guid>(type: "uuid", nullable: true),
PositionId = table.Column<Guid>(type: "uuid", nullable: true),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -342,7 +371,9 @@ namespace AMREZ.EOP.Infrastructures.Migrations
constraints: table =>
{
table.PrimaryKey("PK_user_profiles", x => x.Id);
table.UniqueConstraint("AK_user_profiles_tenant_id_Id", x => new { x.tenant_id, x.Id });
table.CheckConstraint("ck_user_profiles_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_user_profiles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_user_profiles_departments_DepartmentId",
column: x => x.DepartmentId,
@@ -354,10 +385,10 @@ namespace AMREZ.EOP.Infrastructures.Migrations
principalTable: "positions",
principalColumn: "Id");
table.ForeignKey(
name: "FK_user_profiles_users_UserId",
column: x => x.UserId,
name: "FK_user_profiles_users_tenant_id_UserId",
columns: x => new { x.tenant_id, x.UserId },
principalTable: "users",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
@@ -366,9 +397,9 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
RoleId = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -379,18 +410,31 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_user_roles", x => x.Id);
table.CheckConstraint("ck_user_roles_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_user_roles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
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_roles_tenant_id_RoleId",
columns: x => new { x.tenant_id, x.RoleId },
principalTable: "roles",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_user_roles_users_UserId",
column: x => x.UserId,
principalTable: "users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_user_roles_users_tenant_id_UserId",
columns: x => new { x.tenant_id, x.UserId },
principalTable: "users",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@@ -398,7 +442,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
RefreshTokenHash = table.Column<string>(type: "text", nullable: false),
IssuedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
@@ -407,6 +450,7 @@ namespace AMREZ.EOP.Infrastructures.Migrations
DeviceId = table.Column<string>(type: "text", nullable: true),
UserAgent = table.Column<string>(type: "text", nullable: true),
IpAddress = table.Column<string>(type: "text", nullable: true),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -417,11 +461,12 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_user_sessions", x => x.Id);
table.CheckConstraint("ck_user_sessions_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_user_sessions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_user_sessions_users_UserId",
column: x => x.UserId,
name: "FK_user_sessions_users_tenant_id_UserId",
columns: x => new { x.tenant_id, x.UserId },
principalTable: "users",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
@@ -430,13 +475,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserProfileId = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
Relationship = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
Phone = table.Column<string>(type: "text", nullable: true),
Email = table.Column<string>(type: "text", nullable: true),
IsPrimary = table.Column<bool>(type: "boolean", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -447,11 +492,12 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_emergency_contacts", x => x.Id);
table.CheckConstraint("ck_emergency_contacts_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_emergency_contacts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_emergency_contacts_user_profiles_UserProfileId",
column: x => x.UserProfileId,
name: "FK_emergency_contacts_user_profiles_tenant_id_UserProfileId",
columns: x => new { x.tenant_id, x.UserProfileId },
principalTable: "user_profiles",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
@@ -460,7 +506,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserProfileId = table.Column<Guid>(type: "uuid", nullable: false),
Type = table.Column<int>(type: "integer", nullable: false),
Line1 = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
@@ -470,6 +515,7 @@ namespace AMREZ.EOP.Infrastructures.Migrations
PostalCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
Country = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
IsPrimary = table.Column<bool>(type: "boolean", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -480,11 +526,12 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_employee_addresses", x => x.Id);
table.CheckConstraint("ck_employee_addresses_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_employee_addresses_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_employee_addresses_user_profiles_UserProfileId",
column: x => x.UserProfileId,
name: "FK_employee_addresses_user_profiles_tenant_id_UserProfileId",
columns: x => new { x.tenant_id, x.UserProfileId },
principalTable: "user_profiles",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
@@ -493,7 +540,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserProfileId = table.Column<Guid>(type: "uuid", nullable: false),
BankName = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
AccountNumber = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
@@ -501,6 +547,7 @@ namespace AMREZ.EOP.Infrastructures.Migrations
Branch = table.Column<string>(type: "text", nullable: true),
Note = table.Column<string>(type: "text", nullable: true),
IsPrimary = table.Column<bool>(type: "boolean", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -511,11 +558,12 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_employee_bank_accounts", x => x.Id);
table.CheckConstraint("ck_employee_bank_accounts_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_employee_bank_accounts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_employee_bank_accounts_user_profiles_UserProfileId",
column: x => x.UserProfileId,
name: "FK_employee_bank_accounts_user_profiles_tenant_id_UserProfileId",
columns: x => new { x.tenant_id, x.UserProfileId },
principalTable: "user_profiles",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
@@ -524,7 +572,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "nullif(current_setting('app.tenant_id', true),'')::uuid"),
UserProfileId = table.Column<Guid>(type: "uuid", nullable: false),
EmploymentType = table.Column<int>(type: "integer", nullable: false),
StartDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
@@ -534,6 +581,7 @@ namespace AMREZ.EOP.Infrastructures.Migrations
ManagerUserId = table.Column<Guid>(type: "uuid", nullable: true),
WorkEmail = table.Column<string>(type: "text", nullable: true),
WorkPhone = table.Column<string>(type: "text", nullable: true),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now() at time zone 'utc'"),
created_by = table.Column<string>(type: "text", nullable: true),
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
@@ -544,31 +592,27 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
table.PrimaryKey("PK_employments", x => x.Id);
table.CheckConstraint("ck_employments_tenant_not_null", "tenant_id is not null");
table.CheckConstraint("ck_employments_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
table.ForeignKey(
name: "FK_employments_departments_DepartmentId",
column: x => x.DepartmentId,
name: "FK_employments_departments_tenant_id_DepartmentId",
columns: x => new { x.tenant_id, x.DepartmentId },
principalTable: "departments",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_employments_positions_PositionId",
column: x => x.PositionId,
name: "FK_employments_positions_tenant_id_PositionId",
columns: x => new { x.tenant_id, x.PositionId },
principalTable: "positions",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_employments_user_profiles_UserProfileId",
column: x => x.UserProfileId,
name: "FK_employments_user_profiles_tenant_id_UserProfileId",
columns: x => new { x.tenant_id, x.UserProfileId },
principalTable: "user_profiles",
principalColumn: "Id",
principalColumns: new[] { "tenant_id", "Id" },
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_departments_ParentDepartmentId",
table: "departments",
column: "ParentDepartmentId");
migrationBuilder.CreateIndex(
name: "IX_departments_tenant_id",
table: "departments",
@@ -580,6 +624,11 @@ namespace AMREZ.EOP.Infrastructures.Migrations
columns: new[] { "tenant_id", "Code" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_departments_tenant_id_ParentDepartmentId",
table: "departments",
columns: new[] { "tenant_id", "ParentDepartmentId" });
migrationBuilder.CreateIndex(
name: "IX_emergency_contacts_tenant_id",
table: "emergency_contacts",
@@ -590,11 +639,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
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",
@@ -605,11 +649,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
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",
@@ -620,36 +659,26 @@ namespace AMREZ.EOP.Infrastructures.Migrations
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_DepartmentId",
table: "employments",
columns: new[] { "tenant_id", "DepartmentId" });
migrationBuilder.CreateIndex(
name: "IX_employments_tenant_id_PositionId",
table: "employments",
columns: new[] { "tenant_id", "PositionId" });
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",
@@ -687,6 +716,11 @@ namespace AMREZ.EOP.Infrastructures.Migrations
table: "role_permissions",
column: "tenant_id");
migrationBuilder.CreateIndex(
name: "IX_role_permissions_tenant_id_PermissionId",
table: "role_permissions",
columns: new[] { "tenant_id", "PermissionId" });
migrationBuilder.CreateIndex(
name: "IX_role_permissions_tenant_id_RoleId_PermissionId",
table: "role_permissions",
@@ -728,6 +762,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
table: "tenants",
column: "IsActive");
migrationBuilder.CreateIndex(
name: "IX_tenants_TenantId",
schema: "meta",
table: "tenants",
column: "TenantId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_user_external_accounts_tenant_id",
table: "user_external_accounts",
@@ -740,9 +781,9 @@ namespace AMREZ.EOP.Infrastructures.Migrations
unique: true);
migrationBuilder.CreateIndex(
name: "IX_user_external_accounts_UserId",
name: "IX_user_external_accounts_tenant_id_UserId",
table: "user_external_accounts",
column: "UserId");
columns: new[] { "tenant_id", "UserId" });
migrationBuilder.CreateIndex(
name: "IX_user_identities_tenant_id",
@@ -755,11 +796,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
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",
@@ -775,11 +811,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
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",
@@ -790,11 +821,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
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",
@@ -816,12 +842,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
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",
@@ -832,6 +852,11 @@ namespace AMREZ.EOP.Infrastructures.Migrations
table: "user_roles",
column: "tenant_id");
migrationBuilder.CreateIndex(
name: "IX_user_roles_tenant_id_RoleId",
table: "user_roles",
columns: new[] { "tenant_id", "RoleId" });
migrationBuilder.CreateIndex(
name: "IX_user_roles_tenant_id_UserId_RoleId",
table: "user_roles",
@@ -858,11 +883,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
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",

View File

@@ -55,10 +55,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("character varying(256)");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -78,6 +76,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("permissions", null, t =>
{
t.HasCheckConstraint("ck_permissions_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_permissions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -114,10 +114,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("character varying(256)");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -137,6 +135,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("roles", null, t =>
{
t.HasCheckConstraint("ck_roles_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_roles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -169,10 +169,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("uuid");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -190,12 +188,16 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("TenantId", "PermissionId");
b.HasIndex("TenantId", "RoleId", "PermissionId")
.IsUnique();
b.ToTable("role_permissions", null, t =>
{
t.HasCheckConstraint("ck_role_permissions_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_role_permissions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -247,10 +249,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -267,6 +267,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("users", null, t =>
{
t.HasCheckConstraint("ck_users_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_users_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -306,10 +308,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -326,7 +326,7 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId");
b.HasIndex("TenantId", "UserId");
b.HasIndex("TenantId", "Provider", "Subject")
.IsUnique();
@@ -334,6 +334,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("user_external_accounts", null, t =>
{
t.HasCheckConstraint("ck_user_external_accounts_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_external_accounts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -370,10 +372,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasDefaultValue(false);
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<int>("Type")
.HasColumnType("integer");
@@ -396,8 +396,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId");
b.HasIndex("TenantId", "Type", "Identifier")
.IsUnique();
@@ -407,6 +405,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("user_identities", null, t =>
{
t.HasCheckConstraint("ck_user_identities_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_identities_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -462,10 +462,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<int>("Type")
.HasColumnType("integer");
@@ -485,13 +483,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId");
b.HasIndex("TenantId", "UserId");
b.ToTable("user_mfa_factors", null, t =>
{
t.HasCheckConstraint("ck_user_mfa_factors_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_mfa_factors_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -525,10 +523,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -545,13 +541,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId");
b.HasIndex("TenantId", "UserId", "ChangedAt");
b.ToTable("user_password_histories", null, t =>
{
t.HasCheckConstraint("ck_user_password_histories_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_password_histories_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -581,10 +577,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("uuid");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -605,12 +599,16 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("UserId");
b.HasIndex("TenantId", "RoleId");
b.HasIndex("TenantId", "UserId", "RoleId")
.IsUnique();
b.ToTable("user_roles", null, t =>
{
t.HasCheckConstraint("ck_user_roles_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_roles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -656,10 +654,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("timestamp with time zone");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -679,8 +675,6 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId");
b.HasIndex("TenantId", "DeviceId");
b.HasIndex("TenantId", "UserId");
@@ -688,6 +682,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("user_sessions", null, t =>
{
t.HasCheckConstraint("ck_user_sessions_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_sessions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -727,10 +723,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("uuid");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -742,16 +736,18 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasKey("Id");
b.HasIndex("ParentDepartmentId");
b.HasIndex("TenantId");
b.HasIndex("TenantId", "Code")
.IsUnique();
b.HasIndex("TenantId", "ParentDepartmentId");
b.ToTable("departments", null, t =>
{
t.HasCheckConstraint("ck_departments_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_departments_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -797,10 +793,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("character varying(64)");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -817,13 +811,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserProfileId");
b.HasIndex("TenantId", "UserProfileId", "IsPrimary");
b.ToTable("emergency_contacts", null, t =>
{
t.HasCheckConstraint("ck_emergency_contacts_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_emergency_contacts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -879,10 +873,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<int>("Type")
.HasColumnType("integer");
@@ -902,13 +894,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserProfileId");
b.HasIndex("TenantId", "UserProfileId", "IsPrimary");
b.ToTable("employee_addresses", null, t =>
{
t.HasCheckConstraint("ck_employee_addresses_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_employee_addresses_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -959,10 +951,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("text");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -979,13 +969,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserProfileId");
b.HasIndex("TenantId", "UserProfileId", "IsPrimary");
b.ToTable("employee_bank_accounts", null, t =>
{
t.HasCheckConstraint("ck_employee_bank_accounts_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_employee_bank_accounts_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -1030,10 +1020,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("timestamp with time zone");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -1054,19 +1042,19 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasKey("Id");
b.HasIndex("DepartmentId");
b.HasIndex("PositionId");
b.HasIndex("TenantId");
b.HasIndex("UserProfileId");
b.HasIndex("TenantId", "DepartmentId");
b.HasIndex("TenantId", "PositionId");
b.HasIndex("TenantId", "UserProfileId", "StartDate");
b.ToTable("employments", null, t =>
{
t.HasCheckConstraint("ck_employments_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_employments_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -1101,10 +1089,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("integer");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<string>("Title")
.IsRequired()
@@ -1129,6 +1115,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.ToTable("positions", null, t =>
{
t.HasCheckConstraint("ck_positions_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_positions_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -1183,10 +1171,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.HasColumnType("uuid");
b.Property<Guid>("TenantId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("tenant_id")
.HasDefaultValueSql("nullif(current_setting('app.tenant_id', true),'')::uuid");
.HasColumnName("tenant_id");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
@@ -1207,15 +1193,14 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasIndex("TenantId");
b.HasIndex("UserId")
.IsUnique();
b.HasIndex("TenantId", "UserId")
.IsUnique();
b.ToTable("user_profiles", null, t =>
{
t.HasCheckConstraint("ck_user_profiles_tenant_not_null", "tenant_id is not null");
t.HasCheckConstraint("ck_user_profiles_tenant_not_zero", "tenant_id <> '00000000-0000-0000-0000-000000000000'");
});
});
@@ -1251,8 +1236,13 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasKey("TenantKey");
b.HasAlternateKey("TenantId");
b.HasIndex("IsActive");
b.HasIndex("TenantId")
.IsUnique();
b.ToTable("tenants", "meta");
});
@@ -1307,6 +1297,20 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.Permission", null)
.WithMany()
.HasForeignKey("TenantId", "PermissionId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.Role", null)
.WithMany()
.HasForeignKey("TenantId", "RoleId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Permission");
b.Navigation("Role");
@@ -1316,7 +1320,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithMany("ExternalAccounts")
.HasForeignKey("UserId")
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1327,7 +1332,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithMany("Identities")
.HasForeignKey("UserId")
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1338,7 +1344,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithMany("MfaFactors")
.HasForeignKey("UserId")
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1349,7 +1356,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithMany("PasswordHistories")
.HasForeignKey("UserId")
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1370,6 +1378,20 @@ namespace AMREZ.EOP.Infrastructures.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.Role", null)
.WithMany()
.HasForeignKey("TenantId", "RoleId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", null)
.WithMany()
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Role");
b.Navigation("User");
@@ -1379,7 +1401,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithMany("Sessions")
.HasForeignKey("UserId")
.HasForeignKey("TenantId", "UserId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1390,7 +1413,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.Department", "Parent")
.WithMany("Children")
.HasForeignKey("ParentDepartmentId")
.HasForeignKey("TenantId", "ParentDepartmentId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Parent");
@@ -1400,7 +1424,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "UserProfile")
.WithMany("EmergencyContacts")
.HasForeignKey("UserProfileId")
.HasForeignKey("TenantId", "UserProfileId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1411,7 +1436,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "UserProfile")
.WithMany("Addresses")
.HasForeignKey("UserProfileId")
.HasForeignKey("TenantId", "UserProfileId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1422,7 +1448,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "UserProfile")
.WithMany("BankAccounts")
.HasForeignKey("UserProfileId")
.HasForeignKey("TenantId", "UserProfileId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1433,17 +1460,20 @@ namespace AMREZ.EOP.Infrastructures.Migrations
{
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.Department", "Department")
.WithMany()
.HasForeignKey("DepartmentId")
.HasForeignKey("TenantId", "DepartmentId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.Position", "Position")
.WithMany()
.HasForeignKey("PositionId")
.HasForeignKey("TenantId", "PositionId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "UserProfile")
.WithMany("Employments")
.HasForeignKey("UserProfileId")
.HasForeignKey("TenantId", "UserProfileId")
.HasPrincipalKey("TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -1466,7 +1496,8 @@ namespace AMREZ.EOP.Infrastructures.Migrations
b.HasOne("AMREZ.EOP.Domain.Entities.Authentications.User", "User")
.WithOne()
.HasForeignKey("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "UserId")
.HasForeignKey("AMREZ.EOP.Domain.Entities.HumanResources.UserProfile", "TenantId", "UserId")
.HasPrincipalKey("AMREZ.EOP.Domain.Entities.Authentications.User", "TenantId", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();