Skip to content

Commit

Permalink
refactor: update projection states + rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneD committed Jun 9, 2024
1 parent 0292b26 commit da1a618
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<TotaalAantalResponse> Handle(ParcelCountOsloRequest request, C
.Items
.CountAsync(cancellationToken)
: Convert.ToInt32(_context
.ParcelDetailV2ListViewCount
.ParcelDetailListViewCount
.First()
.Count)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<ParcelDetailOsloResponseWithEtag> Handle(ParcelDetailOsloReque
{
var parcel =
await _context
.ParcelDetailWithCountV2
.ParcelDetails
.Include(x => x.Addresses)
.AsNoTracking()
.SingleOrDefaultAsync(item => item.CaPaKey == request.CaPaKey, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ParcelListOsloV2Query : Query<ParcelListV2QueryItem, ParcelFilter>
protected override IQueryable<ParcelListV2QueryItem> Filter(FilteringHeader<ParcelFilter> filtering)
{
var parcels = _context
.ParcelDetailWithCountV2
.ParcelDetails
.AsNoTracking()
.OrderBy(x => x.CaPaKey)
.Where(x => !x.Removed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace ParcelRegistry.Projections.Extract.Migrations
{
using Infrastructure;
using Microsoft.EntityFrameworkCore;

/// <inheritdoc />
public partial class DeleteOldLinksRenameNew : Migration
{
Expand Down Expand Up @@ -76,6 +79,11 @@ protected override void Up(MigrationBuilder migrationBuilder)
newName: "IX_Parcels_CaPaKey",
schema: "ParcelRegistryExtract",
table: "Parcels");

migrationBuilder.Sql(
$"DELETE FROM [{Schema.Extract}].[ProjectionStates] WHERE [Name] in ('ParcelRegistry.Projections.Extract.ParcelExtract.ParcelExtractProjections', 'ParcelRegistry.Projections.Extract.ParcelLinkExtract.ParcelLinkExtractProjections')");
migrationBuilder.Sql($"UPDATE [{Schema.Extract}].[ProjectionStates] SET [Name] = 'ParcelRegistry.Projections.Extract.ParcelLinkExtract.ParcelLinkExtractProjections' WHERE [Name] = 'ParcelRegistry.Projections.Extract.ParcelLinkExtractWithCount.ParcelLinkExtractProjections'");
migrationBuilder.Sql($"UPDATE [{Schema.Extract}].[ProjectionStates] SET [Name] = 'ParcelRegistry.Projections.Extract.ParcelExtract.ParcelExtractProjections' WHERE [Name] = 'ParcelRegistry.Projections.Extract.ParcelExtract.ParcelExtractV2Projections'");
}

/// <inheritdoc />
Expand Down Expand Up @@ -184,6 +192,9 @@ protected override void Down(MigrationBuilder migrationBuilder)
schema: "ParcelRegistryExtract",
table: "ParcelLinks",
column: "ParcelId");

migrationBuilder.Sql($"UPDATE [{Schema.Extract}].[ProjectionStates] SET [Name] = 'ParcelRegistry.Projections.Extract.ParcelLinkExtractWithCount.ParcelLinkExtractProjections' WHERE [Name] = 'ParcelRegistry.Projections.Extract.ParcelLinkExtract.ParcelLinkExtractProjections'");
migrationBuilder.Sql($"UPDATE [{Schema.Extract}].[ProjectionStates] SET [Name] = 'ParcelRegistry.Projections.Extract.ParcelExtract.ParcelExtractV2Projections' WHERE [Name] = 'ParcelRegistry.Projections.Extract.ParcelExtract.ParcelExtractProjections'");
}
}
}
8 changes: 4 additions & 4 deletions src/ParcelRegistry.Projections.Legacy/LegacyContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace ParcelRegistry.Projections.Legacy
public class LegacyContext : RunnerDbContext<LegacyContext>
{
public override string ProjectionStateSchema => Schema.Legacy;
internal const string ParcelDetailV2ListCountName = "vw_ParcelDetailV2ListCount";
public DbSet<ParcelDetail.ParcelDetail> ParcelDetailWithCountV2 { get; set; }
internal const string ParcelDetailListCountName = "vw_ParcelDetailListCount";
public DbSet<ParcelDetail.ParcelDetail> ParcelDetails { get; set; }

public DbSet<ParcelSyndicationItem> ParcelSyndication { get; set; }

public DbSet<ParcelDetailV2ListViewCount> ParcelDetailV2ListViewCount { get; set; }
public DbSet<ParcelDetailV2ListViewCount> ParcelDetailListViewCount { get; set; }

// This needs to be here to please EF
public LegacyContext() { }
Expand All @@ -28,7 +28,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<ParcelDetailV2ListViewCount>()
.HasNoKey()
.ToView(ParcelDetailV2ListCountName, Schema.Legacy);
.ToView(ParcelDetailListCountName, Schema.Legacy);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ protected override void Up(MigrationBuilder migrationBuilder)
nullable: true);

migrationBuilder.Sql($@"
CREATE VIEW [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}]
CREATE VIEW [{Infrastructure.Schema.Legacy}].[vw_ParcelDetailV2ListCount]
WITH SCHEMABINDING
AS
SELECT COUNT_BIG(*) as Count
FROM [{Infrastructure.Schema.Legacy}].[ParcelDetailsV2]
WHERE [Removed] = 0");

migrationBuilder.Sql($@"CREATE UNIQUE CLUSTERED INDEX IX_{LegacyContext.ParcelDetailV2ListCountName} ON [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}] (Count)");
migrationBuilder.Sql($@"CREATE UNIQUE CLUSTERED INDEX IX_vw_ParcelDetailV2ListCount ON [{Infrastructure.Schema.Legacy}].[vw_ParcelDetailV2ListCount] (Count)");
}

protected override void Down(MigrationBuilder migrationBuilder)
Expand All @@ -33,8 +33,8 @@ protected override void Down(MigrationBuilder migrationBuilder)
schema: "ParcelRegistryLegacy",
table: "ParcelSyndication");

