Drop AccountMerge schema, query filters, and domain properties

This commit is contained in:
Meta Vens 2026-12-03 21:29:54 +01:00
commit 7f226f7fb9
5 changed files with 57 additions and 328 deletions

View file

@ -81,12 +81,6 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
public DbSet<ConceptAppraisal> ConceptAppraisals => Set<ConceptAppraisal>();
public DbSet<AccountMerge> AccountMerges => Set<AccountMerge>();
public DbSet<AccountMergeEntry> AccountMergeEntries => Set<AccountMergeEntry>();
public DbSet<AccountMergeNoticeAck> AccountMergeNoticeAcks => Set<AccountMergeNoticeAck>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserAccount>(entity =>
@ -314,8 +308,6 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
modelBuilder.Entity<Vote>(entity =>
{
entity.HasIndex(x => new { x.MotionId, x.UserAccountId }).IsUnique();
// A merge voids a vote by stamping it; every tally reads through this filter, and only AccountMergeLedger ignores it.
entity.HasQueryFilter(x => x.VoidedByMergeId == null);
entity.Property(x => x.Choice).HasConversion<string>();
entity.Property(x => x.Weight).HasPrecision(18, 2);
entity.HasOne(x => x.Motion)
@ -622,7 +614,6 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
entity.Property(x => x.NetworkTag).HasMaxLength(64);
entity.Property(x => x.Stance).HasConversion<string>().HasMaxLength(16);
entity.Property(x => x.VoterClass).HasConversion<string>().HasMaxLength(16);
entity.HasQueryFilter(x => x.VoidedByMergeId == null);
entity.HasIndex(x => new { x.SubjectId, x.VoterKey }).IsUnique();
entity.HasIndex(x => new { x.NetworkTag, x.CastAtUtc });
entity.HasOne(x => x.Subject)
@ -634,63 +625,5 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
.HasForeignKey(x => x.UserAccountId)
.OnDelete(DeleteBehavior.SetNull);
});
modelBuilder.Entity<AccountMerge>(entity =>
{
// State is the token: a transition computed from a stale read (the sweeper's Final over a saga's UndoRequested) fails its save.
entity.Property(x => x.State).HasConversion<string>().HasMaxLength(24).IsConcurrencyToken();
entity.Property(x => x.FailureCode).HasMaxLength(64);
entity.Property(x => x.HeimdallMoveId).HasMaxLength(64);
entity.Property(x => x.HeimdallReverseMoveId).HasMaxLength(64);
entity.Property(x => x.PreviewDigest).HasMaxLength(64);
entity.Property(x => x.SurvivorProofProvider).HasMaxLength(32);
entity.Property(x => x.FoldedProofProviders).HasMaxLength(120);
entity.Property(x => x.ProofFromTier).HasMaxLength(8);
entity.Property(x => x.ProofToTier).HasMaxLength(8);
entity.Property(x => x.LastOutcome).HasMaxLength(64);
// Heimdall's idempotency keys: one merge, one forward key and one reverse key, and no key shared by two merges.
entity.HasIndex(x => x.HeimdallMoveId).IsUnique().HasFilter("\"HeimdallMoveId\" IS NOT NULL");
entity.HasIndex(x => x.HeimdallReverseMoveId).IsUnique().HasFilter("\"HeimdallReverseMoveId\" IS NOT NULL");
entity.HasIndex(x => new { x.FoldedUserAccountId, x.State });
// An account is folded once: the DB refuses a second live merge folding it. The cross-role case (a survivor that is also
// folded) cannot be one unique index; the migration's trigger refuses it.
entity.HasIndex(x => x.FoldedUserAccountId)
.IsUnique()
.HasDatabaseName("UX_AccountMerges_FoldedUserAccountId_Live")
.HasFilter("\"State\" IN ('Confirmed', 'HeimdallMoved', 'Committed', 'Final', 'UndoRequested', 'HeimdallReversed')");
entity.HasIndex(x => new { x.SurvivorUserAccountId, x.State });
entity.HasIndex(x => new { x.State, x.GraceEndsUtc });
entity.HasOne<UserAccount>()
.WithMany()
.HasForeignKey(x => x.SurvivorUserAccountId)
.OnDelete(DeleteBehavior.Restrict);
entity.HasOne<UserAccount>()
.WithMany()
.HasForeignKey(x => x.FoldedUserAccountId)
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity<AccountMergeEntry>(entity =>
{
entity.Property(x => x.Kind).HasConversion<string>().HasMaxLength(24);
entity.Property(x => x.Action).HasConversion<string>().HasMaxLength(24);
entity.Property(x => x.PriorText).HasMaxLength(120);
entity.HasIndex(x => new { x.MergeId, x.Seq }).IsUnique();
entity.HasOne(x => x.Merge)
.WithMany(x => x.Entries)
.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);
});
}
}

