feat(catalog): migrate dev seed data to manufacturer-slug-based global items
Replace brand text field with manufacturerSlug in DEV_GLOBAL_ITEMS, global-items-seed.json, and seed-global-items.ts. Add DEV_MANUFACTURERS for dev-only brands not in SEED_MANUFACTURERS. Expand SEED_MANUFACTURERS with 8 additional manufacturers referenced by seed JSON (Nemo, Therm-a-Rest, Toaks, Katadyn, HydraPak, Nitecore, Outdoor Research, Exposure Lights). Update dev-seed.ts to resolve slug→id before insert and use manufacturerId as the deduplication key. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import { and, eq, like, sql } from "drizzle-orm";
|
||||
import {
|
||||
DEV_CATEGORIES,
|
||||
DEV_GLOBAL_ITEMS,
|
||||
DEV_MANUFACTURERS,
|
||||
DEV_MARKET_PRICES,
|
||||
DEV_SETTINGS,
|
||||
DEV_SETUPS,
|
||||
@@ -79,9 +80,12 @@ async function seedDevData(database: Db = db) {
|
||||
await clearDevData(database);
|
||||
|
||||
try {
|
||||
// ── 1. Seed global items and tags ──────────────────────────
|
||||
// ── 1. Seed global items, tags, and dev-specific manufacturers ─
|
||||
await seedGlobalItems(database);
|
||||
console.log(" Global items and tags seeded.");
|
||||
for (const m of DEV_MANUFACTURERS) {
|
||||
await database.insert(schema.manufacturers).values(m).onConflictDoNothing();
|
||||
}
|
||||
console.log(" Global items, tags, and manufacturers seeded.");
|
||||
|
||||
// ── 2. Insert dev user ─────────────────────────────────────
|
||||
const [user] = await database
|
||||
@@ -123,20 +127,29 @@ async function seedDevData(database: Db = db) {
|
||||
|
||||
// ── 5. Insert global items and tag assignments ─────────────
|
||||
// DEV_GLOBAL_ITEMS may overlap with seed-global-items.json entries.
|
||||
// Insert only items that don't already exist (by brand+model).
|
||||
// Insert only items that don't already exist (by manufacturerId+model).
|
||||
const allManufacturers = await database.select().from(schema.manufacturers);
|
||||
const mfBySlug = new Map(allManufacturers.map((m) => [m.slug, m.id]));
|
||||
|
||||
const existingGlobalItems = await database
|
||||
.select()
|
||||
.from(schema.globalItems);
|
||||
const existingGlobalItemMap = new Map<string, number>();
|
||||
for (const gi of existingGlobalItems) {
|
||||
existingGlobalItemMap.set(`${gi.brand}::${gi.model}`, gi.id);
|
||||
existingGlobalItemMap.set(`${gi.manufacturerId}::${gi.model}`, gi.id);
|
||||
}
|
||||
|
||||
const globalItemIds: number[] = [];
|
||||
let newGlobalCount = 0;
|
||||
|
||||
for (const item of DEV_GLOBAL_ITEMS) {
|
||||
const key = `${item.brand}::${item.model}`;
|
||||
const mfId = mfBySlug.get(item.manufacturerSlug);
|
||||
if (!mfId) {
|
||||
console.warn(` Skipping "${item.model}" — unknown manufacturer slug: ${item.manufacturerSlug}`);
|
||||
globalItemIds.push(0); // placeholder to keep index alignment
|
||||
continue;
|
||||
}
|
||||
const key = `${mfId}::${item.model}`;
|
||||
const existingId = existingGlobalItemMap.get(key);
|
||||
if (existingId) {
|
||||
globalItemIds.push(existingId);
|
||||
@@ -144,7 +157,7 @@ async function seedDevData(database: Db = db) {
|
||||
const [inserted] = await database
|
||||
.insert(schema.globalItems)
|
||||
.values({
|
||||
brand: item.brand,
|
||||
manufacturerId: mfId,
|
||||
model: item.model,
|
||||
category: item.category,
|
||||
weightGrams: item.weightGrams,
|
||||
@@ -154,7 +167,7 @@ async function seedDevData(database: Db = db) {
|
||||
.returning();
|
||||
if (!inserted)
|
||||
throw new Error(
|
||||
`Failed to insert global item: ${item.brand} ${item.model}`,
|
||||
`Failed to insert global item: ${item.manufacturerSlug} ${item.model}`,
|
||||
);
|
||||
globalItemIds.push(inserted.id);
|
||||
newGlobalCount++;
|
||||
|
||||
Reference in New Issue
Block a user