fix: narrow image search migration (#278)

This commit is contained in:
QiuSW
2026-09-14 16:31:07 +08:00
parent b4dc7fc9ae
commit 35b69fc25a
@@ -3,7 +3,6 @@ package version_local
import (
"runtime"
goautomigrations "go-admin/app/goauto/migrations"
"go-admin/cmd/migrate/migration"
common "go-admin/common/models"
"gorm.io/gorm"
@@ -17,13 +16,11 @@ func init() {
// #278 permits image-search tasks while preserving existing task rows.
func migrateImageSearchCollection(db *gorm.DB, version string) error {
return db.Transaction(func(tx *gorm.DB) error {
if err := goautomigrations.Migrate(tx); err != nil {
return err
}
if tx.Dialector.Name() == "mysql" {
if err := tx.Exec("ALTER TABLE collection_task DROP CHECK ck_collection_task_source").Error; err != nil {
return err
}
// MySQL does not support ALTER CHECK in place. The migration runner
// records this version once, so dropping/recreating the named check is
// deterministic and does not trigger a whole-schema AutoMigrate.
_ = tx.Exec("ALTER TABLE collection_task DROP CHECK ck_collection_task_source").Error
if err := tx.Exec("ALTER TABLE collection_task ADD CONSTRAINT ck_collection_task_source CHECK (source IN ('admin','agent_current_page','image_search'))").Error; err != nil {
return err
}