Skip to content

Commit

Permalink
🩹 修改自动迁移后设置表注释前使用新会话
Browse files Browse the repository at this point in the history
Signed-off-by: liutianqi <[email protected]>
  • Loading branch information
iTanken committed Dec 24, 2023
1 parent 15d716a commit 8b81196
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ func (m Migrator) AutoMigrate(dst ...interface{}) error {
}
for i := 0; i < len(dst) && i < len(comments); i++ {
value := dst[i]
tx := m.DB.Session(&gorm.Session{})
comment := strings.ReplaceAll(comments[i], "'", "''")
if err := m.RunWithValue(value, func(stmt *gorm.Statement) error {
return m.DB.Exec(fmt.Sprintf("COMMENT ON TABLE ? IS '%s'", comment), m.CurrentTable(stmt)).Error
return tx.Exec(fmt.Sprintf("COMMENT ON TABLE ? IS '%s'", comment), m.CurrentTable(stmt)).Error
}); err != nil {
return err
}
Expand Down

0 comments on commit 8b81196

Please sign in to comment.