feat: MBTI头像与用户规则链路升级,三端页面与接口同步
Made-with: Cursor
This commit is contained in:
@@ -92,6 +92,8 @@ func Init(dsn string) error {
|
||||
if err := db.AutoMigrate(&model.Person{}); err != nil {
|
||||
log.Printf("database: persons migrate warning: %v", err)
|
||||
}
|
||||
// persons 历史库可能因旧索引冲突导致 AutoMigrate 中断,补一层列级自愈,避免 /api/db/persons 报 Unknown column。
|
||||
ensurePersonSchema(db)
|
||||
if err := db.AutoMigrate(&model.LinkTag{}); err != nil {
|
||||
log.Printf("database: link_tags migrate warning: %v", err)
|
||||
}
|
||||
@@ -125,3 +127,22 @@ func Init(dsn string) error {
|
||||
func DB() *gorm.DB {
|
||||
return db
|
||||
}
|
||||
|
||||
func ensurePersonSchema(db *gorm.DB) {
|
||||
m := db.Migrator()
|
||||
if !m.HasColumn(&model.Person{}, "is_pinned") {
|
||||
if err := db.Exec("ALTER TABLE persons ADD COLUMN is_pinned TINYINT(1) NOT NULL DEFAULT 0 COMMENT '置顶到小程序首页'").Error; err != nil {
|
||||
log.Printf("database: persons schema ensure warning: %v; action=add is_pinned", err)
|
||||
}
|
||||
}
|
||||
if !m.HasColumn(&model.Person{}, "person_source") {
|
||||
if err := db.Exec("ALTER TABLE persons ADD COLUMN person_source VARCHAR(32) NOT NULL DEFAULT '' COMMENT '来源:空=后台手工;vip_sync=超级个体同步'").Error; err != nil {
|
||||
log.Printf("database: persons schema ensure warning: %v; action=add person_source", err)
|
||||
}
|
||||
}
|
||||
if !m.HasIndex(&model.Person{}, "idx_persons_is_pinned") {
|
||||
if err := db.Exec("CREATE INDEX idx_persons_is_pinned ON persons(is_pinned)").Error; err != nil {
|
||||
log.Printf("database: persons schema ensure warning: %v; action=create idx_persons_is_pinned", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user