Skip to content

Commit

Permalink
Added support for multiple establishment sources
Browse files Browse the repository at this point in the history
  • Loading branch information
hortha committed Apr 4, 2024
1 parent f0c2304 commit b633284
Show file tree
Hide file tree
Showing 13 changed files with 2,404 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TeachingRecordSystem.Core.DataStore.Postgres.Models;
using Establishment = TeachingRecordSystem.Core.DataStore.Postgres.Models.Establishment;

namespace TeachingRecordSystem.Core.DataStore.Postgres.Mappings;
Expand All @@ -9,6 +10,7 @@ public void Configure(EntityTypeBuilder<Establishment> builder)
{
builder.ToTable("establishments");
builder.HasKey(e => e.EstablishmentId);
builder.Property(e => e.EstablishmentSourceId).IsRequired().HasDefaultValue(1);
builder.HasIndex(e => e.Urn).HasDatabaseName(Establishment.UrnUniqueIndexName).IsUnique();
builder.HasIndex(e => new { e.LaCode, e.EstablishmentNumber }).HasDatabaseName(Establishment.LaCodeEstablishmentNumberIndexName);
builder.Property(e => e.Urn).HasMaxLength(6).IsFixedLength();
Expand All @@ -26,5 +28,7 @@ public void Configure(EntityTypeBuilder<Establishment> builder)
builder.Property(e => e.Town).HasMaxLength(100).UseCollation("case_insensitive");
builder.Property(e => e.County).HasMaxLength(100).UseCollation("case_insensitive");
builder.Property(e => e.Postcode).HasMaxLength(10).UseCollation("case_insensitive");
builder.HasIndex(e => e.EstablishmentSourceId).HasDatabaseName(Establishment.EstablishmentSourceIdIndexName);
builder.HasOne<EstablishmentSource>().WithMany().HasForeignKey(e => e.EstablishmentSourceId).HasConstraintName("fk_establishments_establishment_id");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TeachingRecordSystem.Core.DataStore.Postgres.Models;

namespace TeachingRecordSystem.Core.DataStore.Postgres.Mappings;

public class EstablishmentSourceMapping : IEntityTypeConfiguration<EstablishmentSource>
{
public void Configure(EntityTypeBuilder<EstablishmentSource> builder)
{
builder.ToTable("establishment_sources");
builder.HasKey(e => e.EstablishmentSourceId);
builder.Property(e => e.Name).HasMaxLength(50).UseCollation("case_insensitive").IsRequired();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public void Configure(EntityTypeBuilder<PersonEmployment> builder)
builder.Property(e => e.EmploymentType).IsRequired();
builder.Property(e => e.CreatedOn).IsRequired();
builder.Property(e => e.UpdatedOn).IsRequired();
builder.HasIndex(e => e.PersonId).HasDatabaseName(PersonEmployment.PersonIdIndexName);
builder.HasIndex(e => e.EstablishmentId).HasDatabaseName(PersonEmployment.EstablishmentIdIndexName);
builder.HasOne<Person>().WithMany().HasForeignKey(e => e.PersonId).HasConstraintName("fk_person_employments_person_id");
builder.HasOne<Establishment>().WithMany().HasForeignKey(e => e.EstablishmentId).HasConstraintName("fk_person_employments_establishment_id");
}
Expand Down
Loading

0 comments on commit b633284

Please sign in to comment.