migrationBuilder.Sql($@"DROP INDEX [IX_{LegacyContext.ParcelDetailV2ListCountName}] ON [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}]");
migrationBuilder.Sql($@"DROP VIEW [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}]");
migrationBuilder.Sql($@"DROP INDEX [IX_{LegacyContext.ParcelDetailListCountName}] ON [{Infrastructure.Schema.Legacy}].[vw_ParcelDetailV2ListCount]");
migrationBuilder.Sql($@"DROP VIEW [{Infrastructure.Schema.Legacy}].[vw_ParcelDetailV2ListCount]");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ public partial class UpdateListCountViewToWithCountTable : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql($@"
ALTER VIEW [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}]
ALTER VIEW [{Infrastructure.Schema.Legacy}].[vw_ParcelDetailV2ListCount]
WITH SCHEMABINDING
AS
SELECT COUNT_BIG(*) as Count
FROM [{Infrastructure.Schema.Legacy}].[{ParcelDetailConfiguration.TableName}]
FROM [{Infrastructure.Schema.Legacy}].[ParcelDetailsV2WithCount]
WHERE [Removed] = 0");

migrationBuilder.Sql($@"CREATE UNIQUE CLUSTERED INDEX IX_{LegacyContext.ParcelDetailV2ListCountName} ON [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}] (Count)");
migrationBuilder.Sql($@"CREATE UNIQUE CLUSTERED INDEX IX_vw_ParcelDetailV2ListCount ON [{Infrastructure.Schema.Legacy}].[vw_ParcelDetailV2ListCount] (Count)");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql($@"
ALTER VIEW [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}]
ALTER VIEW [{Infrastructure.Schema.Legacy}].[vw_ParcelDetailV2ListCount]
WITH SCHEMABINDING
AS
SELECT COUNT_BIG(*) as Count
FROM [{Infrastructure.Schema.Legacy}].[ParcelDetailsV2]
WHERE [Removed] = 0");

migrationBuilder.Sql($@"CREATE UNIQUE CLUSTERED INDEX IX_{LegacyContext.ParcelDetailV2ListCountName} ON [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}] (Count)");
migrationBuilder.Sql($@"CREATE UNIQUE CLUSTERED INDEX IX_vw_ParcelDetailV2ListCount ON [{Infrastructure.Schema.Legacy}].[vw_ParcelDetailV2ListCount] (Count)");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace ParcelRegistry.Projections.Legacy.Migrations
{
using Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner.ProjectionStates;
using ParcelDetail;

/// <inheritdoc />
Expand All @@ -13,7 +14,7 @@ public partial class DeleteOldRenameV2WithCount : Migration
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql($@"DROP VIEW [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}]");
migrationBuilder.Sql($@"DROP VIEW [{Infrastructure.Schema.Legacy}].[vw_ParcelDetailV2ListCount]");

migrationBuilder.DropTable(
name: "ParcelAddressesV2",
Expand Down Expand Up @@ -110,20 +111,23 @@ protected override void Up(MigrationBuilder migrationBuilder)
newName: "IX_ParcelDetails_Status");

migrationBuilder.Sql($@"
CREATE VIEW [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}]
CREATE VIEW [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailListCountName}]
WITH SCHEMABINDING
AS
SELECT COUNT_BIG(*) as Count
FROM [{Infrastructure.Schema.Legacy}].[{ParcelDetailConfiguration.TableName}]
WHERE [Removed] = 0");

