feat: 新增数据填充 seed 命令(@Seed 宏自动注册,不记录运行历史)、database truncate/drop、打包只读模式,提示统一为 simcu::orm,版本 1.2.0

This commit is contained in:
2026-08-22 09:53:43 +08:00
parent 394c4a1fb5
commit 9d7b353e2f
17 changed files with 796 additions and 80 deletions
+45
View File
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* 数据填充(Seed)抽象基类(内部接口,用户不直接继承)。
*
* 用户侧用法:@Seed 类级宏(见 simcu::orm.macros),标注一个普通类,
* seedId 取类名,属性参数仅作描述:
* @Seed["初始化游戏服务器配置"]
* public class InitGames {
* public func run(ctx: DataContext): Unit {
* if (ctx.games.find("game-1").isNone()) {
* let g = Game()
* g.id = "game-1"
* g.apiKey = "key-1"
* g.name = "测试服"
* ctx.games.add(g)
* ctx.saveChanges()
* }
* }
* }
*
* 宏展开自动生成包装类(继承本基类)+ 顶层 let 注册到全局注册表,
* 用户无需手写注册文件。CLI `orm seed` 运行时把应用自己的
* DataContext 实例作为 ctx 传入 run 方法。
*
* 语义:不记录运行历史,可随时/多次运行,幂等由用户代码自行保证
* (如按 id find 后不存在再插入)。
*/
package simcu::orm.seeds
/// 数据填充统一接口(CLI 内部使用)。
public abstract class Seed {
/// 唯一 id(取 @Seed 标注的类名)
public let seedId: String
/// 填充内容说明(CLI 列表展示)
public let description: String
public init(seedId: String, description: String) {
this.seedId = seedId
this.description = description
}
/// 执行填充。ctx 为应用自己的 DbContext 实例(宏生成的包装类负责转型)。
public func run(ctx: Any): Unit
}