清理数据库迁移代码 + 保留历史报告
- 删除 DROP TABLE IF EXISTS SimulationReport(不再每次启动清空报告) - 删除 4 个旧表 DROP 语句(SimTask/TargetConfig/DroneProfile/EquipmentDeployment) - 删除 MetaEntry 版本追踪表和模型文件(开发阶段不需要) - SeedDefaultData 改为简单判断:有数据就跳过,无数据就插入 - SeedDefaultScenarios 改为简单判断:有想定就跳过,无就种子 - 265 测试通过,Unity 编译通过
This commit is contained in:
parent
dc62ba8c82
commit
a3ceae5c14
@ -50,17 +50,10 @@ namespace CounterDrone.Core
|
||||
|
||||
private void SeedDefaultData(SQLiteConnection db)
|
||||
{
|
||||
db.CreateTable<MetaEntry>();
|
||||
|
||||
var defaults = DefaultData.Load(_paths);
|
||||
var currentVersion = db.Table<MetaEntry>()
|
||||
.FirstOrDefault(m => m.Key == "defaultsVersion")?.Value;
|
||||
|
||||
// 版本未变且数据已存在 → 跳过
|
||||
if (currentVersion == defaults.Version && db.Table<AmmunitionSpec>().Count() > 0)
|
||||
if (db.Table<AmmunitionSpec>().Count() > 0)
|
||||
return;
|
||||
|
||||
// 插入或更新默认数据(按 Id 覆盖,不删除用户自建数据)
|
||||
var defaults = DefaultData.Load(_paths);
|
||||
foreach (var a in defaults.Ammunition) db.InsertOrReplace(a);
|
||||
foreach (var f in defaults.FireUnits) db.InsertOrReplace(f);
|
||||
foreach (var l in defaults.LaunchPlatforms) db.InsertOrReplace(l);
|
||||
@ -73,17 +66,12 @@ namespace CounterDrone.Core
|
||||
r.WaypointsJson = System.Text.Json.JsonSerializer.Serialize(r.Waypoints);
|
||||
db.InsertOrReplace(r);
|
||||
}
|
||||
|
||||
db.InsertOrReplace(new MetaEntry { Key = "defaultsVersion", Value = defaults.Version });
|
||||
}
|
||||
|
||||
private void SeedDefaultScenarios(SQLiteConnection db)
|
||||
{
|
||||
var currentVersion = db.Table<MetaEntry>()
|
||||
.FirstOrDefault(m => m.Key == "scenariosVersion")?.Value;
|
||||
|
||||
// 版本未变 → 跳过
|
||||
if (currentVersion == "5") return;
|
||||
if (db.Table<Scenario>().Count() > 0)
|
||||
return;
|
||||
|
||||
var defaults = DefaultData.Load(_paths);
|
||||
var scenario = new ScenarioService(
|
||||
@ -93,19 +81,10 @@ namespace CounterDrone.Core
|
||||
new RoutePlanRepository(db), new WaypointRepository(db));
|
||||
|
||||
DefaultScenarios.Seed(scenario, defaults);
|
||||
|
||||
db.InsertOrReplace(new MetaEntry { Key = "scenariosVersion", Value = "5" });
|
||||
}
|
||||
|
||||
private void CreateMainTables(SQLiteConnection db)
|
||||
{
|
||||
// 删除旧版本残留表
|
||||
db.Execute("DROP TABLE IF EXISTS SimTask");
|
||||
db.Execute("DROP TABLE IF EXISTS TargetConfig");
|
||||
db.Execute("DROP TABLE IF EXISTS DroneProfile");
|
||||
db.Execute("DROP TABLE IF EXISTS EquipmentDeployment");
|
||||
db.Execute("DROP TABLE IF EXISTS SimulationReport");
|
||||
|
||||
db.CreateTable<ModelInfo>();
|
||||
db.CreateTable<AmmunitionSpec>();
|
||||
db.CreateTable<Scenario>();
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
using SQLite;
|
||||
|
||||
namespace CounterDrone.Core.Models
|
||||
{
|
||||
/// <summary>键值对元数据表(版本追踪等)</summary>
|
||||
[Table("Meta")]
|
||||
internal class MetaEntry
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string Key { get; set; } = string.Empty;
|
||||
public string Value { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user