feat: track image search links and preserve manual overrides (#279)

This commit is contained in:
QiuSW
2026-09-14 16:08:55 +08:00
parent baa9408a36
commit b4dc7fc9ae
3 changed files with 28 additions and 2 deletions
+2 -1
View File
@@ -417,7 +417,8 @@ type ShopeeProduct struct {
// PDDProductID stays nullable and must NOT be unique: one Shopee product maps // PDDProductID stays nullable and must NOT be unique: one Shopee product maps
// to at most one PDD product, but several Shopee products may share the same // to at most one PDD product, but several Shopee products may share the same
// PDD product. // PDD product.
PDDProductID *uint64 `json:"pddProductId" gorm:"index"` PDDProductID *uint64 `json:"pddProductId" gorm:"index"`
ImageSearchLinked bool `json:"imageSearchLinked" gorm:"not null;default:false;index"`
// ImageURL holds the SYB-provided reference image URL. It is written by the // ImageURL holds the SYB-provided reference image URL. It is written by the
// #41 import and may be overridden manually; the product domain never joins // #41 import and may be overridden manually; the product domain never joins
// syb_products at read time. // syb_products at read time.
+1 -1
View File
@@ -303,7 +303,7 @@ func (service *Service) LinkPDD(ctx context.Context, id uint64, request LinkPDDR
return SaveResponse{}, err return SaveResponse{}, err
} }
result := db.Model(&models.ShopeeProduct{}).Where("id = ?", id).Updates(map[string]any{ result := db.Model(&models.ShopeeProduct{}).Where("id = ?", id).Updates(map[string]any{
"pdd_product_id": request.PDDProductID, "last_update_request_id": request.RequestID, "pdd_product_id": request.PDDProductID, "image_search_linked": false, "last_update_request_id": request.RequestID,
}) })
if result.Error != nil { if result.Error != nil {
return SaveResponse{}, internalError(result.Error) return SaveResponse{}, internalError(result.Error)
@@ -0,0 +1,25 @@
package version_local
import (
"runtime"
goautomigrations "go-admin/app/goauto/migrations"
"go-admin/cmd/migrate/migration"
common "go-admin/common/models"
"gorm.io/gorm"
)
func init() {
_, fileName, _, _ := runtime.Caller(0)
migration.Migrate.SetVersion(migration.GetFilename(fileName), migrateImageSearchLinkMarker)
}
// #279 stores whether the current Shopee→PDD link was created by image search.
func migrateImageSearchLinkMarker(db *gorm.DB, version string) error {
return db.Transaction(func(tx *gorm.DB) error {
if err := goautomigrations.Migrate(tx); err != nil {
return err
}
return tx.Create(&common.Migration{Version: version}).Error
})
}