diff --git a/src/Bifrost.Web/Data/BifrostDbContext.cs b/src/Bifrost.Web/Data/BifrostDbContext.cs index b093dd5..21c4f40 100644 --- a/src/Bifrost.Web/Data/BifrostDbContext.cs +++ b/src/Bifrost.Web/Data/BifrostDbContext.cs @@ -81,12 +81,6 @@ public sealed class BifrostDbContext(DbContextOptions options) public DbSet ConceptAppraisals => Set(); - public DbSet AccountMerges => Set(); - - public DbSet AccountMergeEntries => Set(); - - public DbSet AccountMergeNoticeAcks => Set(); - protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => @@ -314,8 +308,6 @@ public sealed class BifrostDbContext(DbContextOptions options) modelBuilder.Entity(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(); entity.Property(x => x.Weight).HasPrecision(18, 2); entity.HasOne(x => x.Motion) @@ -622,7 +614,6 @@ public sealed class BifrostDbContext(DbContextOptions options) entity.Property(x => x.NetworkTag).HasMaxLength(64); entity.Property(x => x.Stance).HasConversion().HasMaxLength(16); entity.Property(x => x.VoterClass).HasConversion().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 options) .HasForeignKey(x => x.UserAccountId) .OnDelete(DeleteBehavior.SetNull); }); - - modelBuilder.Entity(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().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() - .WithMany() - .HasForeignKey(x => x.SurvivorUserAccountId) - .OnDelete(DeleteBehavior.Restrict); - entity.HasOne() - .WithMany() - .HasForeignKey(x => x.FoldedUserAccountId) - .OnDelete(DeleteBehavior.Restrict); - }); - - modelBuilder.Entity(entity => - { - entity.Property(x => x.Kind).HasConversion().HasMaxLength(24); - entity.Property(x => x.Action).HasConversion().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(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/20261203120000_DropAccountMergeTables.cs b/src/Bifrost.Web/Data/Migrations/20261203120000_DropAccountMergeTables.cs new file mode 100644 index 0000000..4ba5e21 --- /dev/null +++ b/src/Bifrost.Web/Data/Migrations/20261203120000_DropAccountMergeTables.cs @@ -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 + { + /// + 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"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + throw new NotSupportedException("AccountMerge teardown is one-way (heimdall-body:ruling:manual-merges-teardown-saga)."); + } + } +} diff --git a/src/Bifrost.Web/Data/Migrations/BifrostDbContextModelSnapshot.cs b/src/Bifrost.Web/Data/Migrations/BifrostDbContextModelSnapshot.cs index 267b9c0..177f21c 100644 --- a/src/Bifrost.Web/Data/Migrations/BifrostDbContextModelSnapshot.cs +++ b/src/Bifrost.Web/Data/Migrations/BifrostDbContextModelSnapshot.cs @@ -22,198 +22,6 @@ namespace Bifrost.Web.Data.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("Bifrost.Web.Domain.AccountMerge", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Attempts") - .HasColumnType("integer"); - - b.Property("CommittedUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("ConfirmedByUserAccountId") - .HasColumnType("uuid"); - - b.Property("ConfirmedUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("FailedUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("FailureCode") - .IsRequired() - .HasMaxLength(64) - .HasColumnType("character varying(64)"); - - b.Property("FinalizedUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("FoldedProofProviders") - .IsRequired() - .HasMaxLength(120) - .HasColumnType("character varying(120)"); - - b.Property("FoldedUserAccountId") - .HasColumnType("uuid"); - - b.Property("GraceEndsUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("HeimdallMoveId") - .HasMaxLength(64) - .HasColumnType("character varying(64)"); - - b.Property("HeimdallReverseMoveId") - .HasMaxLength(64) - .HasColumnType("character varying(64)"); - - b.Property("LastOutcome") - .IsRequired() - .HasMaxLength(64) - .HasColumnType("character varying(64)"); - - b.Property("MovedIdentityIds") - .HasColumnType("text"); - - b.Property("NextAttemptUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("PreviewDigest") - .IsRequired() - .HasMaxLength(64) - .HasColumnType("character varying(64)"); - - b.Property("ProofFromTier") - .HasMaxLength(8) - .HasColumnType("character varying(8)"); - - b.Property("ProofToTier") - .HasMaxLength(8) - .HasColumnType("character varying(8)"); - - b.Property("ReversedUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("SealedProofs") - .HasColumnType("text"); - - b.Property("State") - .IsConcurrencyToken() - .IsRequired() - .HasMaxLength(24) - .HasColumnType("character varying(24)"); - - b.Property("SurvivorProofProvider") - .IsRequired() - .HasMaxLength(32) - .HasColumnType("character varying(32)"); - - b.Property("SurvivorUserAccountId") - .HasColumnType("uuid"); - - b.Property("UndoneUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("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("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Action") - .IsRequired() - .HasMaxLength(24) - .HasColumnType("character varying(24)"); - - b.Property("AtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("Kind") - .IsRequired() - .HasMaxLength(24) - .HasColumnType("character varying(24)"); - - b.Property("MergeId") - .HasColumnType("uuid"); - - b.Property("PriorAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("PriorText") - .HasMaxLength(120) - .HasColumnType("character varying(120)"); - - b.Property("PriorUserAccountId") - .HasColumnType("uuid"); - - b.Property("RecordId") - .HasColumnType("uuid"); - - b.Property("Seq") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("MergeId", "Seq") - .IsUnique(); - - 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") @@ -629,12 +437,6 @@ namespace Bifrost.Web.Data.Migrations b.Property("UserAccountId") .HasColumnType("uuid"); - b.Property("VoidedByMergeId") - .HasColumnType("uuid"); - - b.Property("VoidedUtc") - .HasColumnType("timestamp with time zone"); - b.Property("VoterClass") .IsRequired() .HasMaxLength(16) @@ -1883,12 +1685,6 @@ namespace Bifrost.Web.Data.Migrations b.Property("UserAccountId") .HasColumnType("uuid"); - b.Property("VoidedByMergeId") - .HasColumnType("uuid"); - - b.Property("VoidedUtc") - .HasColumnType("timestamp with time zone"); - b.Property("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"); diff --git a/src/Bifrost.Web/Domain/BifrostModels.cs b/src/Bifrost.Web/Domain/BifrostModels.cs index 0489ef4..d3c0f5e 100644 --- a/src/Bifrost.Web/Domain/BifrostModels.cs +++ b/src/Bifrost.Web/Domain/BifrostModels.cs @@ -7,9 +7,7 @@ public enum MembershipStatus Authenticated, PendingApproval, Active, - Suspended, - /// Terminal status of a folded membership; written only by the account merge ledger, never read to decide standing. - Merged + Suspended } public enum MemberRole @@ -362,10 +360,6 @@ public sealed class Membership public ICollection TierSnapshots { get; set; } = []; - /// 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. - [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; } - /// Set by the account merge ledger when a merge removes this vote from every tally; the model's query filter then hides the row. - public Guid? VoidedByMergeId { get; set; } - - public DateTimeOffset? VoidedUtc { get; set; } - public Motion Motion { get; set; } = null!; public UserAccount UserAccount { get; set; } = null!; diff --git a/src/Bifrost.Web/Domain/ConceptVoteModels.cs b/src/Bifrost.Web/Domain/ConceptVoteModels.cs index b927c6d..b86e051 100644 --- a/src/Bifrost.Web/Domain/ConceptVoteModels.cs +++ b/src/Bifrost.Web/Domain/ConceptVoteModels.cs @@ -46,10 +46,5 @@ public sealed class ConceptAppraisal public DateTimeOffset CastAtUtc { get; set; } - /// Set by the account merge ledger when a merge removes this appraisal from every tally; the model's query filter then hides the row. - public Guid? VoidedByMergeId { get; set; } - - public DateTimeOffset? VoidedUtc { get; set; } - public ConceptSubject? Subject { get; set; } }