[Add] MasterData Services.
This commit is contained in:
@@ -126,6 +126,15 @@ public class AppDbContext : DbContext
|
||||
public DbSet<Allergen> Allergens => Set<Allergen>();
|
||||
public DbSet<AllergenBlock> AllergenBlocks => Set<AllergenBlock>();
|
||||
|
||||
public DbSet<Province> Provinces => Set<Province>();
|
||||
public DbSet<ProvinceBlock> ProvinceBlocks => Set<ProvinceBlock>();
|
||||
|
||||
public DbSet<District> Districts => Set<District>();
|
||||
public DbSet<DistrictBlock> DistrictBlocks => Set<DistrictBlock>();
|
||||
|
||||
public DbSet<Subdistrict> Subdistricts => Set<Subdistrict>();
|
||||
public DbSet<SubdistrictBlock> SubdistrictBlocks => Set<SubdistrictBlock>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder model)
|
||||
{
|
||||
// JSON converters/comparers
|
||||
@@ -182,7 +191,6 @@ public class AppDbContext : DbContext
|
||||
metaProp.HasColumnType("jsonb");
|
||||
|
||||
b.HasIndex(x => new { x.Scope, x.TenantId, x.Code }).IsUnique();
|
||||
// b.HasIndex(x => new { x.TenantId, x.OverridesGlobalId }).IsUnique().HasFilter("\"OverridesGlobalId\" IS NOT NULL");
|
||||
}
|
||||
|
||||
void ConfigureBlockBase<TBlock, TMaster>(string table, string schema = "master")
|
||||
@@ -780,6 +788,62 @@ public class AppDbContext : DbContext
|
||||
ConfigureMasterBase<Allergen>("allergens");
|
||||
ConfigureBlockBase<AllergenBlock, Allergen>("allergen_blocks");
|
||||
|
||||
ConfigureMasterBase<Province>("provinces");
|
||||
ConfigureBlockBase<ProvinceBlock, Province>("province_blocks");
|
||||
|
||||
model.Entity<Province>(b =>
|
||||
{
|
||||
b.Property(x => x.Code)
|
||||
.IsRequired()
|
||||
.HasMaxLength(2);
|
||||
|
||||
b.HasIndex(x => x.Code);
|
||||
});
|
||||
|
||||
ConfigureMasterBase<District>("districts");
|
||||
ConfigureBlockBase<DistrictBlock, District>("district_blocks");
|
||||
|
||||
model.Entity<District>(b =>
|
||||
{
|
||||
b.Property(x => x.Code)
|
||||
.IsRequired()
|
||||
.HasMaxLength(4);
|
||||
|
||||
b.HasIndex(x => x.Code);
|
||||
|
||||
b.HasOne(x => x.Province)
|
||||
.WithMany(p => p.Districts)
|
||||
.HasForeignKey(x => new { x.TenantId, x.ProvinceId })
|
||||
.HasPrincipalKey(p => new { p.TenantId, p.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.HasIndex(x => new { x.TenantId, x.ProvinceId });
|
||||
});
|
||||
|
||||
ConfigureMasterBase<Subdistrict>("subdistricts");
|
||||
ConfigureBlockBase<SubdistrictBlock, Subdistrict>("subdistrict_blocks");
|
||||
|
||||
model.Entity<Subdistrict>(b =>
|
||||
{
|
||||
b.Property(x => x.Code)
|
||||
.IsRequired()
|
||||
.HasMaxLength(6);
|
||||
|
||||
b.Property(x => x.Postcode)
|
||||
.HasMaxLength(10);
|
||||
|
||||
b.HasIndex(x => x.Code);
|
||||
b.HasIndex(x => x.Postcode);
|
||||
|
||||
b.HasOne(x => x.District)
|
||||
.WithMany(d => d.Subdistricts)
|
||||
.HasForeignKey(x => new { x.TenantId, x.DistrictId })
|
||||
.HasPrincipalKey(d => new { d.TenantId, d.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.HasIndex(x => new { x.TenantId, x.DistrictId });
|
||||
});
|
||||
|
||||
// ====== Enum conversions ======
|
||||
model.Entity<UserIdentity>().Property(x => x.Type).HasConversion<int>();
|
||||
model.Entity<UserMfaFactor>().Property(x => x.Type).HasConversion<int>();
|
||||
|
||||
Reference in New Issue
Block a user