Sealed-ballot motions: commit-reveal over typed gamecult.sealed_ballot.v0 documents

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Heimdall 2026-11-09 20:24:49 +00:00
commit d5a71eb639
11 changed files with 878 additions and 2 deletions

View file

@ -41,6 +41,8 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
public DbSet<Vote> Votes => Set<Vote>();
public DbSet<SealedBallot> SealedBallots => Set<SealedBallot>();
public DbSet<LedgerEntry> LedgerEntries => Set<LedgerEntry>();
public DbSet<PayoutProposalBatch> PayoutProposalBatches => Set<PayoutProposalBatch>();
@ -275,6 +277,7 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
entity.Property(x => x.Category).HasConversion<string>();
entity.Property(x => x.Status).HasConversion<string>();
entity.Property(x => x.ApprovalThreshold).HasPrecision(6, 3);
entity.Property(x => x.Kind).HasConversion<string>();
entity.HasOne(x => x.Project)
.WithMany(x => x.Motions)
.HasForeignKey(x => x.ProjectId)
@ -299,6 +302,18 @@ public sealed class BifrostDbContext(DbContextOptions<BifrostDbContext> options)
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity<SealedBallot>(entity =>
{
entity.HasIndex(x => new { x.MotionId, x.UserAccountId }).IsUnique();
entity.HasOne(x => x.Motion)
.WithMany(x => x.SealedBallots)
.HasForeignKey(x => x.MotionId);
entity.HasOne(x => x.UserAccount)
.WithMany()
.HasForeignKey(x => x.UserAccountId)
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity<LedgerEntry>(entity =>
{
entity.Property(x => x.EntryType).HasConversion<string>();

View file

@ -0,0 +1,59 @@
using System;
using Bifrost.Web.Data;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bifrost.Web.Data.Migrations
{
// Hand-written: no dotnet-ef on the authoring host. The snapshot was edited to match; BuildTargetModel is left to the base no-op.
[DbContext(typeof(BifrostDbContext))]
[Migration("20261109200000_AddSealedBallotMotions")]
public partial class AddSealedBallotMotions : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(name: "Candidates", table: "Motions", type: "text", nullable: false, defaultValue: "");
migrationBuilder.AddColumn<DateTimeOffset>(name: "CommitClosesAtUtc", table: "Motions", type: "timestamp with time zone", nullable: true);
migrationBuilder.AddColumn<string>(name: "Kind", table: "Motions", type: "text", nullable: false, defaultValue: "Standard");
migrationBuilder.AddColumn<Guid>(name: "PriorMotionId", table: "Motions", type: "uuid", nullable: true);
migrationBuilder.AddColumn<string>(name: "ResultDigest", table: "Motions", type: "text", nullable: false, defaultValue: "");
migrationBuilder.AddColumn<int>(name: "Round", table: "Motions", type: "integer", nullable: false, defaultValue: 1);
migrationBuilder.CreateTable(
name: "SealedBallots",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
MotionId = table.Column<Guid>(type: "uuid", nullable: false),
UserAccountId = table.Column<Guid>(type: "uuid", nullable: false),
Commitment = table.Column<string>(type: "text", nullable: false),
Revision = table.Column<int>(type: "integer", nullable: false),
CommittedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
RevealedCandidate = table.Column<string>(type: "text", nullable: true),
RevealedReason = table.Column<string>(type: "text", nullable: true),
Salt = table.Column<string>(type: "text", nullable: true),
RevealedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SealedBallots", x => x.Id);
table.ForeignKey("FK_SealedBallots_Motions_MotionId", x => x.MotionId, "Motions", "Id", onDelete: ReferentialAction.Cascade);
table.ForeignKey("FK_SealedBallots_UserAccounts_UserAccountId", x => x.UserAccountId, "UserAccounts", "Id", onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(name: "IX_SealedBallots_MotionId_UserAccountId", table: "SealedBallots", columns: new[] { "MotionId", "UserAccountId" }, unique: true);
migrationBuilder.CreateIndex(name: "IX_SealedBallots_UserAccountId", table: "SealedBallots", column: "UserAccountId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(name: "SealedBallots");
foreach (var column in new[] { "Candidates", "CommitClosesAtUtc", "Kind", "PriorMotionId", "ResultDigest", "Round" })
{
migrationBuilder.DropColumn(name: column, table: "Motions");
}
}
}
}

View file

@ -896,15 +896,29 @@ namespace Bifrost.Web.Data.Migrations
b.Property<DateTimeOffset>("ClosesAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("Candidates")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset?>("CommitClosesAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset>("CreatedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("CreatedByUserAccountId")
.HasColumnType("uuid");
b.Property<string>("Kind")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("OpensAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("PriorMotionId")
.HasColumnType("uuid");
b.Property<Guid?>("ProjectId")
.HasColumnType("uuid");
@ -915,6 +929,13 @@ namespace Bifrost.Web.Data.Migrations
b.Property<DateTimeOffset?>("ResolvedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("ResultDigest")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Round")
.HasColumnType("integer");
b.Property<string>("Scope")
.IsRequired()
.HasColumnType("text");
@ -1414,6 +1435,50 @@ namespace Bifrost.Web.Data.Migrations
b.ToTable("VolunteerClaims");
});
modelBuilder.Entity("Bifrost.Web.Domain.SealedBallot", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Commitment")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("CommittedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("MotionId")
.HasColumnType("uuid");
b.Property<string>("RevealedCandidate")
.HasColumnType("text");
b.Property<string>("RevealedReason")
.HasColumnType("text");
b.Property<DateTimeOffset?>("RevealedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<int>("Revision")
.HasColumnType("integer");
b.Property<string>("Salt")
.HasColumnType("text");
b.Property<Guid>("UserAccountId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserAccountId");
b.HasIndex("MotionId", "UserAccountId")
.IsUnique();
b.ToTable("SealedBallots");
});
modelBuilder.Entity("Bifrost.Web.Domain.Vote", b =>
{
b.Property<Guid>("Id")
@ -2209,6 +2274,25 @@ namespace Bifrost.Web.Data.Migrations
b.Navigation("WorkItem");
});
modelBuilder.Entity("Bifrost.Web.Domain.SealedBallot", b =>
{
b.HasOne("Bifrost.Web.Domain.Motion", "Motion")
.WithMany("SealedBallots")
.HasForeignKey("MotionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Bifrost.Web.Domain.UserAccount", "UserAccount")
.WithMany()
.HasForeignKey("UserAccountId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Motion");
b.Navigation("UserAccount");
});
modelBuilder.Entity("Bifrost.Web.Domain.Vote", b =>
{
b.HasOne("Bifrost.Web.Domain.Motion", "Motion")
@ -2331,6 +2415,8 @@ namespace Bifrost.Web.Data.Migrations
modelBuilder.Entity("Bifrost.Web.Domain.Motion", b =>
{
b.Navigation("SealedBallots");
b.Navigation("Votes");
});