feat(18-02): implement global item service, seed script, and seed integration
- searchGlobalItems with LIKE-based case-insensitive search and wildcard escaping - getGlobalItemWithOwnerCount with owner count from junction table - linkItemToGlobal/unlinkItemFromGlobal for item-global linking - seedGlobalItems idempotent seed from JSON catalog - Integrated seed into seedDefaults startup
This commit is contained in:
27
src/db/seed-global-items.ts
Normal file
27
src/db/seed-global-items.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { db as prodDb } from "./index.ts";
|
||||
import { globalItems } from "./schema.ts";
|
||||
import seedData from "./global-items-seed.json";
|
||||
|
||||
type Db = typeof prodDb;
|
||||
|
||||
/**
|
||||
* Seed the global items table with initial bikepacking gear data.
|
||||
* Idempotent: skips if any rows already exist.
|
||||
*/
|
||||
export function seedGlobalItems(db: Db = prodDb) {
|
||||
const existing = db.select().from(globalItems).limit(1).all();
|
||||
if (existing.length > 0) return;
|
||||
|
||||
for (const item of seedData) {
|
||||
db.insert(globalItems)
|
||||
.values({
|
||||
brand: item.brand,
|
||||
model: item.model,
|
||||
category: item.category ?? null,
|
||||
weightGrams: item.weightGrams ?? null,
|
||||
priceCents: item.priceCents ?? null,
|
||||
description: item.description ?? null,
|
||||
})
|
||||
.run();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user