| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package model
-
- import (
- "time"
-
- "git.x2erp.com/qdy/go-db/sqldef"
- )
-
- func init() {
- sqldef.AddRegistration(func(r *sqldef.Registry) {
- tb := sqldef.NewTable("dim_table_field", "表字段字典").
- ID("id", 64).Comment("主键ID").End().
- String("project_id", 8).NotNull().Comment("项目编号").End().
- String("table_name", 64).NotNull().Comment("表名").End().
- String("field_name", 64).NotNull().Comment("字段名称(英文)").End().
- String("field_name_cn", 128).NotNull().Comment("字段中文名称").End().
- String("description", 128).Comment("字段描述").End().
- String("field_type", 64).NotNull().Comment("字段类型(如:varchar, int, datetime等)").End().
- Int("field_length").Comment("字段长度/精度").End().
- Bool("is_primary_key").Default("0").NotNull().Comment("是否为主键(0:否, 1:是)").End().
- Bool("is_nullable").Default("1").NotNull().Comment("是否允许为空(0:否, 1:是)").End().
- Int("decimal_places").Comment("小数位数(对于decimal类型)").End().
- String("creator", 32).NotNull().Comment("创建人").End().
- DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End().
- DateTime("updated_at").NotNull().Default("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP").Comment("更新时间").End()
-
- // 添加唯一索引:同一项目下同一表的字段名不能重复
- //tb.AddUniqueIndex("uk_project_table_field", "project_id", "table_name", "field_name")
-
- // 添加普通索引,方便查询
- tb.AddIndex("idx_project_id", "project_id")
- tb.AddIndex("idx_table_name", "table_name")
- tb.AddIndex("idx_field_name", "field_name")
- tb.AddIndex("idx_field_name_cn", "field_name_cn")
- tb.AddIndex("idx_description", "description")
-
- r.RegisterTable(tb.Build())
- })
- }
-
- // DimTableField 表字段字典结构体
- type DimTableField struct {
- ID string `gorm:"column:id;type:varchar(64);primaryKey;comment:主键ID"`
- ProjectID string `gorm:"column:project_id;type:varchar(8);not null;index:idx_project_id;comment:项目编号"`
- TableName string `gorm:"column:table_name;type:varchar(64);not null;index:idx_table_name;comment:表名"`
- FieldName string `gorm:"column:field_name;type:varchar(64);not null;comment:字段名称(英文)"`
- FieldNameCN string `gorm:"column:field_name_cn;type:varchar(128);not null;comment:字段中文名称"`
- Description string `gorm:"column:description;type:text;comment:字段描述"`
- FieldType string `gorm:"column:field_type;type:varchar(64);not null;comment:字段类型(如:varchar, int, datetime等)"`
- FieldLength *int `gorm:"column:field_length;type:int;comment:字段长度/精度"`
- IsPrimaryKey bool `gorm:"column:is_primary_key;type:tinyint(1);not null;default:0;comment:是否为主键(0:否, 1:是)"`
- IsNullable bool `gorm:"column:is_nullable;type:tinyint(1);not null;default:1;comment:是否允许为空(0:否, 1:是)"`
- DecimalPlaces *int `gorm:"column:decimal_places;type:int;comment:小数位数(对于decimal类型)"`
- Creator string `gorm:"column:creator;type:varchar(32);not null;comment:创建人"`
- CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
- UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:更新时间"`
- }
-
- func (DimTableField) DimTableField() string {
- return "dim_table_field"
- }
|