migrationBuilder.Sql($@"CREATE UNIQUE CLUSTERED INDEX IX_{LegacyContext.ParcelDetailV2ListCountName} ON [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}] (Count)");
migrationBuilder.Sql($@"CREATE UNIQUE CLUSTERED INDEX IX_{LegacyContext.ParcelDetailListCountName} ON [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailListCountName}] (Count)");

migrationBuilder.Sql($"DELETE FROM [{Infrastructure.Schema.Legacy}].[ProjectionStates] WHERE [Name] = 'ParcelRegistry.Projections.Legacy.ParcelDetailV2.ParcelDetailV2Projections'");
migrationBuilder.Sql($"UPDATE [{Infrastructure.Schema.Legacy}].[ProjectionStates] SET [Name] = 'ParcelRegistry.Projections.Legacy.ParcelDetail.ParcelDetailProjections' WHERE [Name] = 'ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailV2Projections'");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql($@"DROP VIEW [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}]");
migrationBuilder.Sql($@"DROP VIEW [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailListCountName}]");

migrationBuilder.CreateTable(
name: "ParcelDetailsV2",
Expand Down Expand Up @@ -260,14 +264,16 @@ protected override void Down(MigrationBuilder migrationBuilder)
onDelete: ReferentialAction.Cascade);

migrationBuilder.Sql($@"
CREATE VIEW [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}]
CREATE VIEW [{Infrastructure.Schema.Legacy}].[vw_ParcelDetailV2ListCount]
WITH SCHEMABINDING
AS
SELECT COUNT_BIG(*) as Count
FROM [{Infrastructure.Schema.Legacy}].[{ParcelDetailConfiguration.TableName}]
WHERE [Removed] = 0");

migrationBuilder.Sql($@"CREATE UNIQUE CLUSTERED INDEX IX_{LegacyContext.ParcelDetailV2ListCountName} ON [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailV2ListCountName}] (Count)");
migrationBuilder.Sql($@"CREATE UNIQUE CLUSTERED INDEX IX_{LegacyContext.ParcelDetailListCountName} ON [{Infrastructure.Schema.Legacy}].[{LegacyContext.ParcelDetailListCountName}] (Count)");

migrationBuilder.Sql($"UPDATE [{Infrastructure.Schema.Legacy}].[ProjectionStates] SET [Name] = 'ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailV2Projections' WHERE [Name] = 'ParcelRegistry.Projections.Legacy.ParcelDetail.ParcelDetailProjections'");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static async Task<ParcelDetail> FindAndUpdateParcelDetail(
CancellationToken ct)
{
var parcel = await context
.ParcelDetailWithCountV2
.ParcelDetails
.FindAsync(parcelId, cancellationToken: ct);

if (parcel == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ParcelDetailProjections()
UpdateHash(item, message);

await context
.ParcelDetailWithCountV2
.ParcelDetails
.AddAsync(item, ct);
});

