diff --git a/check_counts.js b/check_counts.js new file mode 100644 index 0000000..a8daf4e --- /dev/null +++ b/check_counts.js @@ -0,0 +1,31 @@ + +const { Pool } = require('pg'); +const fs = require('fs'); +const path = require('path'); + +const CONFIG_PATH = path.join(process.cwd(), "data", ".db-config.json"); +let url = ""; +if (fs.existsSync(CONFIG_PATH)) { + url = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8")).url; +} + +const pool = new Pool({ connectionString: url || process.env.DATABASE_URL }); + +async function check() { + try { + const resSuppliers = await pool.query(\`SELECT DISTINCT code_fournisseur FROM ventes_produits LIMIT 5\`); + console.log("Suppliers in DB:", resSuppliers.rows.map(r => r.code_fournisseur)); + + for (const row of resSuppliers.rows) { + const supplier = row.code_fournisseur; + const countRes = await pool.query(\`SELECT COUNT(*) FROM ventes_produits WHERE code_fournisseur = $1\`, [supplier]); + const distinctCodein = await pool.query(\`SELECT COUNT(DISTINCT codein) FROM ventes_produits WHERE code_fournisseur = $1\`, [supplier]); + console.log(\`Supplier \${supplier}: Total Rows = \${countRes.rows[0].count}, Distinct Products = \${distinctCodein.rows[0].count}\`); + } + } catch (e) { + console.error("Error:", e); + } finally { + await pool.end(); + } +} +check(); diff --git a/check_drizzle.ts b/check_drizzle.ts new file mode 100644 index 0000000..44932d7 --- /dev/null +++ b/check_drizzle.ts @@ -0,0 +1,19 @@ + +import { db } from "./src/db"; +import { sql } from "drizzle-orm"; + +async function check() { + try { + const res = await db.execute(sql`SELECT COUNT(*) FROM ventes_produits`); + console.log("Total rows in ventes_produits:", res.rows[0].count); + + const resDistinct = await db.execute(sql`SELECT COUNT(DISTINCT codein) FROM ventes_produits`); + console.log("Total distinct codein in ventes_produits:", resDistinct.rows[0].count); + + const resSupplier = await db.execute(sql`SELECT code_fournisseur, COUNT(*) as row_count, COUNT(DISTINCT codein) as prod_count FROM ventes_produits GROUP BY code_fournisseur`); + console.log("Counts per supplier:", resSupplier.rows); + } catch (e) { + console.error("Error:", e); + } +} +check(); diff --git a/next.config.ts b/next.config.ts index da249ca..8328909 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,8 +1,13 @@ /** @type {import('next').NextConfig} */ const nextConfig = { output: "standalone", + serverExternalPackages: ["pg"], + experimental: { + serverActions: { + bodySizeLimit: "10mb", + }, + }, typescript: { - // Idem pour TypeScript ignoreBuildErrors: true, }, eslint: {