diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 948fb71..055ddb9 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -15,7 +15,7 @@ ] }, "dotnet-ef": { - "version": "5.0.1", + "version": "6.0.3", "commands": [ "dotnet-ef" ] diff --git a/src/Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList/LastChangedListContext.cs b/src/Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList/LastChangedListContext.cs index aa79e0c..837b39e 100755 --- a/src/Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList/LastChangedListContext.cs +++ b/src/Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList/LastChangedListContext.cs @@ -4,6 +4,7 @@ namespace Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList using Microsoft.EntityFrameworkCore.Design; using Model; using Runner; + using Runner.ProjectionStates; public class LastChangedListContext : RunnerDbContext { @@ -20,53 +21,10 @@ public LastChangedListContext(DbContextOptions options) protected override void OnModelCreating(ModelBuilder modelBuilder) { - base.OnModelCreating(modelBuilder); + //base.OnModelCreating(modelBuilder); - modelBuilder - .Entity() - .Property(x => x.ToBeIndexed) - .ValueGeneratedOnAddOrUpdate() - .HasComputedColumnSql("CAST(CASE WHEN (([Position] > [LastPopulatedPosition]) AND ([ErrorCount] < 10)) THEN 1 ELSE 0 END AS bit) PERSISTED"); - - modelBuilder - .Entity() - .HasIndex(x => x.ToBeIndexed) - .IncludeProperties(x => x.LastError); - - modelBuilder - .Entity() - .HasIndex(x => x.Position); - - modelBuilder - .Entity() - .HasIndex(x => x.CacheKey); - - modelBuilder - .Entity() - .HasIndex(x => x.ErrorCount); - - modelBuilder - .Entity() - .HasIndex(x => x.LastError); - - modelBuilder - .Entity() - .HasIndex(x => new { x.ToBeIndexed, x.LastError }); - - modelBuilder - .Entity() - .HasKey(x => x.Id) - .IsClustered(); - - modelBuilder - .Entity() - .HasIndex(x => new - { - x.Position, - x.LastPopulatedPosition, - x.ErrorCount, - x.LastError - }); + modelBuilder.ApplyConfiguration(new ProjectionStatesConfiguration(ProjectionStateSchema)); + modelBuilder.ApplyConfiguration(new LastChangedRecordConfiguration(TableName, Schema)); modelBuilder .HasDefaultSchema(Schema); diff --git a/src/Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList/Model/LastChangedRecord.cs b/src/Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList/Model/LastChangedRecord.cs index cfc76d3..da9c97b 100755 --- a/src/Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList/Model/LastChangedRecord.cs +++ b/src/Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList/Model/LastChangedRecord.cs @@ -1,6 +1,8 @@ namespace Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList.Model { using System; + using Microsoft.EntityFrameworkCore; + using Microsoft.EntityFrameworkCore.Metadata.Builders; public class LastChangedRecord { @@ -18,4 +20,48 @@ public class LastChangedRecord public bool ToBeIndexed { get; private set; } } + + public class LastChangedRecordConfiguration : IEntityTypeConfiguration + { + private readonly string _tableName; + private readonly string _schema; + + public LastChangedRecordConfiguration(string tableName, string schema) + { + _tableName = tableName; + _schema = schema; + } + + public LastChangedRecordConfiguration() + { } + + public void Configure(EntityTypeBuilder builder) + { + builder + .ToTable(_tableName, _schema) + .HasKey(x => x.Id) + .IsClustered(); + + builder + .Property(x => x.ToBeIndexed) + .ValueGeneratedOnAddOrUpdate() + .HasComputedColumnSql("CAST(CASE WHEN (([Position] > [LastPopulatedPosition]) AND ([ErrorCount] < 10)) THEN 1 ELSE 0 END AS bit) PERSISTED"); + + builder + .HasIndex(x => x.ToBeIndexed) + .IncludeProperties(x => x.LastError); + builder.HasIndex(x => x.Position); + builder.HasIndex(x => x.CacheKey); + builder.HasIndex(x => x.ErrorCount); + builder.HasIndex(x => x.LastError); + builder.HasIndex(x => new { x.ToBeIndexed, x.LastError }); + builder.HasIndex(x => new + { + x.Position, + x.LastPopulatedPosition, + x.ErrorCount, + x.LastError + }); + } + } }