This commit is contained in:
toom1996
2026-09-22 11:12:23 +08:00
parent 21dce13bde
commit d908036621
6 changed files with 1554 additions and 4 deletions

File diff suppressed because it is too large Load Diff

View File

@ -118,9 +118,14 @@ source varchar(32) not null default ''
source_url varchar(512) not null default ''
```
对应模型:`internal/model/runway_draft.go` 的 `BrandRunwayDraft`、`internal/model/street_snap_draft.go` 的 `StreetSnapDraft`。列由 `AutoMigrate` 托管,**模型上不加 `uniqueIndex` tag**(GORM tag 无法表达部分索引条件)。
对应模型:`internal/model/runway_draft.go` 的 `BrandRunwayDraft`、`internal/model/street_snap_draft.go` 的 `StreetSnapDraft`。**模型上不加 `uniqueIndex` tag**(GORM tag 无法表达部分索引条件)。
索引写在 `internal/database/postgres.go` 的 `EnsureDedupSchema` 中——该函数本就是「`AutoMigrate` 之外的索引补充」的既定位置,且全部 `IF NOT EXISTS` 幂等:
> **落点已变更(2026-09-21)**:服务启动时的自动迁移(`AutoMigrate` / `EnsureDedupSchema`)已移除,
> 全库结构改由 `cmd/dbtool` 的 dump 维护。加列 / 加索引现在走 `db/migrations/` 下的一次性脚本:
> 对开发库执行 → 再 `dbtool dump -clean` 重新导出。本规格的列与索引已落在
> `db/migrations/2026-09-21-03-ingest-source-idempotency.sql`(已应用)。
索引定义(部分唯一索引——全量唯一索引会因存量大量 `('','')` 冲突而建索引失败):
```sql
CREATE UNIQUE INDEX IF NOT EXISTS uq_br_draft_source

View File

@ -117,7 +117,9 @@ CREATE INDEX IF NOT EXISTS idx_image_dups_owner
**不冗余存对手的标题**:读时按 `peer_owner_kind` join 对应表取(草稿 → `*_drafts.title_en` / `.title`;正式 → `brand_runways.title_en` / `street_snaps.title`)。避免标题被改后出现陈旧副本。
建表放在 `internal/database/postgres.go` 的 `EnsureDedupSchema`(该函数本就是「`AutoMigrate` 之外的索引与表补充」的既定位置,且全部幂等)。
> **落点已变更(2026-09-21)**:`AutoMigrate` / `EnsureDedupSchema` 已移除,结构改由 `cmd/dbtool` 的 dump 维护。
> 本节的表与索引已落在 `db/migrations/2026-09-21-02-duplicate-review.sql`(已应用)。
> 今后加表 / 加索引一律走 `db/migrations/` 的一次性脚本 → 对开发库执行 → `dbtool dump -clean` 重新导出。
### 3.2 写入时机与算法
@ -226,7 +228,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS uq_ss_source
```
internal/model/image_duplicate.go 新增(模型)
internal/database/postgres.go EnsureDedupSchema 建表与索引
db/migrations/2026-09-21-02-duplicate-review.sql 建表与索引(已应用)
internal/repository/dup_repository.go 新增:写入 + 读取 + 回填
internal/repository/ingest_repository.go StreetSnapIDByEntity 改键
internal/repository/review_repository.go SaveStreetSnapFromDraft / streetApprovedSiblingImages 改键