feat: 新增数据填充 seed 命令(@Seed 宏自动注册,不记录运行历史)、database truncate/drop、打包只读模式,提示统一为 simcu::orm,版本 1.2.0
This commit is contained in:
@@ -10,10 +10,10 @@
|
||||
* // 模型变更后:快照存在 → 载入旧模型 diff,并覆盖保存新快照
|
||||
* gen.ensure("20250801000000_AddAge", "新增 age 列", "snapshot.json", models1)
|
||||
*
|
||||
* 快照 JSON 结构(版本 1):
|
||||
* {"version":1,"models":[{"table":"users","columns":[
|
||||
* 快照 JSON 结构(版本 2,较 v1 新增 enum 标记):
|
||||
* {"version":2,"models":[{"table":"users","columns":[
|
||||
* {"name":"id","column":"id","type":"Int64","key":true,"auto":true,
|
||||
* "client":false,"required":false,"maxLen":0}]}]}
|
||||
* "client":false,"required":false,"maxLen":0,"enum":false}]}]}
|
||||
*/
|
||||
|
||||
package simcu::orm.migrations
|
||||
@@ -30,7 +30,7 @@ public class ModelSnapshot {
|
||||
/// 快照内的轻量模型列表
|
||||
public var models: ArrayList<EntityModel> = ArrayList()
|
||||
/// 快照格式版本
|
||||
public static let formatVersion: Int64 = 1
|
||||
public static let formatVersion: Int64 = 2
|
||||
|
||||
public init() {}
|
||||
|
||||
@@ -50,6 +50,7 @@ public class ModelSnapshot {
|
||||
lp.isRequired = p.isRequired
|
||||
lp.maxLength = p.maxLength
|
||||
lp.typeNameOverride = p.typeName()
|
||||
lp.isEnum = p.isEnum
|
||||
lm.properties.add(lp)
|
||||
}
|
||||
if (let Some(kp) <- m.keyProperty) {
|
||||
@@ -88,6 +89,7 @@ public class ModelSnapshot {
|
||||
co["client"] = JBool(p.clientGenerated)
|
||||
co["required"] = JBool(p.isRequired)
|
||||
co["maxLen"] = JNumber("${p.maxLength}")
|
||||
co["enum"] = JBool(p.isEnum)
|
||||
cols.add(JObject(co))
|
||||
}
|
||||
mo["columns"] = JArray(cols)
|
||||
@@ -123,23 +125,24 @@ public class ModelSnapshot {
|
||||
lp.clientGenerated = getBool(co, "client")
|
||||
lp.isRequired = getBool(co, "required")
|
||||
lp.maxLength = getLong(co, "maxLen")
|
||||
lp.isEnum = getBool(co, "enum")
|
||||
if (lp.isKey) {
|
||||
lm.keyProperty = Some(lp)
|
||||
}
|
||||
lm.properties.add(lp)
|
||||
case _ => throw Exception(
|
||||
"simorm: 快照 columns 项必须是 object")
|
||||
"simcu::orm: 快照 columns 项必须是 object")
|
||||
}
|
||||
}
|
||||
case _ => throw Exception("simorm: 快照 models[].columns 必须是数组")
|
||||
case _ => throw Exception("simcu::orm: 快照 models[].columns 必须是数组")
|
||||
}
|
||||
snap.models.add(lm)
|
||||
case _ => throw Exception("simorm: 快照 models[] 项必须是 object")
|
||||
case _ => throw Exception("simcu::orm: 快照 models[] 项必须是 object")
|
||||
}
|
||||
}
|
||||
case _ => throw Exception("simorm: 快照缺少 models 数组")
|
||||
case _ => throw Exception("simcu::orm: 快照缺少 models 数组")
|
||||
}
|
||||
case _ => throw Exception("simorm: 快照根必须是 object")
|
||||
case _ => throw Exception("simcu::orm: 快照根必须是 object")
|
||||
}
|
||||
snap
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user