using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Projection.ReadModel.Migrations { /// /// S-19b-2 (ADR-0030): the notification log stops describing ZGW zaak events and starts holding /// the projected register row itself (register id, status, reference). /// /// /// The old columns are dropped and the new ones added rather than renamed. EF scaffolded renames /// (resource → register_id, zaak_id → status), which would carry ZGW /// values into columns that mean something else entirely — "zaak"/"status" as a register id, a /// zaak uuid as a register status — and a rebuild would then project that garbage. /// /// Both tables are emptied instead. A pre-existing row describes a zaak event the new projector /// cannot reproject, and the registrations behind those rows have no RegisterRecord in Objecten /// (only approvals wrote one before this slice), so they are not re-derivable from the new source /// either. The projection is a derived artefact (§8.4) and repopulates as register writes arrive. /// public partial class ProjectionSourcedFromObjecten : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { // ponytail: drops the pre-slice register rather than backfilling it. Fine while stacks are // ephemeral (a fresh `docker compose up` is the norm). If a long-lived environment ever // needs to keep them, backfill by walking Objecten's objects instead of replaying the log. migrationBuilder.Sql("DELETE FROM processed_notifications;"); migrationBuilder.Sql("DELETE FROM register_projection;"); migrationBuilder.DropColumn(name: "actie", table: "processed_notifications"); migrationBuilder.DropColumn(name: "zaak_id", table: "processed_notifications"); migrationBuilder.DropColumn(name: "resource", table: "processed_notifications"); migrationBuilder.AddColumn( name: "register_id", table: "processed_notifications", type: "text", nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "status", table: "processed_notifications", type: "text", nullable: false, defaultValue: ""); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.Sql("DELETE FROM processed_notifications;"); migrationBuilder.Sql("DELETE FROM register_projection;"); migrationBuilder.DropColumn(name: "register_id", table: "processed_notifications"); migrationBuilder.DropColumn(name: "status", table: "processed_notifications"); migrationBuilder.AddColumn( name: "actie", table: "processed_notifications", type: "text", nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "zaak_id", table: "processed_notifications", type: "text", nullable: false, defaultValue: ""); migrationBuilder.AddColumn( name: "resource", table: "processed_notifications", type: "text", nullable: false, defaultValue: ""); } } }