feat(#31): implement PDD product archive module

This commit is contained in:
QiuSW
2026-08-17 16:04:18 +08:00
parent 7df4546e63
commit a7a453633e
16 changed files with 648 additions and 188 deletions
@@ -0,0 +1,40 @@
package version_local
import (
"runtime"
goautomigrations "go-admin/app/goauto/migrations"
"go-admin/cmd/migrate/migration"
common "go-admin/common/models"
"gorm.io/gorm"
)
// This additive migration expands the URL-only PDD product record into the
// latest-value product archive used by collection and later purchasing flows.
func init() {
_, fileName, _, _ := runtime.Caller(0)
migration.Migrate.SetVersion(migration.GetFilename(fileName), migratePDDProductArchive)
}
func migratePDDProductArchive(db *gorm.DB, version string) error {
return db.Transaction(func(tx *gorm.DB) error {
if !tx.Migrator().HasColumn("pdd_product", "specs_json") {
if err := tx.Exec("ALTER TABLE pdd_product ADD specs_json JSON NULL").Error; err != nil {
return err
}
}
if err := tx.Exec("UPDATE pdd_product SET specs_json = JSON_ARRAY() WHERE specs_json IS NULL").Error; err != nil {
return err
}
if tx.Dialector.Name() == "mysql" {
if err := tx.Exec("ALTER TABLE pdd_product MODIFY specs_json JSON NOT NULL").Error; err != nil {
return err
}
}
if err := goautomigrations.Migrate(tx); err != nil {
return err
}
return tx.Create(&common.Migration{Version: version}).Error
})
}