diff --git a/src/Bifrost.Web/Data/BifrostDbContext.cs b/src/Bifrost.Web/Data/BifrostDbContext.cs index 7b0a20d..113b3e6 100644 --- a/src/Bifrost.Web/Data/BifrostDbContext.cs +++ b/src/Bifrost.Web/Data/BifrostDbContext.cs @@ -85,6 +85,8 @@ public sealed class BifrostDbContext(DbContextOptions options) public DbSet AccountMergeEntries => Set(); + public DbSet AccountMergeNoticeAcks => Set(); + protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => @@ -676,5 +678,16 @@ public sealed class BifrostDbContext(DbContextOptions options) .HasForeignKey(x => x.MergeId) .OnDelete(DeleteBehavior.Restrict); }); + + modelBuilder.Entity(entity => + { + entity.HasKey(x => new { x.MergeId, x.Kind, x.Target }); + entity.Property(x => x.Kind).HasConversion().HasMaxLength(16); + entity.Property(x => x.Target).HasConversion().HasMaxLength(16); + entity.HasOne() + .WithMany() + .HasForeignKey(x => x.MergeId) + .OnDelete(DeleteBehavior.Restrict); + }); } } diff --git a/src/Bifrost.Web/Data/Migrations/20261114140000_AddAccountMergeNoticeAcks.cs b/src/Bifrost.Web/Data/Migrations/20261114140000_AddAccountMergeNoticeAcks.cs new file mode 100644 index 0000000..20e53c7 --- /dev/null +++ b/src/Bifrost.Web/Data/Migrations/20261114140000_AddAccountMergeNoticeAcks.cs @@ -0,0 +1,45 @@ +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Bifrost.Web.Data.Migrations +{ + // Hand-written like AddAccountMergeSaga (no dotnet-ef on the authoring host), the snapshot edited to match. Additive: one table of + // acks, the only fact a notice reader adds; the notices themselves are derived from AccountMerges. Down may drop it: it holds only acks. + [DbContext(typeof(BifrostDbContext))] + [Migration("20261114140000_AddAccountMergeNoticeAcks")] + public partial class AddAccountMergeNoticeAcks : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AccountMergeNoticeAcks", + columns: table => new + { + MergeId = table.Column(type: "uuid", nullable: false), + Kind = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + Target = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + AckedUtc = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AccountMergeNoticeAcks", x => new { x.MergeId, x.Kind, x.Target }); + table.ForeignKey( + name: "FK_AccountMergeNoticeAcks_AccountMerges_MergeId", + column: x => x.MergeId, + principalTable: "AccountMerges", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable(name: "AccountMergeNoticeAcks"); + } + } +} diff --git a/src/Bifrost.Web/Data/Migrations/BifrostDbContextModelSnapshot.cs b/src/Bifrost.Web/Data/Migrations/BifrostDbContextModelSnapshot.cs index 2d1d304..ce3e975 100644 --- a/src/Bifrost.Web/Data/Migrations/BifrostDbContextModelSnapshot.cs +++ b/src/Bifrost.Web/Data/Migrations/BifrostDbContextModelSnapshot.cs @@ -193,6 +193,27 @@ namespace Bifrost.Web.Data.Migrations b.ToTable("AccountMergeEntries"); }); + modelBuilder.Entity("Bifrost.Web.Domain.AccountMergeNoticeAck", b => + { + b.Property("MergeId") + .HasColumnType("uuid"); + + b.Property("Kind") + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("Target") + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("AckedUtc") + .HasColumnType("timestamp with time zone"); + + b.HasKey("MergeId", "Kind", "Target"); + + b.ToTable("AccountMergeNoticeAcks"); + }); + modelBuilder.Entity("Bifrost.Web.Domain.AgentDispatchRun", b => { b.Property("Id") @@ -2277,6 +2298,15 @@ namespace Bifrost.Web.Data.Migrations b.Navigation("Merge"); }); + modelBuilder.Entity("Bifrost.Web.Domain.AccountMergeNoticeAck", b => + { + b.HasOne("Bifrost.Web.Domain.AccountMerge", null) + .WithMany() + .HasForeignKey("MergeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + }); + modelBuilder.Entity("Bifrost.Web.Domain.AgentDispatchRun", b => { b.HasOne("Bifrost.Web.Domain.UserAccount", "StartedByUserAccount") diff --git a/src/Bifrost.Web/Domain/AccountMergeModels.cs b/src/Bifrost.Web/Domain/AccountMergeModels.cs index cadcac2..e95d6f6 100644 --- a/src/Bifrost.Web/Domain/AccountMergeModels.cs +++ b/src/Bifrost.Web/Domain/AccountMergeModels.cs @@ -134,3 +134,32 @@ public sealed class AccountMergeEntry public AccountMerge Merge { get; set; } = null!; } + +/// What a merge notice tells its reader: the merge committed, was undone, or can no longer be undone. Stored as a string. +public enum AccountMergeNoticeKind +{ + Merged, + Undone, + Final +} + +/// Who reads the notice feed. A closed set: a new reader is a new constant (and its own token), never a string from a request. Stored as a string. +public enum AccountMergeNoticeTarget +{ + Chat +} + +/// +/// The one fact a notice reader adds: it has seen this notice. The notice itself is derived from the merge row on every read +/// (MergeNoticeFeed) and has no stored status; nothing but the feed writes this row. +/// +public sealed class AccountMergeNoticeAck +{ + public Guid MergeId { get; set; } + + public AccountMergeNoticeKind Kind { get; set; } + + public AccountMergeNoticeTarget Target { get; set; } + + public DateTimeOffset AckedUtc { get; set; } +} diff --git a/tests/Bifrost.Web.Tests/AccountMergePostgresTests.cs b/tests/Bifrost.Web.Tests/AccountMergePostgresTests.cs index 39b0fc0..99fa74e 100644 --- a/tests/Bifrost.Web.Tests/AccountMergePostgresTests.cs +++ b/tests/Bifrost.Web.Tests/AccountMergePostgresTests.cs @@ -407,7 +407,7 @@ public sealed class AccountMergePostgresTests(MergePostgres postgres) : IClassFi { var error = await Assert.ThrowsAnyAsync(() => db.GetService().MigrateAsync("20261113120000_AddPasskeyCredentials")); Assert.Contains("roll-forward only", Pg(error).MessageText); - Assert.Equal("20261114130000_AddAccountMergeSaga", (await db.Database.GetAppliedMigrationsAsync()).Last()); + Assert.Equal("20261114140000_AddAccountMergeNoticeAcks", (await db.Database.GetAppliedMigrationsAsync()).Last()); } await ExecuteAsync(world, "DELETE FROM \"AccountMergeEntries\"; DELETE FROM \"AccountMerges\""); @@ -415,7 +415,7 @@ public sealed class AccountMergePostgresTests(MergePostgres postgres) : IClassFi await down.GetService().MigrateAsync("20261113120000_AddPasskeyCredentials"); Assert.Equal("20261113120000_AddPasskeyCredentials", (await down.Database.GetAppliedMigrationsAsync()).Last()); await down.GetService().MigrateAsync(); // and up again, trigger and index and all - Assert.Equal("20261114130000_AddAccountMergeSaga", (await down.Database.GetAppliedMigrationsAsync()).Last()); + Assert.Equal("20261114140000_AddAccountMergeNoticeAcks", (await down.Database.GetAppliedMigrationsAsync()).Last()); } // ---- restage and intake journal ---- @@ -873,7 +873,7 @@ public sealed class AccountMergePostgresTests(MergePostgres postgres) : IClassFi { var error = await Assert.ThrowsAnyAsync(() => db.GetService().MigrateAsync("20261114120000_AddAccountMerges")); Assert.Contains("AddAccountMergeSaga cannot be reverted", Pg(error).MessageText); - Assert.Equal("20261114130000_AddAccountMergeSaga", (await db.Database.GetAppliedMigrationsAsync()).Last()); + Assert.Equal("20261114140000_AddAccountMergeNoticeAcks", (await db.Database.GetAppliedMigrationsAsync()).Last()); } await ExecuteAsync(world, "DELETE FROM \"AccountMerges\""); diff --git a/tests/Bifrost.Web.Tests/MigrationDiscoveryTests.cs b/tests/Bifrost.Web.Tests/MigrationDiscoveryTests.cs index 28612ee..2085ccc 100644 --- a/tests/Bifrost.Web.Tests/MigrationDiscoveryTests.cs +++ b/tests/Bifrost.Web.Tests/MigrationDiscoveryTests.cs @@ -31,6 +31,7 @@ public sealed class MigrationDiscoveryTests "20261113120000_AddPasskeyCredentials", "20261114120000_AddAccountMerges", "20261114130000_AddAccountMergeSaga", + "20261114140000_AddAccountMergeNoticeAcks", ]; // Database.GetMigrations() reads assembly metadata only; no connection is opened.