View file

@ -0,0 +1,56 @@
using System;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bifrost.Web.Data.Migrations
{
[DbContext(typeof(BifrostDbContext))]
[Migration("20261203120000_DropAccountMergeTables")]
public partial class DropAccountMergeTables : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"
DO $$
DECLARE
has_rows boolean;
BEGIN
IF to_regclass('public.""AccountMerges""') IS NOT NULL THEN
EXECUTE 'SELECT EXISTS (SELECT 1 FROM ""AccountMerges"")' INTO has_rows;
IF has_rows THEN
RAISE EXCEPTION 'DropAccountMergeTables refused: AccountMerges is non-empty';
END IF;
DROP TRIGGER IF EXISTS ""AccountMerges_refuse_chain"" ON ""AccountMerges"";
END IF;
END
$$;
DROP TABLE IF EXISTS ""AccountMergeNoticeAcks"", ""AccountMergeEntries"", ""AccountMerges"";
DROP FUNCTION IF EXISTS ""AccountMerges_refuse_chain""();");
migrationBuilder.DropColumn(
name: "VoidedByMergeId",
table: "Votes");
migrationBuilder.DropColumn(
name: "VoidedUtc",
table: "Votes");
migrationBuilder.DropColumn(
name: "VoidedByMergeId",
table: "ConceptAppraisals");
migrationBuilder.DropColumn(
name: "VoidedUtc",
table: "ConceptAppraisals");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
throw new NotSupportedException("AccountMerge teardown is one-way (heimdall-body:ruling:manual-merges-teardown-saga).");
}
}
}

View file

