package tables import "git.x2erp.com/qdy/go-db/sqldef" func init() { sqldef.AddRegistration(func(r *sqldef.Registry) { // 配置模板明细表(K-V格式) tb := sqldef.NewTable("config_template_detail", "配置模板明细表"). ID("config_template_detail_id", 256).NotNull().Comment("主键ID").End(). String("config_template_id", 128).NotNull().Comment("模板ID,关联config_template表").End(). String("config_key", 64).NotNull().Comment("配置键名").End(). Text("config_value").NotNull().Comment("配置值").End(). String("value_type", 32).NotNull().Default("'string'").Comment("值类型: string/int/bool/float/json").End(). String("data_type", 32).Comment("数据类型: text/number/boolean/select/array/object").End(). Bool("is_required").NotNull().Default("0").Comment("是否必填").End(). Text("default_value").Comment("默认值").End(). Text("validation_rules").Comment("验证规则JSON").End(). Text("description").Comment("配置项说明").End(). Int("sort_order").NotNull().Default("0").Comment("排序号").End(). Bool("is_sensitive").NotNull().Default("0").Comment("是否敏感数据(如密码)").End(). Bool("is_readonly").NotNull().Default("0").Comment("是否只读").End(). String("creator", 32).NotNull().Comment("创建人").End(). DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End(). DateTime("updated_at").Default("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP").Comment("更新时间").End() // 添加索引和约束 tb.AddUniqueIndex("uk_template_key", "config_template_id", "config_key"). AddIndex("idx_template_id", "config_template_id"). AddIndex("idx_sort_order", "sort_order"). AddIndex("idx_is_sensitive", "is_sensitive") // 可选:添加外键约束(如果数据库支持) // tb.AddForeignKey("fk_template_detail_template", "template_id", "config_template", "template_id") // 注册表 r.RegisterTable(tb.Build()) }) }