package tables import ( "time" "git.x2erp.com/qdy/go-db/sqldef" ) func init() { sqldef.AddRegistration(func(r *sqldef.Registry) { tb := sqldef.NewTable("inventory_snapshot", "库存快照表"). ID("snapshot_id", 32).Comment("快照ID,主键").End(). String("sku_id", 32).NotNull().Comment("商品SKU").End(). String("channel_id", 32).NotNull().Comment("所在渠道").End(). String("tenant_id", 8).NotNull().Comment("租户ID").End(). Int("quantity").NotNull().Default("0").Comment("可用库存数量").End(). DateTime("snapshot_time").NotNull().Comment("快照时间点").End(). DateTime("extracted_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("数据抽取时间").End() r.RegisterTable(tb.Build()) }) } // InventorySnapshot 库存快照表结构体 type InventorySnapshot struct { SnapshotID string `gorm:"column:snapshot_id;type:varchar(32);primaryKey;not null;comment:快照ID,主键"` SkuID string `gorm:"column:sku_id;type:varchar(32);not null;comment:商品SKU;index:idx_sku_channel"` ChannelID string `gorm:"column:channel_id;type:varchar(32);not null;comment:所在渠道;index:idx_sku_channel"` Quantity int `gorm:"column:quantity;not null;default:0;comment:可用库存数量"` SnapshotTime time.Time `gorm:"column:snapshot_time;not null;comment:快照时间点"` ExtractedAt time.Time `gorm:"column:extracted_at;not null;default:CURRENT_TIMESTAMP;comment:数据抽取时间"` TenantId string `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"` } func (InventorySnapshot) TableName() string { return "inventory_snapshot" }