From b4dc7fc9aeddfd8fbf71933dab3b256cd13e4859 Mon Sep 17 00:00:00 2001 From: QiuSW <105186638@qq.com> Date: Mon, 14 Sep 2026 16:08:55 +0800 Subject: [PATCH] feat: track image search links and preserve manual overrides (#279) --- server/app/goauto/models/schema.go | 3 ++- server/app/goauto/shopeeproduct/service.go | 2 +- .../1789400100000_image_search_link_marker.go | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 server/cmd/migrate/migration/version-local/1789400100000_image_search_link_marker.go diff --git a/server/app/goauto/models/schema.go b/server/app/goauto/models/schema.go index 0225df5..28bbbc8 100644 --- a/server/app/goauto/models/schema.go +++ b/server/app/goauto/models/schema.go @@ -417,7 +417,8 @@ type ShopeeProduct struct { // 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 // 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 // #41 import and may be overridden manually; the product domain never joins // syb_products at read time. diff --git a/server/app/goauto/shopeeproduct/service.go b/server/app/goauto/shopeeproduct/service.go index ab551e8..a351360 100644 --- a/server/app/goauto/shopeeproduct/service.go +++ b/server/app/goauto/shopeeproduct/service.go @@ -303,7 +303,7 @@ func (service *Service) LinkPDD(ctx context.Context, id uint64, request LinkPDDR return SaveResponse{}, err } 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 { return SaveResponse{}, internalError(result.Error) diff --git a/server/cmd/migrate/migration/version-local/1789400100000_image_search_link_marker.go b/server/cmd/migrate/migration/version-local/1789400100000_image_search_link_marker.go new file mode 100644 index 0000000..7b8eb2a --- /dev/null +++ b/server/cmd/migrate/migration/version-local/1789400100000_image_search_link_marker.go @@ -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 + }) +}