Schema: AddAccountMergeNoticeAcks, the ack row a notice reader adds (notices themselves are derived, nothing stored)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a8c489b0d0
commit
6bd3ce4371
6 changed files with 121 additions and 3 deletions
|
|
@ -85,6 +85,8 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
|
|||
|
||||
public DbSet<AccountMergeEntry> AccountMergeEntries => Set<AccountMergeEntry>();
|
||||
|
||||
public DbSet<AccountMergeNoticeAck> AccountMergeNoticeAcks => Set<AccountMergeNoticeAck>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<UserAccount>(entity =>
|
||||
|
|
@ -676,5 +678,16 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
|
|||
.HasForeignKey(x => x.MergeId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AccountMergeNoticeAck>(entity =>
|
||||
{
|
||||
entity.HasKey(x => new { x.MergeId, x.Kind, x.Target });
|
||||
entity.Property(x => x.Kind).HasConversion<string>().HasMaxLength(16);
|
||||
entity.Property(x => x.Target).HasConversion<string>().HasMaxLength(16);
|
||||
entity.HasOne<AccountMerge>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.MergeId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AccountMergeNoticeAcks",
|
||||
columns: table => new
|
||||
{
|
||||
MergeId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Kind = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
|
||||
Target = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
|
||||
AckedUtc = table.Column<DateTimeOffset>(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);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(name: "AccountMergeNoticeAcks");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -193,6 +193,27 @@ namespace Bifrost.Web.Data.Migrations
|
|||
b.ToTable("AccountMergeEntries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bifrost.Web.Domain.AccountMergeNoticeAck", b =>
|
||||
{
|
||||
b.Property<Guid>("MergeId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Kind")
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.Property<string>("Target")
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.Property<DateTimeOffset>("AckedUtc")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("MergeId", "Kind", "Target");
|
||||
|
||||
b.ToTable("AccountMergeNoticeAcks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bifrost.Web.Domain.AgentDispatchRun", b =>
|
||||
{
|
||||
b.Property<Guid>("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")
|
||||
|
|
|
|||
|
|
@ -134,3 +134,32 @@ public sealed class AccountMergeEntry
|
|||
|
||||
public AccountMerge Merge { get; set; } = null!;
|
||||
}
|
||||
|
||||
/// <summary>What a merge notice tells its reader: the merge committed, was undone, or can no longer be undone. Stored as a string.</summary>
|
||||
public enum AccountMergeNoticeKind
|
||||
{
|
||||
Merged,
|
||||
Undone,
|
||||
Final
|
||||
}
|
||||
|
||||
/// <summary>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.</summary>
|
||||
public enum AccountMergeNoticeTarget
|
||||
{
|
||||
Chat
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public sealed class AccountMergeNoticeAck
|
||||
{
|
||||
public Guid MergeId { get; set; }
|
||||
|
||||
public AccountMergeNoticeKind Kind { get; set; }
|
||||
|
||||
public AccountMergeNoticeTarget Target { get; set; }
|
||||
|
||||
public DateTimeOffset AckedUtc { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -407,7 +407,7 @@ public sealed class AccountMergePostgresTests(MergePostgres postgres) : IClassFi
|
|||
{
|
||||
var error = await Assert.ThrowsAnyAsync<Exception>(() => db.GetService<IMigrator>().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<IMigrator>().MigrateAsync("20261113120000_AddPasskeyCredentials");
|
||||
Assert.Equal("20261113120000_AddPasskeyCredentials", (await down.Database.GetAppliedMigrationsAsync()).Last());
|
||||
await down.GetService<IMigrator>().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<Exception>(() => db.GetService<IMigrator>().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\"");
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue