Add database layer (EF Core + Postgres) and Blazor Server admin site
- 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>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
namespace SOR.Database.Contexts;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Bazaar;
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for the bazaar schema: listings and transaction history.
|
||||
///
|
||||
/// Schema: "bazaar"
|
||||
/// Run migrations: dotnet ef migrations add InitialCreate
|
||||
/// --context BazaarDbContext
|
||||
/// --project src/SOR.Database
|
||||
/// --startup-project src/SOR.Admin
|
||||
/// --output-dir Migrations/Bazaar
|
||||
/// </summary>
|
||||
public sealed class BazaarDbContext : DbContext
|
||||
{
|
||||
public BazaarDbContext(DbContextOptions<BazaarDbContext> options)
|
||||
: base(options) { }
|
||||
|
||||
public DbSet<BazaarListing> Listings => Set<BazaarListing>();
|
||||
public DbSet<BazaarTransaction> Transactions => Set<BazaarTransaction>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.HasDefaultSchema("bazaar");
|
||||
|
||||
builder.Entity<BazaarListing>(e =>
|
||||
{
|
||||
e.ToTable("listings");
|
||||
e.HasKey(l => l.Id);
|
||||
e.Property(l => l.ListingType).HasConversion<string>();
|
||||
e.Property(l => l.Currency).HasConversion<string>();
|
||||
e.Property(l => l.Status).HasConversion<string>();
|
||||
e.Property(l => l.Price).HasColumnType("numeric(18,4)");
|
||||
e.HasIndex(l => l.SellerAccountId);
|
||||
e.HasIndex(l => new { l.Status, l.CardDefinitionId });
|
||||
e.HasIndex(l => new { l.Status, l.ExpiresAt });
|
||||
e.HasMany(l => l.Transactions)
|
||||
.WithOne(t => t.Listing)
|
||||
.HasForeignKey(t => t.ListingId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
builder.Entity<BazaarTransaction>(e =>
|
||||
{
|
||||
e.ToTable("transactions");
|
||||
e.HasKey(t => t.Id);
|
||||
e.Property(t => t.Currency).HasConversion<string>();
|
||||
e.Property(t => t.Amount).HasColumnType("numeric(18,4)");
|
||||
e.HasIndex(t => t.BuyerAccountId);
|
||||
e.HasIndex(t => t.SellerAccountId);
|
||||
e.HasIndex(t => t.TransactedAt);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
namespace SOR.Database.Contexts;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Catalog;
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for the catalog schema: card definitions, sets, and assets.
|
||||
/// This is read-heavy in production (clients and game servers read cards constantly)
|
||||
/// and write-heavy only from the admin tool.
|
||||
///
|
||||
/// Schema: "catalog"
|
||||
/// Run migrations: dotnet ef migrations add InitialCreate
|
||||
/// --context CatalogDbContext
|
||||
/// --project src/SOR.Database
|
||||
/// --startup-project src/SOR.Admin
|
||||
/// --output-dir Migrations/Catalog
|
||||
/// </summary>
|
||||
public sealed class CatalogDbContext : DbContext
|
||||
{
|
||||
public CatalogDbContext(DbContextOptions<CatalogDbContext> options)
|
||||
: base(options) { }
|
||||
|
||||
public DbSet<CardSet> CardSets => Set<CardSet>();
|
||||
public DbSet<CardDefinition> CardDefinitions => Set<CardDefinition>();
|
||||
public DbSet<CardAsset> CardAssets => Set<CardAsset>();
|
||||
public DbSet<CardAnimationBinding> AnimationBindings => Set<CardAnimationBinding>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.HasDefaultSchema("catalog");
|
||||
|
||||
builder.Entity<CardSet>(e =>
|
||||
{
|
||||
e.ToTable("card_sets");
|
||||
e.HasKey(s => s.Id);
|
||||
e.HasIndex(s => s.Code).IsUnique();
|
||||
e.HasMany(s => s.Cards)
|
||||
.WithOne(c => c.Set)
|
||||
.HasForeignKey(c => c.SetId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
});
|
||||
|
||||
builder.Entity<CardDefinition>(e =>
|
||||
{
|
||||
e.ToTable("card_definitions");
|
||||
e.HasKey(c => c.Id);
|
||||
|
||||
// Store enums as strings for readability in the DB and JSONB payloads.
|
||||
e.Property(c => c.CardType).HasConversion<string>();
|
||||
e.Property(c => c.Affinity).HasConversion<string>();
|
||||
e.Property(c => c.AttackType).HasConversion<string>();
|
||||
e.Property(c => c.MovementType).HasConversion<string>();
|
||||
e.Property(c => c.TerramorphaMode).HasConversion<string>();
|
||||
e.Property(c => c.Rarity).HasConversion<string>();
|
||||
|
||||
// JSONB columns — serialized by the service layer.
|
||||
e.Property(c => c.AbilitiesJson)
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("abilities");
|
||||
e.Property(c => c.EffectsJson)
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("effects");
|
||||
e.Property(c => c.OtherCostsJson)
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("other_costs");
|
||||
|
||||
// Postgres native text[] array for genus tags.
|
||||
e.Property(c => c.Genus).HasColumnType("text[]");
|
||||
|
||||
// Indexes for the most common query patterns.
|
||||
e.HasIndex(c => c.Name);
|
||||
e.HasIndex(c => c.CardType);
|
||||
e.HasIndex(c => c.Affinity);
|
||||
e.HasIndex(c => c.Rarity);
|
||||
e.HasIndex(c => new { c.IsPublished, c.SetId });
|
||||
|
||||
e.HasMany(c => c.Assets)
|
||||
.WithOne(a => a.CardDefinition)
|
||||
.HasForeignKey(a => a.CardDefinitionId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
e.HasMany(c => c.AnimationBindings)
|
||||
.WithOne(a => a.CardDefinition)
|
||||
.HasForeignKey(a => a.CardDefinitionId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
builder.Entity<CardAsset>(e =>
|
||||
{
|
||||
e.ToTable("card_assets");
|
||||
e.HasKey(a => a.Id);
|
||||
e.Property(a => a.AssetType).HasConversion<string>();
|
||||
e.HasIndex(a => new { a.CardDefinitionId, a.AssetType });
|
||||
});
|
||||
|
||||
builder.Entity<CardAnimationBinding>(e =>
|
||||
{
|
||||
e.ToTable("card_animation_bindings");
|
||||
e.HasKey(a => a.Id);
|
||||
// One action name per card — no duplicate "attack" bindings.
|
||||
e.HasIndex(a => new { a.CardDefinitionId, a.ActionName }).IsUnique();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
namespace SOR.Database.Contexts;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Chat;
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for the chat schema.
|
||||
/// At scale, high-frequency chat messages may be offloaded to a time-series store;
|
||||
/// this table serves as the durable audit log and history retrieval source.
|
||||
///
|
||||
/// Schema: "chat"
|
||||
/// Run migrations: dotnet ef migrations add InitialCreate
|
||||
/// --context ChatDbContext
|
||||
/// --project src/SOR.Database
|
||||
/// --startup-project src/SOR.Admin
|
||||
/// --output-dir Migrations/Chat
|
||||
/// </summary>
|
||||
public sealed class ChatDbContext : DbContext
|
||||
{
|
||||
public ChatDbContext(DbContextOptions<ChatDbContext> options)
|
||||
: base(options) { }
|
||||
|
||||
public DbSet<ChatChannel> Channels => Set<ChatChannel>();
|
||||
public DbSet<ChatMember> Members => Set<ChatMember>();
|
||||
public DbSet<ChatMessage> Messages => Set<ChatMessage>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.HasDefaultSchema("chat");
|
||||
|
||||
builder.Entity<ChatChannel>(e =>
|
||||
{
|
||||
e.ToTable("channels");
|
||||
e.HasKey(c => c.Id);
|
||||
e.Property(c => c.ChannelType).HasConversion<string>();
|
||||
e.HasIndex(c => c.ChannelType);
|
||||
e.HasIndex(c => c.MatchId);
|
||||
e.HasMany(c => c.Members)
|
||||
.WithOne(m => m.Channel)
|
||||
.HasForeignKey(m => m.ChannelId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
e.HasMany(c => c.Messages)
|
||||
.WithOne(m => m.Channel)
|
||||
.HasForeignKey(m => m.ChannelId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
builder.Entity<ChatMember>(e =>
|
||||
{
|
||||
e.ToTable("members");
|
||||
e.HasKey(m => m.Id);
|
||||
e.HasIndex(m => new { m.ChannelId, m.AccountId }).IsUnique();
|
||||
e.HasIndex(m => m.AccountId);
|
||||
});
|
||||
|
||||
builder.Entity<ChatMessage>(e =>
|
||||
{
|
||||
e.ToTable("messages");
|
||||
e.HasKey(m => m.Id);
|
||||
e.HasIndex(m => new { m.ChannelId, m.SentAt });
|
||||
e.HasIndex(m => m.SenderAccountId);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
namespace SOR.Database.Contexts;
|
||||
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for the identity schema.
|
||||
/// Extends IdentityDbContext so ASP.NET Core Identity manages users, roles,
|
||||
/// claims, external logins, and tokens. We add AccountSession for explicit
|
||||
/// session revocation.
|
||||
///
|
||||
/// Schema: "identity"
|
||||
/// Run migrations: dotnet ef migrations add InitialCreate
|
||||
/// --context SorIdentityDbContext
|
||||
/// --project src/SOR.Database
|
||||
/// --startup-project src/SOR.Admin
|
||||
/// --output-dir Migrations/Identity
|
||||
/// </summary>
|
||||
public sealed class SorIdentityDbContext
|
||||
: IdentityDbContext<Account, IdentityRole<Guid>, Guid>
|
||||
{
|
||||
public SorIdentityDbContext(DbContextOptions<SorIdentityDbContext> options)
|
||||
: base(options) { }
|
||||
|
||||
public DbSet<AccountSession> AccountSessions => Set<AccountSession>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
// MUST call base — Identity configures its own tables here.
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.HasDefaultSchema("identity");
|
||||
|
||||
// Rename Identity's default AspNet* tables to snake_case.
|
||||
builder.Entity<Account>().ToTable("accounts");
|
||||
builder.Entity<IdentityRole<Guid>>().ToTable("roles");
|
||||
builder.Entity<IdentityUserRole<Guid>>().ToTable("account_roles");
|
||||
builder.Entity<IdentityUserClaim<Guid>>().ToTable("account_claims");
|
||||
builder.Entity<IdentityUserLogin<Guid>>().ToTable("external_logins");
|
||||
builder.Entity<IdentityRoleClaim<Guid>>().ToTable("role_claims");
|
||||
builder.Entity<IdentityUserToken<Guid>>().ToTable("account_tokens");
|
||||
|
||||
builder.Entity<Account>(e =>
|
||||
{
|
||||
e.HasIndex(a => a.DisplayName);
|
||||
});
|
||||
|
||||
builder.Entity<AccountSession>(e =>
|
||||
{
|
||||
e.ToTable("account_sessions");
|
||||
e.HasKey(s => s.Id);
|
||||
// Hash lookup must be unique and fast.
|
||||
e.HasIndex(s => s.TokenHash).IsUnique();
|
||||
// Compound index: find all active sessions for an account quickly.
|
||||
e.HasIndex(s => new { s.AccountId, s.ExpiresAt });
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace SOR.Database.Entities.Bazaar;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// A player's offer to sell a card on the bazaar.
|
||||
///
|
||||
/// CardDefinitionId is denormalized (also on PlayerCard) to allow efficient
|
||||
/// filtering/searching without joining to the collection schema.
|
||||
///
|
||||
/// All cross-schema Guids have no EF FKs by design.
|
||||
/// </summary>
|
||||
public sealed class BazaarListing
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Cross-schema: seller's account.</summary>
|
||||
public Guid SellerAccountId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: the specific card instance being listed.</summary>
|
||||
public Guid PlayerCardId { get; set; }
|
||||
|
||||
/// <summary>Denormalized from PlayerCard for query performance.</summary>
|
||||
public Guid CardDefinitionId { get; set; }
|
||||
|
||||
public BazaarListingType ListingType { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
public BazaarCurrency Currency { get; set; }
|
||||
public DateTimeOffset ListedAt { get; set; }
|
||||
public DateTimeOffset? ExpiresAt { get; set; }
|
||||
public BazaarListingStatus Status { get; set; } = BazaarListingStatus.Active;
|
||||
|
||||
public ICollection<BazaarTransaction> Transactions { get; set; } = new List<BazaarTransaction>();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace SOR.Database.Entities.Bazaar;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Immutable record of a completed bazaar sale.
|
||||
/// Created when a listing transitions to Sold status.
|
||||
/// Never updated or deleted — the full audit trail is preserved.
|
||||
/// </summary>
|
||||
public sealed class BazaarTransaction
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid ListingId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: buyer's account.</summary>
|
||||
public Guid BuyerAccountId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: seller's account (denormalized from listing).</summary>
|
||||
public Guid SellerAccountId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: the card instance that changed hands.</summary>
|
||||
public Guid PlayerCardId { get; set; }
|
||||
|
||||
public decimal Amount { get; set; }
|
||||
public BazaarCurrency Currency { get; set; }
|
||||
public DateTimeOffset TransactedAt { get; set; }
|
||||
|
||||
public BazaarListing Listing { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace SOR.Database.Entities.Catalog;
|
||||
|
||||
/// <summary>
|
||||
/// Binds a named in-game action to an animation CDN asset for a specific card.
|
||||
///
|
||||
/// ActionName is a free-form string matching the action identifiers used by the
|
||||
/// game engine and client renderer, e.g.:
|
||||
/// "idle", "attack", "defend", "death", "channel",
|
||||
/// "ability_0", "ability_1" (per ability index),
|
||||
/// "ascend", "transition"
|
||||
///
|
||||
/// This keeps animation bindings flexible — adding new action types requires
|
||||
/// no schema change, only a new row per card.
|
||||
/// </summary>
|
||||
public sealed class CardAnimationBinding
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid CardDefinitionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Action identifier string as expected by the client renderer.
|
||||
/// Examples: "idle", "attack", "death", "ability_0", "ascend".
|
||||
/// </summary>
|
||||
public string ActionName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>CDN URL to the animation file (glTF animation, Spine, etc.).</summary>
|
||||
public string AnimationCdnUrl { get; set; } = string.Empty;
|
||||
|
||||
public CardDefinition CardDefinition { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace SOR.Database.Entities.Catalog;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Links a card definition to one of its static CDN assets (2D art or 3D model).
|
||||
/// A card may have multiple assets of different types (e.g. one Art2D + one Model3D).
|
||||
/// Animations are separate — see CardAnimationBinding.
|
||||
/// </summary>
|
||||
public sealed class CardAsset
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid CardDefinitionId { get; set; }
|
||||
public CardAssetType AssetType { get; set; }
|
||||
|
||||
/// <summary>Full CDN URL, e.g. https://cdn.sor.gg/cards/{id}/art.webp</summary>
|
||||
public string CdnUrl { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>MIME type of the asset, e.g. image/webp, model/gltf-binary.</summary>
|
||||
public string? MimeType { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
public CardDefinition CardDefinition { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
namespace SOR.Database.Entities.Catalog;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// The immutable definition of a card — what it IS, not who owns a copy.
|
||||
///
|
||||
/// Core stats are stored as typed columns for fast filtering and sorting
|
||||
/// (name, type, affinity, costs, combat stats).
|
||||
///
|
||||
/// The ability/effect system is highly recursive and type-specific, so it is
|
||||
/// stored as JSONB. The game engine and admin tool own serialization.
|
||||
/// AbilitiesJson: used by ArchSpirit, Spirit, Ruin.
|
||||
/// EffectsJson: used by Repentance, Instinct, Terramorpha.
|
||||
///
|
||||
/// Genus tags are stored as a Postgres text[] array — fast for containment
|
||||
/// queries (@>) without the overhead of a junction table.
|
||||
/// </summary>
|
||||
public sealed class CardDefinition
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
// ── Shared (all card types) ─────────────────────────────────────────────
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public CardType CardType { get; set; }
|
||||
public Affinity Affinity { get; set; }
|
||||
public int SpCost { get; set; }
|
||||
public int StCost { get; set; }
|
||||
|
||||
/// <summary>JSONB: additional non-SP/ST costs (e.g. discard a card).</summary>
|
||||
public string? OtherCostsJson { get; set; }
|
||||
|
||||
// ── Unit properties (ArchSpirit + Spirit) ───────────────────────────────
|
||||
public int? MinChannelRange { get; set; }
|
||||
public int? MaxChannelRange { get; set; }
|
||||
public AttackType? AttackType { get; set; }
|
||||
public bool? RequiresLos { get; set; }
|
||||
public int? MinAttackRange { get; set; }
|
||||
public int? MaxAttackRange { get; set; }
|
||||
public bool? CanAttack { get; set; }
|
||||
public int? Damage { get; set; }
|
||||
public bool? CanDefend { get; set; }
|
||||
public int? MaxHealth { get; set; }
|
||||
public int? MaxDefense { get; set; }
|
||||
public bool? CanBeAttacked { get; set; }
|
||||
public bool? CanBeBlocked { get; set; }
|
||||
public bool? CanMove { get; set; }
|
||||
public MovementType? MovementType { get; set; }
|
||||
public int? MovementPoints { get; set; }
|
||||
public bool? CanBeObstructed { get; set; }
|
||||
public bool? CanUseAbility { get; set; }
|
||||
|
||||
/// <summary>Postgres text[]: genus classification tags (e.g. "Elemental", "Beast").</summary>
|
||||
public string[]? Genus { get; set; }
|
||||
|
||||
// ── Spirit-only ─────────────────────────────────────────────────────────
|
||||
public bool? CanBeSacrificed { get; set; }
|
||||
|
||||
// ── ArchSpirit-only ─────────────────────────────────────────────────────
|
||||
/// <summary>Tier 1 = base form; higher tiers reached via Ascend/Transition.</summary>
|
||||
public int? Tier { get; set; }
|
||||
|
||||
// ── Terramorpha-only ────────────────────────────────────────────────────
|
||||
public TerramorphaMode? TerramorphaMode { get; set; }
|
||||
|
||||
// ── Ability / Effect data (JSONB) ────────────────────────────────────────
|
||||
/// <summary>JSONB array of AbilityDefinition objects (ArchSpirit, Spirit, Ruin).</summary>
|
||||
public string? AbilitiesJson { get; set; }
|
||||
|
||||
/// <summary>JSONB array of Action objects (Repentance, Instinct, Terramorpha).</summary>
|
||||
public string? EffectsJson { get; set; }
|
||||
|
||||
// ── Publishing metadata ──────────────────────────────────────────────────
|
||||
public CardRarity Rarity { get; set; } = CardRarity.Common;
|
||||
public Guid? SetId { get; set; }
|
||||
public int? CollectorNumber { get; set; }
|
||||
|
||||
/// <summary>Only published cards are visible in the client and available for collection.</summary>
|
||||
public bool IsPublished { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
|
||||
// ── Navigation ───────────────────────────────────────────────────────────
|
||||
public CardSet? Set { get; set; }
|
||||
public ICollection<CardAsset> Assets { get; set; } = new List<CardAsset>();
|
||||
public ICollection<CardAnimationBinding> AnimationBindings { get; set; } = new List<CardAnimationBinding>();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace SOR.Database.Entities.Catalog;
|
||||
|
||||
/// <summary>
|
||||
/// A named release of cards (base set, expansion, promo, etc.).
|
||||
/// Cards reference their set for collector numbering and filtering.
|
||||
/// </summary>
|
||||
public sealed class CardSet
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Human-readable set name, e.g. "Core Set", "Shattered Realms".</summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Short uppercase code used in collector numbers, e.g. "BASE", "SR1".</summary>
|
||||
public string Code { get; set; } = string.Empty;
|
||||
|
||||
public string? Description { get; set; }
|
||||
|
||||
public DateOnly? ReleaseDate { get; set; }
|
||||
|
||||
/// <summary>Whether the set is currently active / legal for play.</summary>
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
public ICollection<CardDefinition> Cards { get; set; } = new List<CardDefinition>();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace SOR.Database.Entities.Chat;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
public sealed class ChatChannel
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public ChatChannelType ChannelType { get; set; }
|
||||
|
||||
/// <summary>For Match channels: the match ID this channel belongs to.</summary>
|
||||
public string? MatchId { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
public ICollection<ChatMember> Members { get; set; } = new List<ChatMember>();
|
||||
public ICollection<ChatMessage> Messages { get; set; } = new List<ChatMessage>();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace SOR.Database.Entities.Chat;
|
||||
|
||||
public sealed class ChatMember
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid ChannelId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: no EF FK to identity.accounts.</summary>
|
||||
public Guid AccountId { get; set; }
|
||||
|
||||
public DateTimeOffset JoinedAt { get; set; }
|
||||
|
||||
/// <summary>Set when the member explicitly leaves or is removed.</summary>
|
||||
public DateTimeOffset? LeftAt { get; set; }
|
||||
|
||||
public ChatChannel Channel { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace SOR.Database.Entities.Chat;
|
||||
|
||||
public sealed class ChatMessage
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid ChannelId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: no EF FK to identity.accounts.</summary>
|
||||
public Guid SenderAccountId { get; set; }
|
||||
|
||||
public string Content { get; set; } = string.Empty;
|
||||
public DateTimeOffset SentAt { get; set; }
|
||||
public DateTimeOffset? EditedAt { get; set; }
|
||||
|
||||
/// <summary>Soft-delete: content is cleared but the row is kept for audit.</summary>
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
public ChatChannel Channel { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace SOR.Database.Entities.Collection;
|
||||
|
||||
/// <summary>
|
||||
/// A named deck belonging to a player.
|
||||
/// Each deck has exactly one ArchSpirit and any number of other cards.
|
||||
/// IsValid is set by the server after validating against current deck construction rules.
|
||||
/// </summary>
|
||||
public sealed class Deck
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Owner. Cross-schema: no EF FK to identity.accounts.</summary>
|
||||
public Guid AccountId { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ArchSpirit card definition this deck is built around.
|
||||
/// Cross-schema: no EF FK to catalog.card_definitions.
|
||||
/// </summary>
|
||||
public Guid ArchSpiritCardDefinitionId { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True when last validated against deck construction rules.
|
||||
/// Re-validated on each change and at match start.
|
||||
/// </summary>
|
||||
public bool IsValid { get; set; }
|
||||
|
||||
public ICollection<DeckCard> Cards { get; set; } = new List<DeckCard>();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace SOR.Database.Entities.Collection;
|
||||
|
||||
/// <summary>
|
||||
/// One card slot in a deck: which card definition and how many copies.
|
||||
/// Cross-schema: CardDefinitionId is a bare Guid with no EF FK.
|
||||
/// </summary>
|
||||
public sealed class DeckCard
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid DeckId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: no EF FK to catalog.card_definitions.</summary>
|
||||
public Guid CardDefinitionId { get; set; }
|
||||
|
||||
public int Quantity { get; set; } = 1;
|
||||
|
||||
public Deck Deck { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace SOR.Database.Entities.Collection;
|
||||
|
||||
/// <summary>
|
||||
/// One physical copy of a card owned by a player.
|
||||
///
|
||||
/// CardDefinitionId references the catalog schema — intentionally no EF FK
|
||||
/// (cross-schema references are by Guid only).
|
||||
///
|
||||
/// Multiple copies of the same CardDefinitionId may exist per account;
|
||||
/// each row is a distinct, individually tradeable instance.
|
||||
/// </summary>
|
||||
public sealed class PlayerCard
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Owning player. Cross-schema: no EF FK to identity.accounts.</summary>
|
||||
public Guid AccountId { get; set; }
|
||||
|
||||
/// <summary>Template definition. Cross-schema: no EF FK to catalog.card_definitions.</summary>
|
||||
public Guid CardDefinitionId { get; set; }
|
||||
|
||||
public DateTimeOffset AcquiredAt { get; set; }
|
||||
|
||||
/// <summary>Foil/premium visual variant of the card art.</summary>
|
||||
public bool IsFoil { get; set; }
|
||||
|
||||
/// <summary>Sequential print number for limited/numbered cards. Null = unlimited.</summary>
|
||||
public int? SerialNumber { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace SOR.Database.Entities.Identity;
|
||||
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Extends ASP.NET Core Identity's IdentityUser with SOR-specific profile fields.
|
||||
///
|
||||
/// Identity manages: email, password hash, lockout, two-factor, external logins.
|
||||
/// We add: display name (in-game handle), avatar CDN URL, audit timestamps.
|
||||
///
|
||||
/// Ban handling uses Identity's built-in LockoutEnd + LockoutEnabled — no
|
||||
/// separate ban table needed for basic bans. A separate audit log of ban
|
||||
/// actions can be added later.
|
||||
/// </summary>
|
||||
public sealed class Account : IdentityUser<Guid>
|
||||
{
|
||||
/// <summary>Publicly visible in-game display name (not the login email).</summary>
|
||||
public string? DisplayName { get; set; }
|
||||
|
||||
/// <summary>CDN URL to the player's avatar image.</summary>
|
||||
public string? AvatarCdnUrl { get; set; }
|
||||
|
||||
/// <summary>UTC time the account was first created.</summary>
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
/// <summary>UTC time of the most recent successful login.</summary>
|
||||
public DateTimeOffset? LastLoginAt { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace SOR.Database.Entities.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Tracks an issued session token so it can be explicitly revoked
|
||||
/// (logout, password change, ban) before it naturally expires.
|
||||
///
|
||||
/// The raw token is never stored — only its SHA-256 hash is kept so
|
||||
/// that a stolen database row cannot be replayed.
|
||||
///
|
||||
/// The Gateway validates tokens by hashing the incoming token and
|
||||
/// looking it up here, checking RevokedAt == null and ExpiresAt > now.
|
||||
/// </summary>
|
||||
public sealed class AccountSession
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Owner of this session. No FK to preserve cross-schema flexibility.</summary>
|
||||
public Guid AccountId { get; set; }
|
||||
|
||||
/// <summary>SHA-256 hex digest of the raw session token.</summary>
|
||||
public string TokenHash { get; set; } = string.Empty;
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset ExpiresAt { get; set; }
|
||||
|
||||
/// <summary>Set when the session is explicitly invalidated (logout, ban, password change).</summary>
|
||||
public DateTimeOffset? RevokedAt { get; set; }
|
||||
|
||||
public string? IpAddress { get; set; }
|
||||
public string? UserAgent { get; set; }
|
||||
|
||||
/// <summary>Optional opaque device identifier supplied by the client.</summary>
|
||||
public string? DeviceId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// All valid card/tile affinity values.
|
||||
///
|
||||
/// Basic affinities (the six primaries): Void, Aether, Lake, Hill, Forest, Field.
|
||||
/// Non-basic affinities are combinations of two basics via the tile slot system
|
||||
/// (Base1 + Base2). See affinity.md for full combination rules.
|
||||
///
|
||||
/// Cards may only carry basic and standard non-basic affinities.
|
||||
/// Gateway and UnstableAether affinities are tile-only — they cannot appear on cards.
|
||||
/// </summary>
|
||||
public enum Affinity
|
||||
{
|
||||
// ── Basic ──────────────────────────────────────────────────────────────
|
||||
Void,
|
||||
Aether,
|
||||
Lake,
|
||||
Hill,
|
||||
Forest,
|
||||
Field,
|
||||
|
||||
// ── Standard non-basic (two-basic combinations) ───────────────────────
|
||||
Ocean, // Lake + Lake
|
||||
Island, // Lake + Hill
|
||||
Marsh, // Lake + Forest
|
||||
Swamp, // Lake + Field
|
||||
Mountain, // Hill + Hill
|
||||
Steppe, // Hill + Forest
|
||||
Fort, // Hill + Field
|
||||
Plains, // Forest + Field
|
||||
Grove, // Forest + Forest
|
||||
Jungle, // Field + Field
|
||||
|
||||
// ── Aether combinations ───────────────────────────────────────────────
|
||||
UnstableAether, // Aether + any non-Aether (tile-only, cannot appear on cards)
|
||||
PerfectAether, // Aether + Aether
|
||||
|
||||
// ── Void combinations ─────────────────────────────────────────────────
|
||||
PureVoid, // Void + Void
|
||||
|
||||
// ── Gateway (Void + one basic, tile-only) ─────────────────────────────
|
||||
GatewayLake,
|
||||
GatewayHill,
|
||||
GatewayForest,
|
||||
GatewayField,
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace SOR.Database.Enums;
|
||||
|
||||
public enum BazaarListingStatus
|
||||
{
|
||||
Active,
|
||||
Sold,
|
||||
Cancelled,
|
||||
Expired,
|
||||
}
|
||||
|
||||
public enum BazaarListingType
|
||||
{
|
||||
/// <summary>Buy-it-now at a fixed price.</summary>
|
||||
Fixed,
|
||||
/// <summary>Timed auction — highest bid wins.</summary>
|
||||
Auction,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// In-game currency types.
|
||||
/// Gold: earned through gameplay, tradeable.
|
||||
/// Premium: purchased with real money, non-tradeable.
|
||||
/// </summary>
|
||||
public enum BazaarCurrency
|
||||
{
|
||||
Gold,
|
||||
Premium,
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
namespace SOR.Database.Enums;
|
||||
|
||||
public enum CardType
|
||||
{
|
||||
ArchSpirit,
|
||||
Spirit,
|
||||
Repentance,
|
||||
Terramorpha,
|
||||
Ruin,
|
||||
Instinct,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How a unit's attack is resolved on the battlefield.
|
||||
/// The exact attack resolution rules are defined in gameplay.md.
|
||||
/// </summary>
|
||||
public enum AttackType
|
||||
{
|
||||
Melee,
|
||||
Ranged,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Governs how a unit traverses the battlefield.
|
||||
/// Walk: blocked by any unit.
|
||||
/// Flight: blocked by other Flight units only.
|
||||
/// Jump: unblocked, min/max tile range, costs 1 MP per landing tile.
|
||||
/// Teleport: unblocked, min/max range, requires line-of-sight, costs 1 MP per tile.
|
||||
/// </summary>
|
||||
public enum MovementType
|
||||
{
|
||||
Walk,
|
||||
Flight,
|
||||
Jump,
|
||||
Teleport,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How many affinity tiles a Terramorpha card affects when channeled.
|
||||
/// Mono = 1 tile, Di = 2 adjacent tiles, Tri = 3 adjacent tiles.
|
||||
/// </summary>
|
||||
public enum TerramorphaMode
|
||||
{
|
||||
Mono,
|
||||
Di,
|
||||
Tri,
|
||||
}
|
||||
|
||||
public enum CardRarity
|
||||
{
|
||||
Common,
|
||||
Uncommon,
|
||||
Rare,
|
||||
Epic,
|
||||
Legendary,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Discriminates the type of CDN asset linked to a card.
|
||||
/// Art2D: flat card illustration shown in hand/collection views.
|
||||
/// Model3D: glTF/GLB model rendered on the battlefield.
|
||||
/// </summary>
|
||||
public enum CardAssetType
|
||||
{
|
||||
Art2D,
|
||||
Model3D,
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace SOR.Database.Enums;
|
||||
|
||||
public enum ChatChannelType
|
||||
{
|
||||
/// <summary>Server-wide public chat.</summary>
|
||||
Global,
|
||||
/// <summary>Private channel for an active match.</summary>
|
||||
Match,
|
||||
/// <summary>Direct message between two accounts.</summary>
|
||||
Direct,
|
||||
/// <summary>Guild/clan channel.</summary>
|
||||
Guild,
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>SOR.Database</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Identity types live in Microsoft.AspNetCore.App -->
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
|
||||
<!-- Design-time only: enables 'dotnet ef migrations add' -->
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,74 @@
|
||||
namespace SOR.Database;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SOR.Database.Contexts;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods to register each DbContext independently.
|
||||
/// Each service only calls the extension(s) it needs.
|
||||
///
|
||||
/// All contexts fall back to "Default" if a context-specific connection string
|
||||
/// is absent, so a single connection string works during local development
|
||||
/// while production can split contexts across servers by overriding individual keys.
|
||||
///
|
||||
/// Connection string key precedence (highest to lowest):
|
||||
/// ConnectionStrings:{ContextName} → ConnectionStrings:Default
|
||||
/// </summary>
|
||||
public static class ServiceRegistration
|
||||
{
|
||||
public static IServiceCollection AddIdentityDatabase(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<SorIdentityDbContext>(opts =>
|
||||
opts.UseNpgsql(Resolve(configuration, "Identity")));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddCatalogDatabase(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<CatalogDbContext>(opts =>
|
||||
opts.UseNpgsql(Resolve(configuration, "Catalog")));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddCollectionDatabase(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<CollectionDbContext>(opts =>
|
||||
opts.UseNpgsql(Resolve(configuration, "Collection")));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddBazaarDatabase(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<BazaarDbContext>(opts =>
|
||||
opts.UseNpgsql(Resolve(configuration, "Bazaar")));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddChatDatabase(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<ChatDbContext>(opts =>
|
||||
opts.UseNpgsql(Resolve(configuration, "Chat")));
|
||||
return services;
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
private static string Resolve(IConfiguration configuration, string contextName)
|
||||
=> configuration.GetConnectionString(contextName)
|
||||
?? configuration.GetConnectionString("Default")
|
||||
?? throw new InvalidOperationException(
|
||||
$"Missing connection string: '{contextName}' or 'Default'. " +
|
||||
"Add it to appsettings.json or environment variables.");
|
||||
}
|
||||
Reference in New Issue
Block a user