fix: seedTags inserts missing tags instead of skipping when any exist
This commit is contained in:
@@ -70,14 +70,16 @@ const SEED_TAGS = [
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
const existing = await db.select().from(tags).limit(1);
|
||||
if (existing.length > 0) return;
|
||||
const existing = await db.select().from(tags);
|
||||
const existingNames = new Set(existing.map((t) => t.name));
|
||||
|
||||
for (const name of SEED_TAGS) {
|
||||
await db.insert(tags).values({ name });
|
||||
if (!existingNames.has(name)) {
|
||||
await db.insert(tags).values({ name });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user