set -e; echo "=== Step 1: Check columns ==="; bun -e 'import { db } from "./src/db/index.ts"; import { sql } from "drizzle-orm"; const r = await db.execute(sql`SELECT column_name FROM information_schema.columns WHERE table_name = '"'"'global_items'"'"' ORDER BY ordinal_position`); console.log(r.rows.map(x => x.column_name));'; echo "=== Step 2: Push schema ==="; bun run db:push; echo "=== Step 3: Nuke data ==="; bun -e 'import { db } from "./src/db/index.ts"; import { apiKeys, categories, globalItemTags, globalItems, items, oauthCodes, oauthTokens, settings, setupItems, setups, tags, threadCandidates, threads, users } from "./src/db/schema.ts"; await db.delete(setupItems); await db.delete(setups); await db.delete(threadCandidates); await db.delete(threads); await db.delete(items); await db.delete(settings); await db.delete(apiKeys); await db.delete(oauthTokens); await db.delete(oauthCodes); await db.delete(categories); await db.delete(users); await db.delete(globalItemTags); await db.delete(tags); await db.delete(globalItems); console.log("Nuke complete");'; echo "=== Step 4: Re-seed ==="; bun run db:seed:dev; echo "=== Step 5: Verify tags ==="; bun -e 'import { db } from "./src/db/index.ts"; import { tags, globalItemTags } from "./src/db/schema.ts"; import { inArray } from "drizzle-orm"; const hobbyNames = ["bikepacking","cycling","camping","hiking","backpacking","climbing","running"]; const found = await db.select().from(tags).where(inArray(tags.name, hobbyNames)); console.log("Hobby tags:", found.map(t => t.name)); const a = await db.select().from(globalItemTags); console.log("Tag assignments:", a.length);'; echo "=== Step 6: Test query ==="; bun -e 'import { getPopularItemsByTags } from "./src/server/services/discovery.service.ts"; const r = await getPopularItemsByTags(undefined, ["bikepacking","cycling","camping"], 5); console.log("Items found:", r.length); for (const i of r) console.log(" -", i.brand, i.model);'; echo "=== Done ==="
