fix(guild): make GuildInvite unique index partial on Status=Pending to allow re-invite after reject/cancel
Partial index (filter: "Status" = 0) replaces the unconditional unique index on (GuildId, InviteeViewerId). Old Rejected/Canceled rows no longer conflict when a new Pending invite is inserted for the same pair. Adds regression tests: Reinvite_after_reject_succeeds and Reinvite_after_cancel_succeeds. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
5008
SVSim.Database/Migrations/20260627172620_MakeGuildInviteUniqueIndexPartial.Designer.cs
generated
Normal file
5008
SVSim.Database/Migrations/20260627172620_MakeGuildInviteUniqueIndexPartial.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SVSim.Database.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class MakeGuildInviteUniqueIndexPartial : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_GuildInvites_GuildId_InviteeViewerId",
|
||||
table: "GuildInvites");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_GuildInvites_GuildId_InviteeViewerId",
|
||||
table: "GuildInvites",
|
||||
columns: new[] { "GuildId", "InviteeViewerId" },
|
||||
unique: true,
|
||||
filter: "\"Status\" = 0");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_GuildInvites_GuildId_InviteeViewerId",
|
||||
table: "GuildInvites");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_GuildInvites_GuildId_InviteeViewerId",
|
||||
table: "GuildInvites",
|
||||
columns: new[] { "GuildId", "InviteeViewerId" },
|
||||
unique: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -536,7 +536,8 @@ public class SVSimDbContext : DbContext
|
||||
e.Property(i => i.Id).ValueGeneratedOnAdd();
|
||||
e.HasOne(i => i.Guild).WithMany().HasForeignKey(i => i.GuildId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
e.HasIndex(i => new { i.GuildId, i.InviteeViewerId }).IsUnique(); // one pending invite per pair
|
||||
e.HasIndex(i => new { i.GuildId, i.InviteeViewerId }).IsUnique()
|
||||
.HasFilter("\"Status\" = 0"); // partial: one PENDING invite per pair
|
||||
e.HasIndex(i => new { i.InviteeViewerId, i.Status }); // "my pending invites"
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user