- SOR.Database: 5 bounded-context DbContexts (identity, catalog, collection, bazaar, chat), all entities/enums, JSONB for card abilities, ServiceRegistration with per-context connection string fallback to "Default" - SOR.Admin: Blazor Server (.NET 8) — card editor, account management, bazaar overview, feature flags; Identity + cookie auth; FallbackPolicy requires Admin/SuperAdmin role; login via minimal API form POST endpoint - Directory.Packages.props: add Microsoft.AspNetCore.Identity.EntityFrameworkCore - SOR.slnx: add SOR.Admin + SOR.Database to solution (11 projects, 0 errors, 0 warnings) Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
namespace SOR.Database.Contexts;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SOR.Database.Entities.Collection;
|
|
|
|
/// <summary>
|
|
/// EF Core DbContext for the collection schema: player-owned cards and decks.
|
|
/// All cross-schema IDs (AccountId, CardDefinitionId) are bare Guids — no EF FKs.
|
|
///
|
|
/// Schema: "collection"
|
|
/// Run migrations: dotnet ef migrations add InitialCreate
|
|
/// --context CollectionDbContext
|
|
/// --project src/SOR.Database
|
|
/// --startup-project src/SOR.Admin
|
|
/// --output-dir Migrations/Collection
|
|
/// </summary>
|
|
public sealed class CollectionDbContext : DbContext
|
|
{
|
|
public CollectionDbContext(DbContextOptions<CollectionDbContext> options)
|
|
: base(options) { }
|
|
|
|
public DbSet<PlayerCard> PlayerCards => Set<PlayerCard>();
|
|
public DbSet<Deck> Decks => Set<Deck>();
|
|
public DbSet<DeckCard> DeckCards => Set<DeckCard>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
{
|
|
builder.HasDefaultSchema("collection");
|
|
|
|
builder.Entity<PlayerCard>(e =>
|
|
{
|
|
e.ToTable("player_cards");
|
|
e.HasKey(c => c.Id);
|
|
e.HasIndex(c => c.AccountId);
|
|
e.HasIndex(c => new { c.AccountId, c.CardDefinitionId });
|
|
});
|
|
|
|
builder.Entity<Deck>(e =>
|
|
{
|
|
e.ToTable("decks");
|
|
e.HasKey(d => d.Id);
|
|
e.HasIndex(d => d.AccountId);
|
|
e.HasMany(d => d.Cards)
|
|
.WithOne(dc => dc.Deck)
|
|
.HasForeignKey(dc => dc.DeckId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
});
|
|
|
|
builder.Entity<DeckCard>(e =>
|
|
{
|
|
e.ToTable("deck_cards");
|
|
e.HasKey(dc => dc.Id);
|
|
// Same card definition can only appear once per deck row (use Quantity for copies).
|
|
e.HasIndex(dc => new { dc.DeckId, dc.CardDefinitionId }).IsUnique();
|
|
});
|
|
}
|
|
}
|