feat(S5): add EF Core SQLite context with 33 P0-P2 tables and initial migration
This commit is contained in:
@@ -0,0 +1,185 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using OshimaBot.Data.Entities;
|
||||||
|
|
||||||
|
namespace OshimaBot.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// P0~P2 所需表。P3(clubs / rooms / betting_* 等)按计划不进入首批 Migration。
|
||||||
|
/// 不规则字段用 TEXT 存 JSON,由应用层序列化,可查询字段一律列式。
|
||||||
|
/// 外键关系在 S6 仓储层落地时补齐,当前先建表、主键与索引。
|
||||||
|
/// </summary>
|
||||||
|
public sealed class BotDbContext(DbContextOptions<BotDbContext> options) : DbContext(options)
|
||||||
|
{
|
||||||
|
public DbSet<User> Users => Set<User>();
|
||||||
|
public DbSet<UserIdentity> UserIdentities => Set<UserIdentity>();
|
||||||
|
public DbSet<UserRole> UserRoles => Set<UserRole>();
|
||||||
|
public DbSet<ApiKey> ApiKeys => Set<ApiKey>();
|
||||||
|
public DbSet<BindCode> BindCodes => Set<BindCode>();
|
||||||
|
public DbSet<AuditLog> AuditLogs => Set<AuditLog>();
|
||||||
|
|
||||||
|
public DbSet<PlayerState> PlayerStates => Set<PlayerState>();
|
||||||
|
public DbSet<Character> Characters => Set<Character>();
|
||||||
|
public DbSet<CharacterSkill> CharacterSkills => Set<CharacterSkill>();
|
||||||
|
public DbSet<CharacterEquipment> CharacterEquipment => Set<CharacterEquipment>();
|
||||||
|
public DbSet<ItemInstance> ItemInstances => Set<ItemInstance>();
|
||||||
|
public DbSet<Squad> Squads => Set<Squad>();
|
||||||
|
public DbSet<SquadMember> SquadMembers => Set<SquadMember>();
|
||||||
|
public DbSet<TrainingSession> TrainingSessions => Set<TrainingSession>();
|
||||||
|
public DbSet<DailyQuest> DailyQuests => Set<DailyQuest>();
|
||||||
|
public DbSet<SignInRecord> SignInRecords => Set<SignInRecord>();
|
||||||
|
public DbSet<ActivityProgress> ActivityProgress => Set<ActivityProgress>();
|
||||||
|
public DbSet<ExplorationRun> ExplorationRuns => Set<ExplorationRun>();
|
||||||
|
public DbSet<ForgingJob> ForgingJobs => Set<ForgingJob>();
|
||||||
|
public DbSet<MailMessage> MailMessages => Set<MailMessage>();
|
||||||
|
public DbSet<RenameRequest> RenameRequests => Set<RenameRequest>();
|
||||||
|
public DbSet<UserSession> UserSessions => Set<UserSession>();
|
||||||
|
|
||||||
|
public DbSet<LedgerEntry> LedgerEntries => Set<LedgerEntry>();
|
||||||
|
public DbSet<Store> Stores => Set<Store>();
|
||||||
|
public DbSet<StoreGood> StoreGoods => Set<StoreGood>();
|
||||||
|
public DbSet<MarketListing> MarketListings => Set<MarketListing>();
|
||||||
|
public DbSet<Trade> Trades => Set<Trade>();
|
||||||
|
public DbSet<TradeItem> TradeItems => Set<TradeItem>();
|
||||||
|
|
||||||
|
public DbSet<ProcessedEvent> ProcessedEvents => Set<ProcessedEvent>();
|
||||||
|
public DbSet<GatewaySession> GatewaySessions => Set<GatewaySession>();
|
||||||
|
public DbSet<SimulationRun> SimulationRuns => Set<SimulationRun>();
|
||||||
|
public DbSet<SimulationStatistic> SimulationStatistics => Set<SimulationStatistic>();
|
||||||
|
public DbSet<AppConfig> AppConfigs => Set<AppConfig>();
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
|
// ---- 身份与权限 ----
|
||||||
|
modelBuilder.Entity<User>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => x.Handle).IsUnique();
|
||||||
|
entity.Property(x => x.Version).IsConcurrencyToken();
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<UserIdentity>(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<UserRole>().HasKey(x => new { x.UserId, x.Role });
|
||||||
|
modelBuilder.Entity<ApiKey>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => x.KeyHash).IsUnique();
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<BindCode>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Code);
|
||||||
|
entity.HasIndex(x => x.UserId);
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<AuditLog>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.ActorUserId, x.CreatedAtUtc });
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---- 玩家存档 ----
|
||||||
|
modelBuilder.Entity<PlayerState>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.UserId);
|
||||||
|
entity.Property(x => x.Version).IsConcurrencyToken();
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<Character>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.UserId, x.IsMain });
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<CharacterSkill>().HasKey(x => new { x.CharacterId, x.SkillId, x.Slot });
|
||||||
|
modelBuilder.Entity<CharacterEquipment>().HasKey(x => new { x.CharacterId, x.Slot });
|
||||||
|
modelBuilder.Entity<ItemInstance>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.UserId, x.CatalogId });
|
||||||
|
entity.Property(x => x.Version).IsConcurrencyToken();
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<Squad>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => x.UserId);
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<SquadMember>().HasKey(x => new { x.SquadId, x.Slot });
|
||||||
|
modelBuilder.Entity<TrainingSession>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.UserId, x.SettledAtUtc });
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<DailyQuest>().HasKey(x => new { x.UserId, x.QuestKey, x.QuestDate });
|
||||||
|
modelBuilder.Entity<SignInRecord>().HasKey(x => new { x.UserId, x.SignInDate });
|
||||||
|
modelBuilder.Entity<ActivityProgress>().HasKey(x => new { x.UserId, x.ActivityKey });
|
||||||
|
modelBuilder.Entity<ExplorationRun>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.UserId, x.SettledAtUtc });
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<ForgingJob>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.UserId, x.SettledAtUtc });
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<MailMessage>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.ReceiverUserId, x.ReadAtUtc });
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<RenameRequest>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.Status, x.CreatedAtUtc });
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<UserSession>().HasKey(x => x.UserId);
|
||||||
|
|
||||||
|
// ---- 经济与交易 ----
|
||||||
|
modelBuilder.Entity<LedgerEntry>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.UserId, x.CreatedAtUtc });
|
||||||
|
entity.HasIndex(x => new { x.RefType, x.RefId });
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<Store>().HasKey(x => x.Key);
|
||||||
|
modelBuilder.Entity<StoreGood>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => x.StoreKey);
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<MarketListing>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.Status, x.CreatedAtUtc });
|
||||||
|
entity.HasIndex(x => x.SellerUserId);
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<Trade>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => x.SellerUserId);
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<TradeItem>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => x.TradeId);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---- 系统 / 运行 ----
|
||||||
|
modelBuilder.Entity<ProcessedEvent>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => new { x.EventId, x.MsgSeq });
|
||||||
|
entity.HasIndex(x => x.ReceivedAtUtc);
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<GatewaySession>().HasKey(x => x.BotAppId);
|
||||||
|
modelBuilder.Entity<SimulationRun>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(x => x.Id);
|
||||||
|
entity.HasIndex(x => new { x.UserId, x.StartedAtUtc });
|
||||||
|
});
|
||||||
|
modelBuilder.Entity<SimulationStatistic>().HasKey(x => new { x.Scope, x.CatalogId });
|
||||||
|
modelBuilder.Entity<AppConfig>().HasKey(x => x.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using OshimaBot.Models;
|
||||||
|
|
||||||
|
namespace OshimaBot.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 放在 IHostedService 中而非 Program 启动代码里:EF CLI 设计时只构建 Host、不启动 HostedService,
|
||||||
|
/// 从而避免生成 Migration 时反过来尝试执行 Migration。
|
||||||
|
/// </summary>
|
||||||
|
public sealed class DatabaseInitializer(
|
||||||
|
IServiceScopeFactory scopeFactory,
|
||||||
|
IOptions<DatabaseOptions> options,
|
||||||
|
ILogger<DatabaseInitializer> 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<BotDbContext>();
|
||||||
|
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 与外键约束。");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
namespace OshimaBot.Data.Entities;
|
||||||
|
|
||||||
|
/// <summary>所有货币变动必须与「加物品/扣物品」在同一事务写入,用于对账与防丢。</summary>
|
||||||
|
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; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
namespace OshimaBot.Data.Entities;
|
||||||
|
|
||||||
|
/// <summary>内部用户主键。业务代码只使用 Id,外部 OpenID 单独存 UserIdentity。</summary>
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>外部身份(QQ user_openid / member_openid 等),支持多身份、换绑与 union_openid 合并。</summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>一次性绑定码,用于第三方/管理端绑定 QQ OpenID,替代旧版直接回显接入码。</summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,799 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace OshimaBot.Data.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Initial : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ActivityProgress",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
ActivityKey = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ProgressJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ClaimedJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
UpdatedAtUtc = table.Column<DateTime>(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<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: true),
|
||||||
|
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
KeyHash = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ScopesJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ExpiresAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
RevokedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ApiKeys", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "AppConfigs",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Key = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ValueJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
UpdatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_AppConfigs", x => x.Key);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "AuditLogs",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
ActorUserId = table.Column<long>(type: "INTEGER", nullable: true),
|
||||||
|
Action = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Target = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
PayloadJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_AuditLogs", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "BindCodes",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Code = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Purpose = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ExpiresAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
UsedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_BindCodes", x => x.Code);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CharacterEquipment",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
CharacterId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Slot = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ItemInstanceId = table.Column<long>(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<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
CatalogId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
CatalogVersion = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Level = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
Exp = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
BreakLevel = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
AttrsJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
IsMain = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Characters", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CharacterSkills",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
CharacterId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
SkillId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Slot = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
Level = table.Column<int>(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<long>(type: "INTEGER", nullable: false),
|
||||||
|
QuestKey = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
QuestDate = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Status = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
ProgressJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ClaimedAtUtc = table.Column<DateTime>(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<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
RegionKey = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
StateJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
StartedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
EndsAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
SettledAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ExplorationRuns", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ForgingJobs",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
RecipeKey = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
StateJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
StartedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
EndsAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
SettledAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ForgingJobs", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "GatewaySessions",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
BotAppId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
SessionId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
LastSeq = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
UpdatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_GatewaySessions", x => x.BotAppId);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ItemInstances",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
CatalogId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Quantity = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
Quality = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
Locked = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||||
|
Bound = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||||
|
PayloadJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
AcquiredAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
Version = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ItemInstances", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "LedgerEntries",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Currency = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Delta = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
BalanceAfter = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Reason = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
RefType = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
RefId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_LedgerEntries", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MailMessages",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
SenderUserId = table.Column<long>(type: "INTEGER", nullable: true),
|
||||||
|
ReceiverUserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Subject = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Content = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ReadAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MailMessages", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MarketListings",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
SellerUserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
ItemInstanceId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Price = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Fee = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Status = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
ClosedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MarketListings", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "PlayerStates",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
Credits = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Diamonds = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Exp = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Level = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
SignInStreak = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
SignedOn = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
LogonOn = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
LunchClaimedOn = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
DinnerClaimedOn = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ExploreTimes = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
HorseRacingPoints = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
CooperativePoints = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
ForgePoints = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
UpdatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
Version = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_PlayerStates", x => x.UserId);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ProcessedEvents",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
EventId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
MsgSeq = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
ReceivedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
ProcessedAtUtc = table.Column<DateTime>(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<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
TargetType = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
TargetId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
RequestedName = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Status = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
ReviewedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_RenameRequests", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SignInRecords",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
SignInDate = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
RewardJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(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<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: true),
|
||||||
|
Seed = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
OptionsJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ResultJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
RoundsJson = table.Column<string>(type: "TEXT", nullable: true),
|
||||||
|
StartedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
FinishedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SimulationRuns", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SimulationStatistics",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Scope = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
CatalogId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
StatsJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
UpdatedAtUtc = table.Column<DateTime>(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<long>(type: "INTEGER", nullable: false),
|
||||||
|
Slot = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
CharacterId = table.Column<long>(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<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
IsActive = table.Column<bool>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Squads", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "StoreGoods",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
StoreKey = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
ItemCatalogId = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
PriceCurrency = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Price = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Stock = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
Quota = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
RefreshAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_StoreGoods", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Stores",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Key = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Kind = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
RefreshAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
ConfigJson = table.Column<string>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Stores", x => x.Key);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "TradeItems",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
TradeId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
FromUserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
ItemInstanceId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Quantity = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
Price = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_TradeItems", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Trades",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
BuyerUserId = table.Column<long>(type: "INTEGER", nullable: true),
|
||||||
|
SellerUserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Status = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
ClosedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Trades", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "TrainingSessions",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
CharacterId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
StartedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
EndsAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
SettledAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_TrainingSessions", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "UserIdentities",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Provider = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Subject = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
UnionSubject = table.Column<string>(type: "TEXT", nullable: true),
|
||||||
|
Scene = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_UserIdentities", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "UserRoles",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false),
|
||||||
|
Role = table.Column<int>(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<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
Handle = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Nickname = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Status = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
CreatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
LastSeenAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
Version = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Users", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "UserSessions",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
UserId = table.Column<long>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
CurrentRegion = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
PendingActionJson = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
PendingExpiresAtUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
PageCursor = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
UpdatedAtUtc = table.Column<DateTime>(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,175 @@
|
|||||||
|
namespace OshimaBot.Data.Entities;
|
||||||
|
|
||||||
|
/// <summary>替代旧版 saved/{uid}.json 的主存档行。日期字段按 Asia/Shanghai 存 yyyy-MM-dd。</summary>
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>只存 catalog_id + 版本 + 数值快照,不序列化 FunGame.Core 实体对象。</summary>
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>MUD 会话态:当前场景、待确认动作、分页游标,替代内存字典与 SemaphoreSlim。</summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
namespace OshimaBot.Data.Entities;
|
||||||
|
|
||||||
|
/// <summary>事件幂等:替代 IMemoryCache,重启/多实例后仍可去重。清理任务按 ReceivedAtUtc 删除过期行。</summary>
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>WebSocket Resume 所需会话信息。</summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>替代 rounds_archive.zip 与内存中的 LastRecord。</summary>
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>替代 CharacterStatistics.json / TeamCharacterStatistics.json 与静态字典。</summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>少量动态 KV,替代 rainbot/config.json、daily.json、giftbox.json 等配置文件。</summary>
|
||||||
|
public sealed class AppConfig
|
||||||
|
{
|
||||||
|
public string Key { get; set; } = "";
|
||||||
|
public string ValueJson { get; set; } = "{}";
|
||||||
|
public DateTime UpdatedAtUtc { get; set; } = DateTime.UtcNow;
|
||||||
|
}
|
||||||
@@ -12,6 +12,11 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
|
||||||
<PackageReference Include="Rebex.Elliptic.Ed25519" Version="1.2.2" />
|
<PackageReference Include="Rebex.Elliptic.Ed25519" Version="1.2.2" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.11" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.11">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using OshimaBot.Data;
|
||||||
using OshimaBot.Game.Services;
|
using OshimaBot.Game.Services;
|
||||||
using OshimaBot.Models;
|
using OshimaBot.Models;
|
||||||
using OshimaBot.Security;
|
using OshimaBot.Security;
|
||||||
@@ -32,6 +35,20 @@ builder.Services.AddOptions<DatabaseOptions>()
|
|||||||
|
|
||||||
builder.Services.AddSingleton<WebhookSignatureVerifier>();
|
builder.Services.AddSingleton<WebhookSignatureVerifier>();
|
||||||
|
|
||||||
|
builder.Services.AddDbContext<BotDbContext>(options =>
|
||||||
|
{
|
||||||
|
string connectionString = builder.Configuration.GetValue<string>(
|
||||||
|
$"{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<DatabaseInitializer>();
|
||||||
|
|
||||||
builder.Services.AddHttpClient(QQBotService.HttpClientName, client =>
|
builder.Services.AddHttpClient(QQBotService.HttpClientName, client =>
|
||||||
{
|
{
|
||||||
client.Timeout = TimeSpan.FromSeconds(builder.Configuration.GetValue("QQBot:RequestTimeoutSeconds", 30));
|
client.Timeout = TimeSpan.FromSeconds(builder.Configuration.GetValue("QQBot:RequestTimeoutSeconds", 30));
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"GatewayRequestTimeoutSeconds": 15
|
"GatewayRequestTimeoutSeconds": 15
|
||||||
},
|
},
|
||||||
"Database": {
|
"Database": {
|
||||||
"ConnectionString": "Data Source=oshimobot.db",
|
"ConnectionString": "Data Source=oshimobot.db;Default Timeout=30",
|
||||||
"ApplyMigrationsOnStartup": true
|
"ApplyMigrationsOnStartup": true
|
||||||
},
|
},
|
||||||
"Server": {
|
"Server": {
|
||||||
|
|||||||
Reference in New Issue
Block a user