Skip to content

Commit

Permalink
Revert "Revert "Allow person employment establishment to be null (to …
Browse files Browse the repository at this point in the history
…support knwing someone is working but we don't know where exactly)""

This reverts commit c5cd1d2.
  • Loading branch information
hortha committed Apr 5, 2024
1 parent c5cd1d2 commit 5b7c385
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public void Configure(EntityTypeBuilder<Establishment> builder)
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");
builder.HasOne<EstablishmentSource>().WithMany().HasForeignKey(e => e.EstablishmentSourceId).HasConstraintName("fk_establishments_establishment_source_id");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public void Configure(EntityTypeBuilder<PersonEmployment> builder)
{
builder.ToTable("person_employments");
builder.HasKey(e => e.PersonEmploymentId);
builder.Property(e => e.EstablishmentId).IsRequired();
builder.Property(e => e.StartDate).IsRequired();
builder.Property(e => e.EmploymentType).IsRequired();
builder.Property(e => e.CreatedOn).IsRequired();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

Expand All @@ -11,6 +12,18 @@ public partial class EstablishmentSources : Migration
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_person_employments_establishment_id",
table: "person_employments");

migrationBuilder.AlterColumn<Guid>(
name: "establishment_id",
table: "person_employments",
type: "uuid",
nullable: true,
oldClrType: typeof(Guid),
oldType: "uuid");

migrationBuilder.AlterColumn<int>(
name: "urn",
table: "establishments",
Expand Down Expand Up @@ -123,11 +136,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
table: "person_employments",
column: "person_id");

migrationBuilder.CreateIndex(
name: "ix_establishment_establishment_source_id",
table: "establishments",
column: "establishment_source_id");

migrationBuilder.InsertData(
table: "establishment_sources",
columns: new[] { "establishment_source_id", "name" },
Expand All @@ -137,22 +145,38 @@ protected override void Up(MigrationBuilder migrationBuilder)
{ 2, "TPS" }
});

migrationBuilder.CreateIndex(
name: "ix_establishment_establishment_source_id",
table: "establishments",
column: "establishment_source_id");

migrationBuilder.AddForeignKey(
name: "fk_establishments_establishment_id",
name: "fk_establishments_establishment_source_id",
table: "establishments",
column: "establishment_source_id",
principalTable: "establishment_sources",
principalColumn: "establishment_source_id",
onDelete: ReferentialAction.Cascade);

migrationBuilder.AddForeignKey(
name: "fk_person_employments_establishment_id",
table: "person_employments",
column: "establishment_id",
principalTable: "establishments",
principalColumn: "establishment_id");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_establishments_establishment_id",
name: "fk_establishments_establishment_source_id",
table: "establishments");

migrationBuilder.DropForeignKey(
name: "fk_person_employments_establishment_id",
table: "person_employments");

migrationBuilder.DropTable(
name: "establishment_sources");

Expand All @@ -172,6 +196,16 @@ protected override void Down(MigrationBuilder migrationBuilder)
name: "establishment_source_id",
table: "establishments");

migrationBuilder.AlterColumn<Guid>(
name: "establishment_id",
table: "person_employments",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
oldClrType: typeof(Guid),
oldType: "uuid",
oldNullable: true);

migrationBuilder.AlterColumn<int>(
name: "urn",
table: "establishments",
Expand Down Expand Up @@ -269,6 +303,14 @@ protected override void Down(MigrationBuilder migrationBuilder)
oldClrType: typeof(int),
oldType: "integer",
oldNullable: true);

migrationBuilder.AddForeignKey(
name: "fk_person_employments_establishment_id",
table: "person_employments",
column: "establishment_id",
principalTable: "establishments",
principalColumn: "establishment_id",
onDelete: ReferentialAction.Cascade);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("date")
.HasColumnName("end_date");

b.Property<Guid>("EstablishmentId")
b.Property<Guid?>("EstablishmentId")
.HasColumnType("uuid")
.HasColumnName("establishment_id");

Expand Down Expand Up @@ -1864,7 +1864,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasForeignKey("EstablishmentSourceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_establishments_establishment_id");
.HasConstraintName("fk_establishments_establishment_source_id");
});

modelBuilder.Entity("TeachingRecordSystem.Core.DataStore.Postgres.Models.EytsAwardedEmailsJobItem", b =>
Expand Down Expand Up @@ -1918,8 +1918,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasOne("TeachingRecordSystem.Core.DataStore.Postgres.Models.Establishment", null)
.WithMany()
.HasForeignKey("EstablishmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_person_employments_establishment_id");

b.HasOne("TeachingRecordSystem.Core.DataStore.Postgres.Models.Person", null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class PersonEmployment

public required Guid PersonEmploymentId { get; set; }
public required Guid PersonId { get; set; }
public required Guid EstablishmentId { get; set; }
public required Guid? EstablishmentId { get; set; }
public required DateOnly StartDate { get; set; }
public required DateOnly? EndDate { get; set; }
public required EmploymentType EmploymentType { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public record PersonEmployment
{
public required Guid PersonEmploymentId { get; init; }
public required Guid PersonId { get; init; }
public required Guid EstablishmentId { get; init; }
public required Guid? EstablishmentId { get; init; }
public required DateOnly StartDate { get; init; }
public required DateOnly? EndDate { get; init; }
public required EmploymentType EmploymentType { get; init; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using TeachingRecordSystem.Core.Jobs.Scheduling;
using TeachingRecordSystem.Core.Services.Establishments;
using TeachingRecordSystem.Core.Services.WorkforceData;

namespace TeachingRecordSystem.Core.Jobs;

Expand All @@ -9,6 +8,8 @@ public class RefreshEstablishmentsJob(IBackgroundJobScheduler backgroundJobSched
public async Task ExecuteAsync(CancellationToken cancellationToken)
{
var refreshJobId = await backgroundJobScheduler.Enqueue<EstablishmentRefresher>(j => j.RefreshEstablishments(cancellationToken));
await backgroundJobScheduler.ContinueJobWith<TpsCsvExtractProcessor>(refreshJobId, j => j.UpdateLatestEstablishmentVersions(cancellationToken));

// The following is temporarily commented out as the current query was take over an hour to return and needs further investigation
// await backgroundJobScheduler.ContinueJobWith<TpsCsvExtractProcessor>(refreshJobId, j => j.UpdateLatestEstablishmentVersions(cancellationToken));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async IAsyncEnumerable<Establishment> GetEstablishments()
response.EnsureSuccessStatusCode();

using var stream = await response.Content.ReadAsStreamAsync();
// The CSV file is encoded in Windows 1252 encoding which is almost identical to Latin1 and allows Welsh characters to be read correctly
// The CSV file is encoded in Windows 1252 encoding which is almost identical to Latin1 and allows Welsh and other special characters to be read correctly
using var reader = new StreamReader(stream, Encoding.Latin1);
using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture) { HasHeaderRecord = true });

Expand Down

0 comments on commit 5b7c385

Please sign in to comment.