Skip to content

Commit f510014

Browse files
committed
fix(data/smartphone,scripts): drop duplicate honor-magic-7-pro and guard against future slug collisions
The seed/dump loaders fail on `UNIQUE constraint failed: smartphones.slug` because two records share `slug=honor-magic-7-pro` - a 2024-10-30 China launch and a 2025-01-08 global launch. Keep the earlier `verified: true` record under data/smartphone/honor/2024/ and remove the duplicate. Also harden `scripts/validate.py` with `_check_unique_slugs` so a future duplicate is caught before the seed step blows up CI (Test + Pages + refresh-data workflows all hit the same error on 985007d). Refs #1
1 parent 985007d commit f510014

2 files changed

Lines changed: 26 additions & 39 deletions

File tree

data/smartphone/honor/2025/honor-magic-7-pro.json

Lines changed: 0 additions & 39 deletions
This file was deleted.

scripts/validate.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ def _check_date(name: str, value: object, errors: list[str]) -> None:
110110
errors.append(f"{name}: release_date '{value}' must be ISO 8601 YYYY-MM-DD (§14.2)")
111111

112112

113+
def _check_unique_slugs(
114+
category: str, records: list[tuple[str, dict[str, Any]]], errors: list[str]
115+
) -> None:
116+
"""Each category's `slug` must be unique — seed/dump load into a UNIQUE column."""
117+
seen: dict[str, str] = {}
118+
for fname, rec in records:
119+
slug = rec.get("slug")
120+
if not isinstance(slug, str):
121+
continue
122+
if slug in seen:
123+
errors.append(
124+
f"{fname}: duplicate {category} slug '{slug}' (also in {seen[slug]})"
125+
)
126+
else:
127+
seen[slug] = fname
128+
129+
113130
def validate() -> list[str]:
114131
errors: list[str] = []
115132

@@ -122,6 +139,15 @@ def validate() -> list[str]:
122139
brand_slugs = {rec["slug"] for _, rec in brands if "slug" in rec}
123140
soc_slugs = {rec["slug"] for _, rec in socs if "slug" in rec}
124141

142+
for category, records in (
143+
("brand", brands),
144+
("soc", socs),
145+
("smartphone", phones),
146+
("gpu", gpus),
147+
("cpu", cpus),
148+
):
149+
_check_unique_slugs(category, records, errors)
150+
125151
for fname, rec in brands:
126152
_check_required(fname, rec, BRAND_REQUIRED, errors)
127153
_check_slug(fname, rec.get("slug"), errors)

0 commit comments

Comments
 (0)