Expand Down Expand Up @@ -267,7 +267,7 @@ await context.FindAndUpdateParcelDetail(
UpdateHash(item, message);

await context
.ParcelDetailWithCountV2
.ParcelDetails
.AddAsync(item, ct);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ await Sut
new Envelope<ParcelAddressWasReplacedBecauseAddressWasReaddressed>(new Envelope(@event, eventMetadata)))
.Then(async context =>
{
var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync(parcelWasImported.ParcelId);
var parcelDetailV2 = await context.ParcelDetails.FindAsync(parcelWasImported.ParcelId);
parcelDetailV2.Should().NotBeNull();

var previousRelation = parcelDetailV2!.Addresses
Expand Down Expand Up @@ -101,7 +101,7 @@ await Sut
new Envelope<ParcelAddressWasReplacedBecauseAddressWasReaddressed>(new Envelope(@event, eventMetadata)))
.Then(async context =>
{
var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync(parcelWasImported.ParcelId);
var parcelDetailV2 = await context.ParcelDetails.FindAsync(parcelWasImported.ParcelId);
parcelDetailV2.Should().NotBeNull();

var previousRelation = parcelDetailV2!.Addresses
Expand Down Expand Up @@ -157,7 +157,7 @@ await Sut
new Envelope<ParcelAddressWasReplacedBecauseAddressWasReaddressed>(new Envelope(@event, eventMetadata)))
.Then(async context =>
{
var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync(parcelWasImported.ParcelId);
var parcelDetailV2 = await context.ParcelDetails.FindAsync(parcelWasImported.ParcelId);
parcelDetailV2.Should().NotBeNull();

var previousRelation = parcelDetailV2!.Addresses
Expand Down Expand Up @@ -235,7 +235,7 @@ await Sut
new Envelope<ParcelAddressesWereReaddressed>(new Envelope(@event, eventMetadata)))
.Then(async context =>
{
var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync(parcelWasImported.ParcelId);
var parcelDetailV2 = await context.ParcelDetails.FindAsync(parcelWasImported.ParcelId);
parcelDetailV2.Should().NotBeNull();

foreach (var addressPersistentLocalId in attachedAddressPersistentLocalIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ await Sut
{
var geometry = WKBReaderFactory.Create().Read(message.ExtendedWkbGeometry.ToByteArray());

var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync(message.ParcelId);
var parcelDetailV2 = await context.ParcelDetails.FindAsync(message.ParcelId);
parcelDetailV2.Should().NotBeNull();
parcelDetailV2!.CaPaKey.Should().Be(message.CaPaKey);
parcelDetailV2.Status.Should().Be(ParcelStatus.Parse(message.ParcelStatus));
Expand Down Expand Up @@ -81,7 +81,7 @@ await Sut
{
var geometry = WKBReaderFactory.Create().Read(message.ExtendedWkbGeometry.ToByteArray());

var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync(message.ParcelId);
var parcelDetailV2 = await context.ParcelDetails.FindAsync(message.ParcelId);
parcelDetailV2.Should().NotBeNull();
parcelDetailV2!.CaPaKey.Should().Be(message.CaPaKey);
parcelDetailV2.Status.Should().Be(ParcelStatus.Realized);
Expand All @@ -106,7 +106,7 @@ await Sut
CreateEnvelope(parcelWasRetiredV2))
.Then(async context =>
{
var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync(parcelWasRetiredV2.ParcelId);
var parcelDetailV2 = await context.ParcelDetails.FindAsync(parcelWasRetiredV2.ParcelId);
parcelDetailV2.Should().NotBeNull();
parcelDetailV2!.CaPaKey.Should().Be(parcelWasRetiredV2.CaPaKey);
parcelDetailV2.Status.Should().Be(ParcelStatus.Retired);
Expand All @@ -131,7 +131,7 @@ await Sut
CreateEnvelope(parcelGeometryWasChanged))
.Then(async context =>
{
var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync((Guid)_fixture.Create<ParcelId>());
var parcelDetailV2 = await context.ParcelDetails.FindAsync((Guid)_fixture.Create<ParcelId>());
parcelDetailV2.Should().NotBeNull();
parcelDetailV2!.Gml.Should().Be(GeometryHelpers.ValidGmlPolygon);
parcelDetailV2.GmlType.Should().Be("Polygon");
Expand All @@ -157,7 +157,7 @@ await Sut
CreateEnvelope(@event))
.Then(async context =>
{
var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync((Guid)_fixture.Create<ParcelId>());
var parcelDetailV2 = await context.ParcelDetails.FindAsync((Guid)_fixture.Create<ParcelId>());
parcelDetailV2.Should().NotBeNull();
parcelDetailV2!.Gml.Should().Be(GeometryHelpers.ValidGmlPolygon);
parcelDetailV2.GmlType.Should().Be("Polygon");
Expand Down Expand Up @@ -188,7 +188,7 @@ await Sut
new Envelope<ParcelAddressWasAttachedV2>(new Envelope(addressWasAttached, metadata2)))
.Then(async context =>
{
var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync(message.ParcelId);
var parcelDetailV2 = await context.ParcelDetails.FindAsync(message.ParcelId);
parcelDetailV2.Should().NotBeNull();
parcelDetailV2!.Addresses.Should().BeEquivalentTo(
message.AddressPersistentLocalIds
Expand Down Expand Up @@ -224,7 +224,7 @@ await Sut
new Envelope<ParcelAddressWasDetachedV2>(new Envelope(addressWasDetached, metadata2)))
.Then(async context =>
{
var parcelDetailV2 = await context.ParcelDetailWithCountV2.FindAsync(parcelWasMigrated.ParcelId);
var parcelDetailV2 = await context.ParcelDetails.FindAsync(parcelWasMigrated.ParcelId);
parcelDetailV2.Should().NotBeNull();
parcelDetailV2!.Addresses.Select(x => x.AddressPersistentLocalId).Should()
.NotContain(addressWasDetached.AddressPersistentLocalId);
Expand Down

0 comments on commit da1a618

Please sign in to comment.