fix(publish): 补齐实体键唯一索引的测试覆盖与守卫消息
This commit is contained in:
@ -74,4 +74,18 @@ func TestStreetEntityKeyUnique(t *testing.T) {
|
||||
if _, err := repo.CreateStreetSnapWithImages(ctx, dup, []model.StreetSnapImage{{Image: "uniq-b.jpg", SortOrder: 1}}); err == nil {
|
||||
t.Fatalf("同一实体键的第二行应被唯一索引拒绝,实际插入成功")
|
||||
}
|
||||
|
||||
// 软删首行后,实体键不再占用(与 is_deleted = 0 的部分索引口径一致)。
|
||||
if err := db.Model(&model.StreetSnap{}).Where("id = ?", id).Update("is_deleted", 1).Error; err != nil {
|
||||
t.Fatalf("软删失败: %v", err)
|
||||
}
|
||||
again := &model.StreetSnap{JobID: 1, Title: "uniq", Year: year, City: city, Status: model.StatusPending}
|
||||
newID, err := repo.CreateStreetSnapWithImages(ctx, again, []model.StreetSnapImage{{Image: "uniq-c.jpg", SortOrder: 1}})
|
||||
if err != nil {
|
||||
t.Fatalf("软删后应可再插入同实体键: %v", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
db.Exec("DELETE FROM street_snap_images WHERE snap_id = ?", newID)
|
||||
db.Exec("DELETE FROM street_snaps WHERE id = ?", newID)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user