@ -22,198 +22,6 @@ namespace Bifrost.Web.Data.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Bifrost.Web.Domain.AccountMerge", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Attempts")
.HasColumnType("integer");
b.Property<DateTimeOffset?>("CommittedUtc")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("ConfirmedByUserAccountId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("ConfirmedUtc")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset>("CreatedUtc")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("FailedUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("FailureCode")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<DateTimeOffset?>("FinalizedUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("FoldedProofProviders")
.IsRequired()
.HasMaxLength(120)
.HasColumnType("character varying(120)");
b.Property<Guid>("FoldedUserAccountId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("GraceEndsUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("HeimdallMoveId")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("HeimdallReverseMoveId")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("LastOutcome")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("MovedIdentityIds")
.HasColumnType("text");
b.Property<DateTimeOffset?>("NextAttemptUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("PreviewDigest")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("ProofFromTier")
.HasMaxLength(8)
.HasColumnType("character varying(8)");
b.Property<string>("ProofToTier")
.HasMaxLength(8)
.HasColumnType("character varying(8)");
b.Property<DateTimeOffset?>("ReversedUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("SealedProofs")
.HasColumnType("text");
b.Property<string>("State")
.IsConcurrencyToken()
.IsRequired()
.HasMaxLength(24)
.HasColumnType("character varying(24)");
b.Property<string>("SurvivorProofProvider")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)");
b.Property<Guid>("SurvivorUserAccountId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("UndoneUtc")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("UndoRequestedUtc")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("FoldedUserAccountId")
.IsUnique()
.HasDatabaseName("UX_AccountMerges_FoldedUserAccountId_Live")
.HasFilter("\"State\" IN ('Confirmed', 'HeimdallMoved', 'Committed', 'Final', 'UndoRequested', 'HeimdallReversed')");
b.HasIndex("FoldedUserAccountId", "State");
b.HasIndex("HeimdallMoveId")
.IsUnique()
.HasFilter("\"HeimdallMoveId\" IS NOT NULL");
b.HasIndex("HeimdallReverseMoveId")
.IsUnique()
.HasFilter("\"HeimdallReverseMoveId\" IS NOT NULL");
b.HasIndex("State", "GraceEndsUtc");
b.HasIndex("SurvivorUserAccountId", "State");
b.ToTable("AccountMerges");
});
modelBuilder.Entity("Bifrost.Web.Domain.AccountMergeEntry", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Action")
.IsRequired()
.HasMaxLength(24)
.HasColumnType("character varying(24)");
b.Property<DateTimeOffset>("AtUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("Kind")
.IsRequired()
.HasMaxLength(24)
.HasColumnType("character varying(24)");
b.Property<Guid>("MergeId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("PriorAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("PriorText")
.HasMaxLength(120)
.HasColumnType("character varying(120)");
b.Property<Guid?>("PriorUserAccountId")
.HasColumnType("uuid");
b.Property<Guid>("RecordId")
.HasColumnType("uuid");
b.Property<int>("Seq")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("MergeId", "Seq")
.IsUnique();
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")
@ -629,12 +437,6 @@ namespace Bifrost.Web.Data.Migrations
b.Property<Guid?>("UserAccountId")
.HasColumnType("uuid");
b.Property<Guid?>("VoidedByMergeId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("VoidedUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("VoterClass")
.IsRequired()
.HasMaxLength(16)
@ -1883,12 +1685,6 @@ namespace Bifrost.Web.Data.Migrations
b.Property<Guid>("UserAccountId")
.HasColumnType("uuid");
b.Property<Guid?>("VoidedByMergeId")
.HasColumnType("uuid");
b.Property<DateTimeOffset?>("VoidedUtc")
.HasColumnType("timestamp with time zone");
b.Property<decimal>("Weight")
.HasPrecision(18, 2)
.HasColumnType("numeric(18,2)");
@ -2276,41 +2072,6 @@ namespace Bifrost.Web.Data.Migrations
b.ToTable("OpenIddictTokens", (string)null);
});
modelBuilder.Entity("Bifrost.Web.Domain.AccountMerge", b =>
{
b.HasOne("Bifrost.Web.Domain.UserAccount", null)
.WithMany()
.HasForeignKey("FoldedUserAccountId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("Bifrost.Web.Domain.UserAccount", null)
.WithMany()
.HasForeignKey("SurvivorUserAccountId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("Bifrost.Web.Domain.AccountMergeEntry", b =>
{
b.HasOne("Bifrost.Web.Domain.AccountMerge", "Merge")
.WithMany("Entries")
.HasForeignKey("MergeId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
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")
@ -2846,11 +2607,6 @@ namespace Bifrost.Web.Data.Migrations
b.Navigation("Authorization");
});
modelBuilder.Entity("Bifrost.Web.Domain.AccountMerge", b =>
{
b.Navigation("Entries");
});
modelBuilder.Entity("Bifrost.Web.Domain.Membership", b =>
{
b.Navigation("RoleAssignments");

View file

@ -7,9 +7,7 @@ public enum MembershipStatus
Authenticated,
PendingApproval,
Active,
Suspended,
/// <summary>Terminal status of a folded membership; written only by the account merge ledger, never read to decide standing.</summary>
Merged
Suspended
}
public enum MemberRole
@ -362,10 +360,6 @@ public sealed class Membership
public ICollection<TierSnapshot> TierSnapshots { get; set; } = [];
/// <summary>The folded membership of a landed merge. Terminal: only AccountMergeLedger writes it or leaves it, so every other status writer (sign-in sync, bootstrap, claim, approval, suspension) refuses a merged row.</summary>
[NotMapped]
public bool IsMerged => Status == MembershipStatus.Merged;
[NotMapped]
public decimal EffectiveVotingWeight =>
Status != MembershipStatus.Active
@ -786,11 +780,6 @@ public sealed class Vote
public DateTimeOffset CastAtUtc { get; set; }
/// <summary>Set by the account merge ledger when a merge removes this vote from every tally; the model's query filter then hides the row.</summary>
public Guid? VoidedByMergeId { get; set; }
public DateTimeOffset? VoidedUtc { get; set; }
public Motion Motion { get; set; } = null!;
public UserAccount UserAccount { get; set; } = null!;

View file

@ -46,10 +46,5 @@ public sealed class ConceptAppraisal
public DateTimeOffset CastAtUtc { get; set; }
/// <summary>Set by the account merge ledger when a merge removes this appraisal from every tally; the model's query filter then hides the row.</summary>
public Guid? VoidedByMergeId { get; set; }
public DateTimeOffset? VoidedUtc { get; set; }
public ConceptSubject? Subject { get; set; }
}