import { createDatabase, closeDatabase } from "@app/database"; import * as fs from "node:fs/promises"; import * as path from "node:path"; async function main() { const dbUrl = process.env.DATABASE_URL; if (!dbUrl) throw new Error("DATABASE_URL saknas"); const { db } = createDatabase(dbUrl); const recipes = await db.query.recipes.findMany({ where: (t, { eq }) => eq(t.verificationStatus, "verified"), }); const enriched = []; for (const r of recipes) { const ingredients = await db.query.recipeIngredients.findMany({ where: (t, { eq }) => eq(t.recipeId, r.id), }); const steps = await db.query.recipeSteps.findMany({ where: (t, { eq }) => eq(t.recipeId, r.id), }); enriched.push({ ...r, ingredients, steps }); } const publicDir = "/mnt/c/Users/Public"; const outPath = path.join(publicDir, "cibello-verified-119-result.json"); await fs.writeFile(outPath, JSON.stringify({ exportedAt: new Date().toISOString(), count: enriched.length, recipes: enriched, }, null, 2), "utf-8"); console.error(`[export-verified] Exported ${recipes.length} verified recipes to ${outPath}`); await closeDatabase(); } main().catch((err) => { console.error(err); process.exit(1); });