fix: seedTags inserts missing tags instead of skipping when any exist
All checks were successful
CI / ci (push) Successful in 1m15s
CI / e2e (push) Has been skipped
CI / deploy (push) Successful in 15s

This commit is contained in:
2026-04-13 14:09:28 +02:00
parent 80f4d1d9ae
commit cd55f3c282

View File

@@ -70,14 +70,16 @@ const SEED_TAGS = [
/** /**
* Seed curated tags for outdoor/adventure gear. * Seed curated tags for outdoor/adventure gear.
* Idempotent: skips if any tags already exist. * Idempotent: inserts only tags that don't already exist.
*/ */
export async function seedTags(db: Db = prodDb) { export async function seedTags(db: Db = prodDb) {
const existing = await db.select().from(tags).limit(1); const existing = await db.select().from(tags);
if (existing.length > 0) return; const existingNames = new Set(existing.map((t) => t.name));
for (const name of SEED_TAGS) { for (const name of SEED_TAGS) {
await db.insert(tags).values({ name }); if (!existingNames.has(name)) {
await db.insert(tags).values({ name });
}
} }
} }