From 4455eabc2508ad812dcb269e30770314b37c947c Mon Sep 17 00:00:00 2001 From: milimoe Date: Mon, 9 Nov 2026 20:59:09 +0800 Subject: [PATCH] feat(S5): add EF Core SQLite context with 33 P0-P2 tables and initial migration --- OshimaBot/Data/BotDbContext.cs | 185 +++ OshimaBot/Data/DatabaseInitializer.cs | 31 + OshimaBot/Data/Economy.cs | 68 ++ OshimaBot/Data/Identity.cs | 64 ++ .../20261109125643_Initial.Designer.cs | 1009 +++++++++++++++++ .../Data/Migrations/20261109125643_Initial.cs | 799 +++++++++++++ .../Migrations/BotDbContextModelSnapshot.cs | 1006 ++++++++++++++++ OshimaBot/Data/PlayerState.cs | 175 +++ OshimaBot/Data/SystemEntities.cs | 49 + OshimaBot/OshimaBot.csproj | 5 + OshimaBot/Program.cs | 17 + OshimaBot/appsettings.json | 2 +- 12 files changed, 3409 insertions(+), 1 deletion(-) create mode 100644 OshimaBot/Data/BotDbContext.cs create mode 100644 OshimaBot/Data/DatabaseInitializer.cs create mode 100644 OshimaBot/Data/Economy.cs create mode 100644 OshimaBot/Data/Identity.cs create mode 100644 OshimaBot/Data/Migrations/20261109125643_Initial.Designer.cs create mode 100644 OshimaBot/Data/Migrations/20261109125643_Initial.cs create mode 100644 OshimaBot/Data/Migrations/BotDbContextModelSnapshot.cs create mode 100644 OshimaBot/Data/PlayerState.cs create mode 100644 OshimaBot/Data/SystemEntities.cs diff --git a/OshimaBot/Data/BotDbContext.cs b/OshimaBot/Data/BotDbContext.cs new file mode 100644 index 0000000..0c99663 --- /dev/null +++ b/OshimaBot/Data/BotDbContext.cs @@ -0,0 +1,185 @@ +using Microsoft.EntityFrameworkCore; +using OshimaBot.Data.Entities; + +namespace OshimaBot.Data; + +/// +/// P0~P2 所需表。P3(clubs / rooms / betting_* 等)按计划不进入首批 Migration。 +/// 不规则字段用 TEXT 存 JSON,由应用层序列化,可查询字段一律列式。 +/// 外键关系在 S6 仓储层落地时补齐,当前先建表、主键与索引。 +/// +public sealed class BotDbContext(DbContextOptions options) : DbContext(options) +{ + public DbSet Users => Set(); + public DbSet UserIdentities => Set(); + public DbSet UserRoles => Set(); + public DbSet ApiKeys => Set(); + public DbSet BindCodes => Set(); + public DbSet AuditLogs => Set(); + + public DbSet PlayerStates => Set(); + public DbSet Characters => Set(); + public DbSet CharacterSkills => Set(); + public DbSet CharacterEquipment => Set(); + public DbSet ItemInstances => Set(); + public DbSet Squads => Set(); + public DbSet SquadMembers => Set(); + public DbSet TrainingSessions => Set(); + public DbSet DailyQuests => Set(); + public DbSet SignInRecords => Set(); + public DbSet ActivityProgress => Set(); + public DbSet ExplorationRuns => Set(); + public DbSet ForgingJobs => Set(); + public DbSet MailMessages => Set(); + public DbSet RenameRequests => Set(); + public DbSet UserSessions => Set(); + + public DbSet LedgerEntries => Set(); + public DbSet Stores => Set(); + public DbSet StoreGoods => Set(); + public DbSet MarketListings => Set(); + public DbSet Trades => Set(); + public DbSet TradeItems => Set(); + + public DbSet ProcessedEvents => Set(); + public DbSet GatewaySessions => Set(); + public DbSet SimulationRuns => Set(); + public DbSet SimulationStatistics => Set(); + public DbSet AppConfigs => Set(); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + // ---- 身份与权限 ---- + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => x.Handle).IsUnique(); + entity.Property(x => x.Version).IsConcurrencyToken(); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.Provider, x.Subject }).IsUnique(); + entity.HasIndex(x => x.UserId); + entity.HasIndex(x => x.UnionSubject); + }); + modelBuilder.Entity().HasKey(x => new { x.UserId, x.Role }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => x.KeyHash).IsUnique(); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Code); + entity.HasIndex(x => x.UserId); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.ActorUserId, x.CreatedAtUtc }); + }); + + // ---- 玩家存档 ---- + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.UserId); + entity.Property(x => x.Version).IsConcurrencyToken(); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.UserId, x.IsMain }); + }); + modelBuilder.Entity().HasKey(x => new { x.CharacterId, x.SkillId, x.Slot }); + modelBuilder.Entity().HasKey(x => new { x.CharacterId, x.Slot }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.UserId, x.CatalogId }); + entity.Property(x => x.Version).IsConcurrencyToken(); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => x.UserId); + }); + modelBuilder.Entity().HasKey(x => new { x.SquadId, x.Slot }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.UserId, x.SettledAtUtc }); + }); + modelBuilder.Entity().HasKey(x => new { x.UserId, x.QuestKey, x.QuestDate }); + modelBuilder.Entity().HasKey(x => new { x.UserId, x.SignInDate }); + modelBuilder.Entity().HasKey(x => new { x.UserId, x.ActivityKey }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.UserId, x.SettledAtUtc }); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.UserId, x.SettledAtUtc }); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.ReceiverUserId, x.ReadAtUtc }); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.Status, x.CreatedAtUtc }); + }); + modelBuilder.Entity().HasKey(x => x.UserId); + + // ---- 经济与交易 ---- + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.UserId, x.CreatedAtUtc }); + entity.HasIndex(x => new { x.RefType, x.RefId }); + }); + modelBuilder.Entity().HasKey(x => x.Key); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => x.StoreKey); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.Status, x.CreatedAtUtc }); + entity.HasIndex(x => x.SellerUserId); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => x.SellerUserId); + }); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => x.TradeId); + }); + + // ---- 系统 / 运行 ---- + modelBuilder.Entity(entity => + { + entity.HasKey(x => new { x.EventId, x.MsgSeq }); + entity.HasIndex(x => x.ReceivedAtUtc); + }); + modelBuilder.Entity().HasKey(x => x.BotAppId); + modelBuilder.Entity(entity => + { + entity.HasKey(x => x.Id); + entity.HasIndex(x => new { x.UserId, x.StartedAtUtc }); + }); + modelBuilder.Entity().HasKey(x => new { x.Scope, x.CatalogId }); + modelBuilder.Entity().HasKey(x => x.Key); + } +} diff --git a/OshimaBot/Data/DatabaseInitializer.cs b/OshimaBot/Data/DatabaseInitializer.cs new file mode 100644 index 0000000..dde2da5 --- /dev/null +++ b/OshimaBot/Data/DatabaseInitializer.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; +using OshimaBot.Models; + +namespace OshimaBot.Data; + +/// +/// 放在 IHostedService 中而非 Program 启动代码里:EF CLI 设计时只构建 Host、不启动 HostedService, +/// 从而避免生成 Migration 时反过来尝试执行 Migration。 +/// +public sealed class DatabaseInitializer( + IServiceScopeFactory scopeFactory, + IOptions options, + ILogger logger) : BackgroundService +{ + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + if (!options.Value.ApplyMigrationsOnStartup) + { + logger.LogInformation("已跳过数据库自动迁移(Database:ApplyMigrationsOnStartup=false)。"); + return; + } + + using IServiceScope scope = scopeFactory.CreateScope(); + BotDbContext db = scope.ServiceProvider.GetRequiredService(); + await db.Database.MigrateAsync(stoppingToken); + await db.Database.ExecuteSqlRawAsync("PRAGMA journal_mode=WAL;", stoppingToken); + await db.Database.ExecuteSqlRawAsync("PRAGMA foreign_keys=ON;", stoppingToken); + logger.LogInformation("数据库迁移完成,已启用 WAL 与外键约束。"); + } +} diff --git a/OshimaBot/Data/Economy.cs b/OshimaBot/Data/Economy.cs new file mode 100644 index 0000000..2aa942f --- /dev/null +++ b/OshimaBot/Data/Economy.cs @@ -0,0 +1,68 @@ +namespace OshimaBot.Data.Entities; + +/// 所有货币变动必须与「加物品/扣物品」在同一事务写入,用于对账与防丢。 +public sealed class LedgerEntry +{ + public long Id { get; set; } + public long UserId { get; set; } + public string Currency { get; set; } = "credits"; + public long Delta { get; set; } + public long BalanceAfter { get; set; } + public string Reason { get; set; } = ""; + public string RefType { get; set; } = ""; + public string RefId { get; set; } = ""; + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; +} + +public sealed class Store +{ + public string Key { get; set; } = ""; + public string Name { get; set; } = ""; + public string Kind { get; set; } = "system"; + public DateTime? RefreshAtUtc { get; set; } + public string ConfigJson { get; set; } = "{}"; +} + +public sealed class StoreGood +{ + public long Id { get; set; } + public string StoreKey { get; set; } = ""; + public string ItemCatalogId { get; set; } = ""; + public string PriceCurrency { get; set; } = "credits"; + public long Price { get; set; } + public int Stock { get; set; } = -1; + public int Quota { get; set; } = -1; + public DateTime? RefreshAtUtc { get; set; } +} + +public sealed class MarketListing +{ + public long Id { get; set; } + public long SellerUserId { get; set; } + public long ItemInstanceId { get; set; } + public long Price { get; set; } + public long Fee { get; set; } + public int Status { get; set; } + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; + public DateTime? ClosedAtUtc { get; set; } +} + +public sealed class Trade +{ + public long Id { get; set; } + public long? BuyerUserId { get; set; } + public long SellerUserId { get; set; } + public int Status { get; set; } + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; + public DateTime? ClosedAtUtc { get; set; } +} + +public sealed class TradeItem +{ + public long Id { get; set; } + public long TradeId { get; set; } + public long FromUserId { get; set; } + public long ItemInstanceId { get; set; } + public int Quantity { get; set; } = 1; + public long Price { get; set; } +} diff --git a/OshimaBot/Data/Identity.cs b/OshimaBot/Data/Identity.cs new file mode 100644 index 0000000..cd3827e --- /dev/null +++ b/OshimaBot/Data/Identity.cs @@ -0,0 +1,64 @@ +namespace OshimaBot.Data.Entities; + +/// 内部用户主键。业务代码只使用 Id,外部 OpenID 单独存 UserIdentity。 +public sealed class User +{ + public long Id { get; set; } + public string Handle { get; set; } = ""; + public string Nickname { get; set; } = ""; + public int Status { get; set; } + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; + public DateTime LastSeenAtUtc { get; set; } = DateTime.UtcNow; + public int Version { get; set; } +} + +/// 外部身份(QQ user_openid / member_openid 等),支持多身份、换绑与 union_openid 合并。 +public sealed class UserIdentity +{ + public long Id { get; set; } + public long UserId { get; set; } + public string Provider { get; set; } = "qq"; + public string Subject { get; set; } = ""; + public string? UnionSubject { get; set; } + public string Scene { get; set; } = "c2c"; + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; +} + +public sealed class UserRole +{ + public long UserId { get; set; } + public int Role { get; set; } +} + +public sealed class ApiKey +{ + public long Id { get; set; } + public long? UserId { get; set; } + public string Name { get; set; } = ""; + public string KeyHash { get; set; } = ""; + public string ScopesJson { get; set; } = "[]"; + public DateTime? ExpiresAtUtc { get; set; } + public DateTime? RevokedAtUtc { get; set; } + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; +} + +/// 一次性绑定码,用于第三方/管理端绑定 QQ OpenID,替代旧版直接回显接入码。 +public sealed class BindCode +{ + public string Code { get; set; } = ""; + public long UserId { get; set; } + public string Purpose { get; set; } = ""; + public DateTime ExpiresAtUtc { get; set; } + public DateTime? UsedAtUtc { get; set; } + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; +} + +public sealed class AuditLog +{ + public long Id { get; set; } + public long? ActorUserId { get; set; } + public string Action { get; set; } = ""; + public string Target { get; set; } = ""; + public string PayloadJson { get; set; } = "{}"; + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; +} diff --git a/OshimaBot/Data/Migrations/20261109125643_Initial.Designer.cs b/OshimaBot/Data/Migrations/20261109125643_Initial.Designer.cs new file mode 100644 index 0000000..8e9cb16 --- /dev/null +++ b/OshimaBot/Data/Migrations/20261109125643_Initial.Designer.cs @@ -0,0 +1,1009 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OshimaBot.Data; + +#nullable disable + +namespace OshimaBot.Data.Migrations +{ + [DbContext(typeof(BotDbContext))] + [Migration("20261109125643_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.11"); + + modelBuilder.Entity("OshimaBot.Data.Entities.ActivityProgress", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("ActivityKey") + .HasColumnType("TEXT"); + + b.Property("ClaimedJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ProgressJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("UserId", "ActivityKey"); + + b.ToTable("ActivityProgress"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.ApiKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ExpiresAtUtc") + .HasColumnType("TEXT"); + + b.Property("KeyHash") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RevokedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ScopesJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("KeyHash") + .IsUnique(); + + b.ToTable("ApiKeys"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.AppConfig", b => + { + b.Property("Key") + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ValueJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("AppConfigs"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.AuditLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Action") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ActorUserId") + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("PayloadJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Target") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ActorUserId", "CreatedAtUtc"); + + b.ToTable("AuditLogs"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.BindCode", b => + { + b.Property("Code") + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ExpiresAtUtc") + .HasColumnType("TEXT"); + + b.Property("Purpose") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UsedAtUtc") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Code"); + + b.HasIndex("UserId"); + + b.ToTable("BindCodes"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AttrsJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("BreakLevel") + .HasColumnType("INTEGER"); + + b.Property("CatalogId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("CatalogVersion") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Exp") + .HasColumnType("INTEGER"); + + b.Property("IsMain") + .HasColumnType("INTEGER"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "IsMain"); + + b.ToTable("Characters"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.CharacterEquipment", b => + { + b.Property("CharacterId") + .HasColumnType("INTEGER"); + + b.Property("Slot") + .HasColumnType("TEXT"); + + b.Property("ItemInstanceId") + .HasColumnType("INTEGER"); + + b.HasKey("CharacterId", "Slot"); + + b.ToTable("CharacterEquipment"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.CharacterSkill", b => + { + b.Property("CharacterId") + .HasColumnType("INTEGER"); + + b.Property("SkillId") + .HasColumnType("TEXT"); + + b.Property("Slot") + .HasColumnType("INTEGER"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.HasKey("CharacterId", "SkillId", "Slot"); + + b.ToTable("CharacterSkills"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.DailyQuest", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("QuestKey") + .HasColumnType("TEXT"); + + b.Property("QuestDate") + .HasColumnType("TEXT"); + + b.Property("ClaimedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ProgressJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.HasKey("UserId", "QuestKey", "QuestDate"); + + b.ToTable("DailyQuests"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.ExplorationRun", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("EndsAtUtc") + .HasColumnType("TEXT"); + + b.Property("RegionKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SettledAtUtc") + .HasColumnType("TEXT"); + + b.Property("StartedAtUtc") + .HasColumnType("TEXT"); + + b.Property("StateJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "SettledAtUtc"); + + b.ToTable("ExplorationRuns"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.ForgingJob", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("EndsAtUtc") + .HasColumnType("TEXT"); + + b.Property("RecipeKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SettledAtUtc") + .HasColumnType("TEXT"); + + b.Property("StartedAtUtc") + .HasColumnType("TEXT"); + + b.Property("StateJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "SettledAtUtc"); + + b.ToTable("ForgingJobs"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.GatewaySession", b => + { + b.Property("BotAppId") + .HasColumnType("TEXT"); + + b.Property("LastSeq") + .HasColumnType("INTEGER"); + + b.Property("SessionId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("BotAppId"); + + b.ToTable("GatewaySessions"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.ItemInstance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AcquiredAtUtc") + .HasColumnType("TEXT"); + + b.Property("Bound") + .HasColumnType("INTEGER"); + + b.Property("CatalogId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Locked") + .HasColumnType("INTEGER"); + + b.Property("PayloadJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Quality") + .HasColumnType("INTEGER"); + + b.Property("Quantity") + .HasColumnType("INTEGER"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("Version") + .IsConcurrencyToken() + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "CatalogId"); + + b.ToTable("ItemInstances"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.LedgerEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BalanceAfter") + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Currency") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Delta") + .HasColumnType("INTEGER"); + + b.Property("Reason") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RefId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RefType") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("RefType", "RefId"); + + b.HasIndex("UserId", "CreatedAtUtc"); + + b.ToTable("LedgerEntries"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.MailMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Content") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ReadAtUtc") + .HasColumnType("TEXT"); + + b.Property("ReceiverUserId") + .HasColumnType("INTEGER"); + + b.Property("SenderUserId") + .HasColumnType("INTEGER"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ReceiverUserId", "ReadAtUtc"); + + b.ToTable("MailMessages"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.MarketListing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ClosedAtUtc") + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Fee") + .HasColumnType("INTEGER"); + + b.Property("ItemInstanceId") + .HasColumnType("INTEGER"); + + b.Property("Price") + .HasColumnType("INTEGER"); + + b.Property("SellerUserId") + .HasColumnType("INTEGER"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("SellerUserId"); + + b.HasIndex("Status", "CreatedAtUtc"); + + b.ToTable("MarketListings"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.PlayerState", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CooperativePoints") + .HasColumnType("INTEGER"); + + b.Property("Credits") + .HasColumnType("INTEGER"); + + b.Property("Diamonds") + .HasColumnType("INTEGER"); + + b.Property("DinnerClaimedOn") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Exp") + .HasColumnType("INTEGER"); + + b.Property("ExploreTimes") + .HasColumnType("INTEGER"); + + b.Property("ForgePoints") + .HasColumnType("INTEGER"); + + b.Property("HorseRacingPoints") + .HasColumnType("INTEGER"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.Property("LogonOn") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LunchClaimedOn") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SignInStreak") + .HasColumnType("INTEGER"); + + b.Property("SignedOn") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Version") + .IsConcurrencyToken() + .HasColumnType("INTEGER"); + + b.HasKey("UserId"); + + b.ToTable("PlayerStates"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.ProcessedEvent", b => + { + b.Property("EventId") + .HasColumnType("TEXT"); + + b.Property("MsgSeq") + .HasColumnType("INTEGER"); + + b.Property("ProcessedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ReceivedAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("EventId", "MsgSeq"); + + b.HasIndex("ReceivedAtUtc"); + + b.ToTable("ProcessedEvents"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.RenameRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("RequestedName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ReviewedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("TargetId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TargetType") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Status", "CreatedAtUtc"); + + b.ToTable("RenameRequests"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.SignInRecord", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("SignInDate") + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("RewardJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("UserId", "SignInDate"); + + b.ToTable("SignInRecords"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.SimulationRun", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FinishedAtUtc") + .HasColumnType("TEXT"); + + b.Property("OptionsJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ResultJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RoundsJson") + .HasColumnType("TEXT"); + + b.Property("Seed") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("StartedAtUtc") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "StartedAtUtc"); + + b.ToTable("SimulationRuns"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.SimulationStatistic", b => + { + b.Property("Scope") + .HasColumnType("TEXT"); + + b.Property("CatalogId") + .HasColumnType("TEXT"); + + b.Property("StatsJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("Scope", "CatalogId"); + + b.ToTable("SimulationStatistics"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.Squad", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Squads"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.SquadMember", b => + { + b.Property("SquadId") + .HasColumnType("INTEGER"); + + b.Property("Slot") + .HasColumnType("INTEGER"); + + b.Property("CharacterId") + .HasColumnType("INTEGER"); + + b.HasKey("SquadId", "Slot"); + + b.ToTable("SquadMembers"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.Store", b => + { + b.Property("Key") + .HasColumnType("TEXT"); + + b.Property("ConfigJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Kind") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RefreshAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("Stores"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.StoreGood", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ItemCatalogId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("INTEGER"); + + b.Property("PriceCurrency") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Quota") + .HasColumnType("INTEGER"); + + b.Property("RefreshAtUtc") + .HasColumnType("TEXT"); + + b.Property("Stock") + .HasColumnType("INTEGER"); + + b.Property("StoreKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("StoreKey"); + + b.ToTable("StoreGoods"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.Trade", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BuyerUserId") + .HasColumnType("INTEGER"); + + b.Property("ClosedAtUtc") + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("SellerUserId") + .HasColumnType("INTEGER"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("SellerUserId"); + + b.ToTable("Trades"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.TradeItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FromUserId") + .HasColumnType("INTEGER"); + + b.Property("ItemInstanceId") + .HasColumnType("INTEGER"); + + b.Property("Price") + .HasColumnType("INTEGER"); + + b.Property("Quantity") + .HasColumnType("INTEGER"); + + b.Property("TradeId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("TradeId"); + + b.ToTable("TradeItems"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.TrainingSession", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CharacterId") + .HasColumnType("INTEGER"); + + b.Property("EndsAtUtc") + .HasColumnType("TEXT"); + + b.Property("SettledAtUtc") + .HasColumnType("TEXT"); + + b.Property("StartedAtUtc") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "SettledAtUtc"); + + b.ToTable("TrainingSessions"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Handle") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastSeenAtUtc") + .HasColumnType("TEXT"); + + b.Property("Nickname") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("Version") + .IsConcurrencyToken() + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Handle") + .IsUnique(); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.UserIdentity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Provider") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Scene") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UnionSubject") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UnionSubject"); + + b.HasIndex("UserId"); + + b.HasIndex("Provider", "Subject") + .IsUnique(); + + b.ToTable("UserIdentities"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.UserRole", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("Role") + .HasColumnType("INTEGER"); + + b.HasKey("UserId", "Role"); + + b.ToTable("UserRoles"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.UserSession", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CurrentRegion") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PageCursor") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PendingActionJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PendingExpiresAtUtc") + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("UserId"); + + b.ToTable("UserSessions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OshimaBot/Data/Migrations/20261109125643_Initial.cs b/OshimaBot/Data/Migrations/20261109125643_Initial.cs new file mode 100644 index 0000000..31696fd --- /dev/null +++ b/OshimaBot/Data/Migrations/20261109125643_Initial.cs @@ -0,0 +1,799 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace OshimaBot.Data.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ActivityProgress", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + ActivityKey = table.Column(type: "TEXT", nullable: false), + ProgressJson = table.Column(type: "TEXT", nullable: false), + ClaimedJson = table.Column(type: "TEXT", nullable: false), + UpdatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ActivityProgress", x => new { x.UserId, x.ActivityKey }); + }); + + migrationBuilder.CreateTable( + name: "ApiKeys", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: true), + Name = table.Column(type: "TEXT", nullable: false), + KeyHash = table.Column(type: "TEXT", nullable: false), + ScopesJson = table.Column(type: "TEXT", nullable: false), + ExpiresAtUtc = table.Column(type: "TEXT", nullable: true), + RevokedAtUtc = table.Column(type: "TEXT", nullable: true), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ApiKeys", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AppConfigs", + columns: table => new + { + Key = table.Column(type: "TEXT", nullable: false), + ValueJson = table.Column(type: "TEXT", nullable: false), + UpdatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AppConfigs", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "AuditLogs", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ActorUserId = table.Column(type: "INTEGER", nullable: true), + Action = table.Column(type: "TEXT", nullable: false), + Target = table.Column(type: "TEXT", nullable: false), + PayloadJson = table.Column(type: "TEXT", nullable: false), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AuditLogs", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "BindCodes", + columns: table => new + { + Code = table.Column(type: "TEXT", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false), + Purpose = table.Column(type: "TEXT", nullable: false), + ExpiresAtUtc = table.Column(type: "TEXT", nullable: false), + UsedAtUtc = table.Column(type: "TEXT", nullable: true), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BindCodes", x => x.Code); + }); + + migrationBuilder.CreateTable( + name: "CharacterEquipment", + columns: table => new + { + CharacterId = table.Column(type: "INTEGER", nullable: false), + Slot = table.Column(type: "TEXT", nullable: false), + ItemInstanceId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CharacterEquipment", x => new { x.CharacterId, x.Slot }); + }); + + migrationBuilder.CreateTable( + name: "Characters", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: false), + CatalogId = table.Column(type: "TEXT", nullable: false), + CatalogVersion = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + Level = table.Column(type: "INTEGER", nullable: false), + Exp = table.Column(type: "INTEGER", nullable: false), + BreakLevel = table.Column(type: "INTEGER", nullable: false), + AttrsJson = table.Column(type: "TEXT", nullable: false), + IsMain = table.Column(type: "INTEGER", nullable: false), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Characters", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CharacterSkills", + columns: table => new + { + CharacterId = table.Column(type: "INTEGER", nullable: false), + SkillId = table.Column(type: "TEXT", nullable: false), + Slot = table.Column(type: "INTEGER", nullable: false), + Level = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CharacterSkills", x => new { x.CharacterId, x.SkillId, x.Slot }); + }); + + migrationBuilder.CreateTable( + name: "DailyQuests", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + QuestKey = table.Column(type: "TEXT", nullable: false), + QuestDate = table.Column(type: "TEXT", nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + ProgressJson = table.Column(type: "TEXT", nullable: false), + ClaimedAtUtc = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_DailyQuests", x => new { x.UserId, x.QuestKey, x.QuestDate }); + }); + + migrationBuilder.CreateTable( + name: "ExplorationRuns", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: false), + RegionKey = table.Column(type: "TEXT", nullable: false), + StateJson = table.Column(type: "TEXT", nullable: false), + StartedAtUtc = table.Column(type: "TEXT", nullable: false), + EndsAtUtc = table.Column(type: "TEXT", nullable: false), + SettledAtUtc = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ExplorationRuns", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ForgingJobs", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: false), + RecipeKey = table.Column(type: "TEXT", nullable: false), + StateJson = table.Column(type: "TEXT", nullable: false), + StartedAtUtc = table.Column(type: "TEXT", nullable: false), + EndsAtUtc = table.Column(type: "TEXT", nullable: false), + SettledAtUtc = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ForgingJobs", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "GatewaySessions", + columns: table => new + { + BotAppId = table.Column(type: "TEXT", nullable: false), + SessionId = table.Column(type: "TEXT", nullable: false), + LastSeq = table.Column(type: "INTEGER", nullable: false), + UpdatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_GatewaySessions", x => x.BotAppId); + }); + + migrationBuilder.CreateTable( + name: "ItemInstances", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: false), + CatalogId = table.Column(type: "TEXT", nullable: false), + Quantity = table.Column(type: "INTEGER", nullable: false), + Quality = table.Column(type: "INTEGER", nullable: false), + Locked = table.Column(type: "INTEGER", nullable: false), + Bound = table.Column(type: "INTEGER", nullable: false), + PayloadJson = table.Column(type: "TEXT", nullable: false), + AcquiredAtUtc = table.Column(type: "TEXT", nullable: false), + Version = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ItemInstances", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "LedgerEntries", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: false), + Currency = table.Column(type: "TEXT", nullable: false), + Delta = table.Column(type: "INTEGER", nullable: false), + BalanceAfter = table.Column(type: "INTEGER", nullable: false), + Reason = table.Column(type: "TEXT", nullable: false), + RefType = table.Column(type: "TEXT", nullable: false), + RefId = table.Column(type: "TEXT", nullable: false), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LedgerEntries", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "MailMessages", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + SenderUserId = table.Column(type: "INTEGER", nullable: true), + ReceiverUserId = table.Column(type: "INTEGER", nullable: false), + Subject = table.Column(type: "TEXT", nullable: false), + Content = table.Column(type: "TEXT", nullable: false), + ReadAtUtc = table.Column(type: "TEXT", nullable: true), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MailMessages", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "MarketListings", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + SellerUserId = table.Column(type: "INTEGER", nullable: false), + ItemInstanceId = table.Column(type: "INTEGER", nullable: false), + Price = table.Column(type: "INTEGER", nullable: false), + Fee = table.Column(type: "INTEGER", nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false), + ClosedAtUtc = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_MarketListings", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "PlayerStates", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Credits = table.Column(type: "INTEGER", nullable: false), + Diamonds = table.Column(type: "INTEGER", nullable: false), + Exp = table.Column(type: "INTEGER", nullable: false), + Level = table.Column(type: "INTEGER", nullable: false), + SignInStreak = table.Column(type: "INTEGER", nullable: false), + SignedOn = table.Column(type: "TEXT", nullable: false), + LogonOn = table.Column(type: "TEXT", nullable: false), + LunchClaimedOn = table.Column(type: "TEXT", nullable: false), + DinnerClaimedOn = table.Column(type: "TEXT", nullable: false), + ExploreTimes = table.Column(type: "INTEGER", nullable: false), + HorseRacingPoints = table.Column(type: "INTEGER", nullable: false), + CooperativePoints = table.Column(type: "INTEGER", nullable: false), + ForgePoints = table.Column(type: "INTEGER", nullable: false), + UpdatedAtUtc = table.Column(type: "TEXT", nullable: false), + Version = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PlayerStates", x => x.UserId); + }); + + migrationBuilder.CreateTable( + name: "ProcessedEvents", + columns: table => new + { + EventId = table.Column(type: "TEXT", nullable: false), + MsgSeq = table.Column(type: "INTEGER", nullable: false), + ReceivedAtUtc = table.Column(type: "TEXT", nullable: false), + ProcessedAtUtc = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ProcessedEvents", x => new { x.EventId, x.MsgSeq }); + }); + + migrationBuilder.CreateTable( + name: "RenameRequests", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: false), + TargetType = table.Column(type: "TEXT", nullable: false), + TargetId = table.Column(type: "TEXT", nullable: false), + RequestedName = table.Column(type: "TEXT", nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false), + ReviewedAtUtc = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_RenameRequests", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SignInRecords", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + SignInDate = table.Column(type: "TEXT", nullable: false), + RewardJson = table.Column(type: "TEXT", nullable: false), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SignInRecords", x => new { x.UserId, x.SignInDate }); + }); + + migrationBuilder.CreateTable( + name: "SimulationRuns", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: true), + Seed = table.Column(type: "TEXT", nullable: false), + OptionsJson = table.Column(type: "TEXT", nullable: false), + ResultJson = table.Column(type: "TEXT", nullable: false), + RoundsJson = table.Column(type: "TEXT", nullable: true), + StartedAtUtc = table.Column(type: "TEXT", nullable: false), + FinishedAtUtc = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_SimulationRuns", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SimulationStatistics", + columns: table => new + { + Scope = table.Column(type: "TEXT", nullable: false), + CatalogId = table.Column(type: "TEXT", nullable: false), + StatsJson = table.Column(type: "TEXT", nullable: false), + UpdatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SimulationStatistics", x => new { x.Scope, x.CatalogId }); + }); + + migrationBuilder.CreateTable( + name: "SquadMembers", + columns: table => new + { + SquadId = table.Column(type: "INTEGER", nullable: false), + Slot = table.Column(type: "INTEGER", nullable: false), + CharacterId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SquadMembers", x => new { x.SquadId, x.Slot }); + }); + + migrationBuilder.CreateTable( + name: "Squads", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + IsActive = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Squads", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "StoreGoods", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + StoreKey = table.Column(type: "TEXT", nullable: false), + ItemCatalogId = table.Column(type: "TEXT", nullable: false), + PriceCurrency = table.Column(type: "TEXT", nullable: false), + Price = table.Column(type: "INTEGER", nullable: false), + Stock = table.Column(type: "INTEGER", nullable: false), + Quota = table.Column(type: "INTEGER", nullable: false), + RefreshAtUtc = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_StoreGoods", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Stores", + columns: table => new + { + Key = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + Kind = table.Column(type: "TEXT", nullable: false), + RefreshAtUtc = table.Column(type: "TEXT", nullable: true), + ConfigJson = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Stores", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "TradeItems", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + TradeId = table.Column(type: "INTEGER", nullable: false), + FromUserId = table.Column(type: "INTEGER", nullable: false), + ItemInstanceId = table.Column(type: "INTEGER", nullable: false), + Quantity = table.Column(type: "INTEGER", nullable: false), + Price = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TradeItems", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Trades", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + BuyerUserId = table.Column(type: "INTEGER", nullable: true), + SellerUserId = table.Column(type: "INTEGER", nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false), + ClosedAtUtc = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Trades", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "TrainingSessions", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: false), + CharacterId = table.Column(type: "INTEGER", nullable: false), + StartedAtUtc = table.Column(type: "TEXT", nullable: false), + EndsAtUtc = table.Column(type: "TEXT", nullable: false), + SettledAtUtc = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_TrainingSessions", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "UserIdentities", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: false), + Provider = table.Column(type: "TEXT", nullable: false), + Subject = table.Column(type: "TEXT", nullable: false), + UnionSubject = table.Column(type: "TEXT", nullable: true), + Scene = table.Column(type: "TEXT", nullable: false), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserIdentities", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "UserRoles", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + Role = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.Role }); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Handle = table.Column(type: "TEXT", nullable: false), + Nickname = table.Column(type: "TEXT", nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + CreatedAtUtc = table.Column(type: "TEXT", nullable: false), + LastSeenAtUtc = table.Column(type: "TEXT", nullable: false), + Version = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "UserSessions", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + CurrentRegion = table.Column(type: "TEXT", nullable: false), + PendingActionJson = table.Column(type: "TEXT", nullable: false), + PendingExpiresAtUtc = table.Column(type: "TEXT", nullable: true), + PageCursor = table.Column(type: "TEXT", nullable: false), + UpdatedAtUtc = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserSessions", x => x.UserId); + }); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_KeyHash", + table: "ApiKeys", + column: "KeyHash", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AuditLogs_ActorUserId_CreatedAtUtc", + table: "AuditLogs", + columns: new[] { "ActorUserId", "CreatedAtUtc" }); + + migrationBuilder.CreateIndex( + name: "IX_BindCodes_UserId", + table: "BindCodes", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Characters_UserId_IsMain", + table: "Characters", + columns: new[] { "UserId", "IsMain" }); + + migrationBuilder.CreateIndex( + name: "IX_ExplorationRuns_UserId_SettledAtUtc", + table: "ExplorationRuns", + columns: new[] { "UserId", "SettledAtUtc" }); + + migrationBuilder.CreateIndex( + name: "IX_ForgingJobs_UserId_SettledAtUtc", + table: "ForgingJobs", + columns: new[] { "UserId", "SettledAtUtc" }); + + migrationBuilder.CreateIndex( + name: "IX_ItemInstances_UserId_CatalogId", + table: "ItemInstances", + columns: new[] { "UserId", "CatalogId" }); + + migrationBuilder.CreateIndex( + name: "IX_LedgerEntries_RefType_RefId", + table: "LedgerEntries", + columns: new[] { "RefType", "RefId" }); + + migrationBuilder.CreateIndex( + name: "IX_LedgerEntries_UserId_CreatedAtUtc", + table: "LedgerEntries", + columns: new[] { "UserId", "CreatedAtUtc" }); + + migrationBuilder.CreateIndex( + name: "IX_MailMessages_ReceiverUserId_ReadAtUtc", + table: "MailMessages", + columns: new[] { "ReceiverUserId", "ReadAtUtc" }); + + migrationBuilder.CreateIndex( + name: "IX_MarketListings_SellerUserId", + table: "MarketListings", + column: "SellerUserId"); + + migrationBuilder.CreateIndex( + name: "IX_MarketListings_Status_CreatedAtUtc", + table: "MarketListings", + columns: new[] { "Status", "CreatedAtUtc" }); + + migrationBuilder.CreateIndex( + name: "IX_ProcessedEvents_ReceivedAtUtc", + table: "ProcessedEvents", + column: "ReceivedAtUtc"); + + migrationBuilder.CreateIndex( + name: "IX_RenameRequests_Status_CreatedAtUtc", + table: "RenameRequests", + columns: new[] { "Status", "CreatedAtUtc" }); + + migrationBuilder.CreateIndex( + name: "IX_SimulationRuns_UserId_StartedAtUtc", + table: "SimulationRuns", + columns: new[] { "UserId", "StartedAtUtc" }); + + migrationBuilder.CreateIndex( + name: "IX_Squads_UserId", + table: "Squads", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_StoreGoods_StoreKey", + table: "StoreGoods", + column: "StoreKey"); + + migrationBuilder.CreateIndex( + name: "IX_TradeItems_TradeId", + table: "TradeItems", + column: "TradeId"); + + migrationBuilder.CreateIndex( + name: "IX_Trades_SellerUserId", + table: "Trades", + column: "SellerUserId"); + + migrationBuilder.CreateIndex( + name: "IX_TrainingSessions_UserId_SettledAtUtc", + table: "TrainingSessions", + columns: new[] { "UserId", "SettledAtUtc" }); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentities_Provider_Subject", + table: "UserIdentities", + columns: new[] { "Provider", "Subject" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentities_UnionSubject", + table: "UserIdentities", + column: "UnionSubject"); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentities_UserId", + table: "UserIdentities", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Handle", + table: "Users", + column: "Handle", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ActivityProgress"); + + migrationBuilder.DropTable( + name: "ApiKeys"); + + migrationBuilder.DropTable( + name: "AppConfigs"); + + migrationBuilder.DropTable( + name: "AuditLogs"); + + migrationBuilder.DropTable( + name: "BindCodes"); + + migrationBuilder.DropTable( + name: "CharacterEquipment"); + + migrationBuilder.DropTable( + name: "Characters"); + + migrationBuilder.DropTable( + name: "CharacterSkills"); + + migrationBuilder.DropTable( + name: "DailyQuests"); + + migrationBuilder.DropTable( + name: "ExplorationRuns"); + + migrationBuilder.DropTable( + name: "ForgingJobs"); + + migrationBuilder.DropTable( + name: "GatewaySessions"); + + migrationBuilder.DropTable( + name: "ItemInstances"); + + migrationBuilder.DropTable( + name: "LedgerEntries"); + + migrationBuilder.DropTable( + name: "MailMessages"); + + migrationBuilder.DropTable( + name: "MarketListings"); + + migrationBuilder.DropTable( + name: "PlayerStates"); + + migrationBuilder.DropTable( + name: "ProcessedEvents"); + + migrationBuilder.DropTable( + name: "RenameRequests"); + + migrationBuilder.DropTable( + name: "SignInRecords"); + + migrationBuilder.DropTable( + name: "SimulationRuns"); + + migrationBuilder.DropTable( + name: "SimulationStatistics"); + + migrationBuilder.DropTable( + name: "SquadMembers"); + + migrationBuilder.DropTable( + name: "Squads"); + + migrationBuilder.DropTable( + name: "StoreGoods"); + + migrationBuilder.DropTable( + name: "Stores"); + + migrationBuilder.DropTable( + name: "TradeItems"); + + migrationBuilder.DropTable( + name: "Trades"); + + migrationBuilder.DropTable( + name: "TrainingSessions"); + + migrationBuilder.DropTable( + name: "UserIdentities"); + + migrationBuilder.DropTable( + name: "UserRoles"); + + migrationBuilder.DropTable( + name: "Users"); + + migrationBuilder.DropTable( + name: "UserSessions"); + } + } +} diff --git a/OshimaBot/Data/Migrations/BotDbContextModelSnapshot.cs b/OshimaBot/Data/Migrations/BotDbContextModelSnapshot.cs new file mode 100644 index 0000000..8652a7b --- /dev/null +++ b/OshimaBot/Data/Migrations/BotDbContextModelSnapshot.cs @@ -0,0 +1,1006 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OshimaBot.Data; + +#nullable disable + +namespace OshimaBot.Data.Migrations +{ + [DbContext(typeof(BotDbContext))] + partial class BotDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.11"); + + modelBuilder.Entity("OshimaBot.Data.Entities.ActivityProgress", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("ActivityKey") + .HasColumnType("TEXT"); + + b.Property("ClaimedJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ProgressJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("UserId", "ActivityKey"); + + b.ToTable("ActivityProgress"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.ApiKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ExpiresAtUtc") + .HasColumnType("TEXT"); + + b.Property("KeyHash") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RevokedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ScopesJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("KeyHash") + .IsUnique(); + + b.ToTable("ApiKeys"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.AppConfig", b => + { + b.Property("Key") + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ValueJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("AppConfigs"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.AuditLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Action") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ActorUserId") + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("PayloadJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Target") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ActorUserId", "CreatedAtUtc"); + + b.ToTable("AuditLogs"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.BindCode", b => + { + b.Property("Code") + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ExpiresAtUtc") + .HasColumnType("TEXT"); + + b.Property("Purpose") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UsedAtUtc") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Code"); + + b.HasIndex("UserId"); + + b.ToTable("BindCodes"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AttrsJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("BreakLevel") + .HasColumnType("INTEGER"); + + b.Property("CatalogId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("CatalogVersion") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Exp") + .HasColumnType("INTEGER"); + + b.Property("IsMain") + .HasColumnType("INTEGER"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "IsMain"); + + b.ToTable("Characters"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.CharacterEquipment", b => + { + b.Property("CharacterId") + .HasColumnType("INTEGER"); + + b.Property("Slot") + .HasColumnType("TEXT"); + + b.Property("ItemInstanceId") + .HasColumnType("INTEGER"); + + b.HasKey("CharacterId", "Slot"); + + b.ToTable("CharacterEquipment"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.CharacterSkill", b => + { + b.Property("CharacterId") + .HasColumnType("INTEGER"); + + b.Property("SkillId") + .HasColumnType("TEXT"); + + b.Property("Slot") + .HasColumnType("INTEGER"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.HasKey("CharacterId", "SkillId", "Slot"); + + b.ToTable("CharacterSkills"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.DailyQuest", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("QuestKey") + .HasColumnType("TEXT"); + + b.Property("QuestDate") + .HasColumnType("TEXT"); + + b.Property("ClaimedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ProgressJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.HasKey("UserId", "QuestKey", "QuestDate"); + + b.ToTable("DailyQuests"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.ExplorationRun", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("EndsAtUtc") + .HasColumnType("TEXT"); + + b.Property("RegionKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SettledAtUtc") + .HasColumnType("TEXT"); + + b.Property("StartedAtUtc") + .HasColumnType("TEXT"); + + b.Property("StateJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "SettledAtUtc"); + + b.ToTable("ExplorationRuns"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.ForgingJob", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("EndsAtUtc") + .HasColumnType("TEXT"); + + b.Property("RecipeKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SettledAtUtc") + .HasColumnType("TEXT"); + + b.Property("StartedAtUtc") + .HasColumnType("TEXT"); + + b.Property("StateJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "SettledAtUtc"); + + b.ToTable("ForgingJobs"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.GatewaySession", b => + { + b.Property("BotAppId") + .HasColumnType("TEXT"); + + b.Property("LastSeq") + .HasColumnType("INTEGER"); + + b.Property("SessionId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("BotAppId"); + + b.ToTable("GatewaySessions"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.ItemInstance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AcquiredAtUtc") + .HasColumnType("TEXT"); + + b.Property("Bound") + .HasColumnType("INTEGER"); + + b.Property("CatalogId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Locked") + .HasColumnType("INTEGER"); + + b.Property("PayloadJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Quality") + .HasColumnType("INTEGER"); + + b.Property("Quantity") + .HasColumnType("INTEGER"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("Version") + .IsConcurrencyToken() + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "CatalogId"); + + b.ToTable("ItemInstances"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.LedgerEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BalanceAfter") + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Currency") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Delta") + .HasColumnType("INTEGER"); + + b.Property("Reason") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RefId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RefType") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("RefType", "RefId"); + + b.HasIndex("UserId", "CreatedAtUtc"); + + b.ToTable("LedgerEntries"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.MailMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Content") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ReadAtUtc") + .HasColumnType("TEXT"); + + b.Property("ReceiverUserId") + .HasColumnType("INTEGER"); + + b.Property("SenderUserId") + .HasColumnType("INTEGER"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ReceiverUserId", "ReadAtUtc"); + + b.ToTable("MailMessages"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.MarketListing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ClosedAtUtc") + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Fee") + .HasColumnType("INTEGER"); + + b.Property("ItemInstanceId") + .HasColumnType("INTEGER"); + + b.Property("Price") + .HasColumnType("INTEGER"); + + b.Property("SellerUserId") + .HasColumnType("INTEGER"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("SellerUserId"); + + b.HasIndex("Status", "CreatedAtUtc"); + + b.ToTable("MarketListings"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.PlayerState", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CooperativePoints") + .HasColumnType("INTEGER"); + + b.Property("Credits") + .HasColumnType("INTEGER"); + + b.Property("Diamonds") + .HasColumnType("INTEGER"); + + b.Property("DinnerClaimedOn") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Exp") + .HasColumnType("INTEGER"); + + b.Property("ExploreTimes") + .HasColumnType("INTEGER"); + + b.Property("ForgePoints") + .HasColumnType("INTEGER"); + + b.Property("HorseRacingPoints") + .HasColumnType("INTEGER"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.Property("LogonOn") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LunchClaimedOn") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SignInStreak") + .HasColumnType("INTEGER"); + + b.Property("SignedOn") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Version") + .IsConcurrencyToken() + .HasColumnType("INTEGER"); + + b.HasKey("UserId"); + + b.ToTable("PlayerStates"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.ProcessedEvent", b => + { + b.Property("EventId") + .HasColumnType("TEXT"); + + b.Property("MsgSeq") + .HasColumnType("INTEGER"); + + b.Property("ProcessedAtUtc") + .HasColumnType("TEXT"); + + b.Property("ReceivedAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("EventId", "MsgSeq"); + + b.HasIndex("ReceivedAtUtc"); + + b.ToTable("ProcessedEvents"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.RenameRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("RequestedName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ReviewedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("TargetId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TargetType") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Status", "CreatedAtUtc"); + + b.ToTable("RenameRequests"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.SignInRecord", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("SignInDate") + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("RewardJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("UserId", "SignInDate"); + + b.ToTable("SignInRecords"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.SimulationRun", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FinishedAtUtc") + .HasColumnType("TEXT"); + + b.Property("OptionsJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ResultJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RoundsJson") + .HasColumnType("TEXT"); + + b.Property("Seed") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("StartedAtUtc") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "StartedAtUtc"); + + b.ToTable("SimulationRuns"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.SimulationStatistic", b => + { + b.Property("Scope") + .HasColumnType("TEXT"); + + b.Property("CatalogId") + .HasColumnType("TEXT"); + + b.Property("StatsJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("Scope", "CatalogId"); + + b.ToTable("SimulationStatistics"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.Squad", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Squads"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.SquadMember", b => + { + b.Property("SquadId") + .HasColumnType("INTEGER"); + + b.Property("Slot") + .HasColumnType("INTEGER"); + + b.Property("CharacterId") + .HasColumnType("INTEGER"); + + b.HasKey("SquadId", "Slot"); + + b.ToTable("SquadMembers"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.Store", b => + { + b.Property("Key") + .HasColumnType("TEXT"); + + b.Property("ConfigJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Kind") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RefreshAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("Stores"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.StoreGood", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ItemCatalogId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("INTEGER"); + + b.Property("PriceCurrency") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Quota") + .HasColumnType("INTEGER"); + + b.Property("RefreshAtUtc") + .HasColumnType("TEXT"); + + b.Property("Stock") + .HasColumnType("INTEGER"); + + b.Property("StoreKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("StoreKey"); + + b.ToTable("StoreGoods"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.Trade", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BuyerUserId") + .HasColumnType("INTEGER"); + + b.Property("ClosedAtUtc") + .HasColumnType("TEXT"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("SellerUserId") + .HasColumnType("INTEGER"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("SellerUserId"); + + b.ToTable("Trades"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.TradeItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FromUserId") + .HasColumnType("INTEGER"); + + b.Property("ItemInstanceId") + .HasColumnType("INTEGER"); + + b.Property("Price") + .HasColumnType("INTEGER"); + + b.Property("Quantity") + .HasColumnType("INTEGER"); + + b.Property("TradeId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("TradeId"); + + b.ToTable("TradeItems"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.TrainingSession", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CharacterId") + .HasColumnType("INTEGER"); + + b.Property("EndsAtUtc") + .HasColumnType("TEXT"); + + b.Property("SettledAtUtc") + .HasColumnType("TEXT"); + + b.Property("StartedAtUtc") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "SettledAtUtc"); + + b.ToTable("TrainingSessions"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Handle") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastSeenAtUtc") + .HasColumnType("TEXT"); + + b.Property("Nickname") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("Version") + .IsConcurrencyToken() + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("Handle") + .IsUnique(); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.UserIdentity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAtUtc") + .HasColumnType("TEXT"); + + b.Property("Provider") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Scene") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UnionSubject") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UnionSubject"); + + b.HasIndex("UserId"); + + b.HasIndex("Provider", "Subject") + .IsUnique(); + + b.ToTable("UserIdentities"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.UserRole", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("Role") + .HasColumnType("INTEGER"); + + b.HasKey("UserId", "Role"); + + b.ToTable("UserRoles"); + }); + + modelBuilder.Entity("OshimaBot.Data.Entities.UserSession", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CurrentRegion") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PageCursor") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PendingActionJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PendingExpiresAtUtc") + .HasColumnType("TEXT"); + + b.Property("UpdatedAtUtc") + .HasColumnType("TEXT"); + + b.HasKey("UserId"); + + b.ToTable("UserSessions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OshimaBot/Data/PlayerState.cs b/OshimaBot/Data/PlayerState.cs new file mode 100644 index 0000000..6f6fae2 --- /dev/null +++ b/OshimaBot/Data/PlayerState.cs @@ -0,0 +1,175 @@ +namespace OshimaBot.Data.Entities; + +/// 替代旧版 saved/{uid}.json 的主存档行。日期字段按 Asia/Shanghai 存 yyyy-MM-dd。 +public sealed class PlayerState +{ + public long UserId { get; set; } + public long Credits { get; set; } + public long Diamonds { get; set; } + public long Exp { get; set; } + public int Level { get; set; } = 1; + public int SignInStreak { get; set; } + public string SignedOn { get; set; } = ""; + public string LogonOn { get; set; } = ""; + public string LunchClaimedOn { get; set; } = ""; + public string DinnerClaimedOn { get; set; } = ""; + public int ExploreTimes { get; set; } + public long HorseRacingPoints { get; set; } + public long CooperativePoints { get; set; } + public long ForgePoints { get; set; } + public DateTime UpdatedAtUtc { get; set; } = DateTime.UtcNow; + public int Version { get; set; } +} + +/// 只存 catalog_id + 版本 + 数值快照,不序列化 FunGame.Core 实体对象。 +public sealed class Character +{ + public long Id { get; set; } + public long UserId { get; set; } + public string CatalogId { get; set; } = ""; + public string CatalogVersion { get; set; } = ""; + public string Name { get; set; } = ""; + public int Level { get; set; } = 1; + public long Exp { get; set; } + public int BreakLevel { get; set; } + public string AttrsJson { get; set; } = "{}"; + public bool IsMain { get; set; } + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; +} + +public sealed class CharacterSkill +{ + public long CharacterId { get; set; } + public string SkillId { get; set; } = ""; + public int Level { get; set; } = 1; + public int Slot { get; set; } +} + +public sealed class CharacterEquipment +{ + public long CharacterId { get; set; } + public string Slot { get; set; } = ""; + public long ItemInstanceId { get; set; } +} + +public sealed class ItemInstance +{ + public long Id { get; set; } + public long UserId { get; set; } + public string CatalogId { get; set; } = ""; + public int Quantity { get; set; } = 1; + public int Quality { get; set; } + public bool Locked { get; set; } + public bool Bound { get; set; } + public string PayloadJson { get; set; } = "{}"; + public DateTime AcquiredAtUtc { get; set; } = DateTime.UtcNow; + public int Version { get; set; } +} + +public sealed class Squad +{ + public long Id { get; set; } + public long UserId { get; set; } + public string Name { get; set; } = ""; + public bool IsActive { get; set; } +} + +public sealed class SquadMember +{ + public long SquadId { get; set; } + public long CharacterId { get; set; } + public int Slot { get; set; } +} + +public sealed class TrainingSession +{ + public long Id { get; set; } + public long UserId { get; set; } + public long CharacterId { get; set; } + public DateTime StartedAtUtc { get; set; } + public DateTime EndsAtUtc { get; set; } + public DateTime? SettledAtUtc { get; set; } +} + +public sealed class DailyQuest +{ + public long UserId { get; set; } + public string QuestKey { get; set; } = ""; + public string QuestDate { get; set; } = ""; + public int Status { get; set; } + public string ProgressJson { get; set; } = "{}"; + public DateTime? ClaimedAtUtc { get; set; } +} + +public sealed class SignInRecord +{ + public long UserId { get; set; } + public string SignInDate { get; set; } = ""; + public string RewardJson { get; set; } = "{}"; + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; +} + +public sealed class ActivityProgress +{ + public long UserId { get; set; } + public string ActivityKey { get; set; } = ""; + public string ProgressJson { get; set; } = "{}"; + public string ClaimedJson { get; set; } = "[]"; + public DateTime UpdatedAtUtc { get; set; } = DateTime.UtcNow; +} + +public sealed class ExplorationRun +{ + public long Id { get; set; } + public long UserId { get; set; } + public string RegionKey { get; set; } = ""; + public string StateJson { get; set; } = "{}"; + public DateTime StartedAtUtc { get; set; } + public DateTime EndsAtUtc { get; set; } + public DateTime? SettledAtUtc { get; set; } +} + +public sealed class ForgingJob +{ + public long Id { get; set; } + public long UserId { get; set; } + public string RecipeKey { get; set; } = ""; + public string StateJson { get; set; } = "{}"; + public DateTime StartedAtUtc { get; set; } + public DateTime EndsAtUtc { get; set; } + public DateTime? SettledAtUtc { get; set; } +} + +public sealed class MailMessage +{ + public long Id { get; set; } + public long? SenderUserId { get; set; } + public long ReceiverUserId { get; set; } + public string Subject { get; set; } = ""; + public string Content { get; set; } = ""; + public DateTime? ReadAtUtc { get; set; } + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; +} + +public sealed class RenameRequest +{ + public long Id { get; set; } + public long UserId { get; set; } + public string TargetType { get; set; } = ""; + public string TargetId { get; set; } = ""; + public string RequestedName { get; set; } = ""; + public int Status { get; set; } + public DateTime CreatedAtUtc { get; set; } = DateTime.UtcNow; + public DateTime? ReviewedAtUtc { get; set; } +} + +/// MUD 会话态:当前场景、待确认动作、分页游标,替代内存字典与 SemaphoreSlim。 +public sealed class UserSession +{ + public long UserId { get; set; } + public string CurrentRegion { get; set; } = ""; + public string PendingActionJson { get; set; } = ""; + public DateTime? PendingExpiresAtUtc { get; set; } + public string PageCursor { get; set; } = ""; + public DateTime UpdatedAtUtc { get; set; } = DateTime.UtcNow; +} diff --git a/OshimaBot/Data/SystemEntities.cs b/OshimaBot/Data/SystemEntities.cs new file mode 100644 index 0000000..abbb17f --- /dev/null +++ b/OshimaBot/Data/SystemEntities.cs @@ -0,0 +1,49 @@ +namespace OshimaBot.Data.Entities; + +/// 事件幂等:替代 IMemoryCache,重启/多实例后仍可去重。清理任务按 ReceivedAtUtc 删除过期行。 +public sealed class ProcessedEvent +{ + public string EventId { get; set; } = ""; + public int MsgSeq { get; set; } + public DateTime ReceivedAtUtc { get; set; } = DateTime.UtcNow; + public DateTime? ProcessedAtUtc { get; set; } +} + +/// WebSocket Resume 所需会话信息。 +public sealed class GatewaySession +{ + public string BotAppId { get; set; } = ""; + public string SessionId { get; set; } = ""; + public long LastSeq { get; set; } + public DateTime UpdatedAtUtc { get; set; } = DateTime.UtcNow; +} + +/// 替代 rounds_archive.zip 与内存中的 LastRecord。 +public sealed class SimulationRun +{ + public long Id { get; set; } + public long? UserId { get; set; } + public string Seed { get; set; } = ""; + public string OptionsJson { get; set; } = "{}"; + public string ResultJson { get; set; } = "{}"; + public string? RoundsJson { get; set; } + public DateTime StartedAtUtc { get; set; } = DateTime.UtcNow; + public DateTime? FinishedAtUtc { get; set; } +} + +/// 替代 CharacterStatistics.json / TeamCharacterStatistics.json 与静态字典。 +public sealed class SimulationStatistic +{ + public string Scope { get; set; } = "character"; + public string CatalogId { get; set; } = ""; + public string StatsJson { get; set; } = "{}"; + public DateTime UpdatedAtUtc { get; set; } = DateTime.UtcNow; +} + +/// 少量动态 KV,替代 rainbot/config.json、daily.json、giftbox.json 等配置文件。 +public sealed class AppConfig +{ + public string Key { get; set; } = ""; + public string ValueJson { get; set; } = "{}"; + public DateTime UpdatedAtUtc { get; set; } = DateTime.UtcNow; +} diff --git a/OshimaBot/OshimaBot.csproj b/OshimaBot/OshimaBot.csproj index adeb1e1..c2044ed 100644 --- a/OshimaBot/OshimaBot.csproj +++ b/OshimaBot/OshimaBot.csproj @@ -12,6 +12,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/OshimaBot/Program.cs b/OshimaBot/Program.cs index 1bcb9c8..1075c10 100644 --- a/OshimaBot/Program.cs +++ b/OshimaBot/Program.cs @@ -1,4 +1,7 @@ +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; +using OshimaBot.Data; using OshimaBot.Game.Services; using OshimaBot.Models; using OshimaBot.Security; @@ -32,6 +35,20 @@ builder.Services.AddOptions() builder.Services.AddSingleton(); +builder.Services.AddDbContext(options => +{ + string connectionString = builder.Configuration.GetValue( + $"{DatabaseOptions.SectionName}:ConnectionString") ?? "Data Source=oshimobot.db"; + SqliteConnectionStringBuilder sqlite = new(connectionString); + if (!Path.IsPathRooted(sqlite.DataSource)) + { + // 相对路径统一基于 ContentRootPath,保证应用运行时与 EF CLI 指向同一个库文件。 + sqlite.DataSource = Path.GetFullPath(Path.Combine(builder.Environment.ContentRootPath, sqlite.DataSource)); + } + options.UseSqlite(sqlite.ToString()); +}); +builder.Services.AddHostedService(); + builder.Services.AddHttpClient(QQBotService.HttpClientName, client => { client.Timeout = TimeSpan.FromSeconds(builder.Configuration.GetValue("QQBot:RequestTimeoutSeconds", 30)); diff --git a/OshimaBot/appsettings.json b/OshimaBot/appsettings.json index f47523c..b8b0e57 100644 --- a/OshimaBot/appsettings.json +++ b/OshimaBot/appsettings.json @@ -21,7 +21,7 @@ "GatewayRequestTimeoutSeconds": 15 }, "Database": { - "ConnectionString": "Data Source=oshimobot.db", + "ConnectionString": "Data Source=oshimobot.db;Default Timeout=30", "ApplyMigrationsOnStartup": true }, "Server": {