feat: implement product grid data fetching with schema self-healing and add a database verification script.

This commit is contained in:
Michael committed 2026-03-10 13:53:33 +01:00
1 parent 08d361e980
commit 1b09994087
5 files changed
+133 -1

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
const { Pool } = require('pg');
const fs = require('fs');
const path = require('path');
async function main() {
console.log("--- DB DIAGNOSIS Start (Node) ---");
let connectionString = process.env.DATABASE_URL;
try {
const CONFIG_PATH = path.join(process.cwd(), "data", ".db-config.json");
if (fs.existsSync(CONFIG_PATH)) {
const config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
if (config.url) {
connectionString = config.url;
}
}
} catch (err) {}
if (!connectionString) {
console.error("No connection string found.");
return;
}
const pool = new Pool({ connectionString });
try {
const res = await pool.query(`
SELECT
code_fournisseur,
nom_fournisseur,
COUNT(*) as total_rows,
COUNT(DISTINCT codein) as distinct_products
FROM ventes_produits
GROUP BY code_fournisseur, nom_fournisseur
ORDER BY total_rows DESC
`);
console.table(res.rows);
} catch (error) {
console.error("Diagnosis failed:", error);
} finally {
await pool.end();
}
}
main();
+27
View File
@@ -0,0 +1,27 @@
import { db } from "@/db";
import { ventesProduits } from "@/db/schema";
import { sql } from "drizzle-orm";
async function main() {
console.log("--- DB DIAGNOSIS Start ---");
try {
const results = await db.execute(sql`
SELECT
code_fournisseur,
nom_fournisseur,
COUNT(*) as total_rows,
COUNT(DISTINCT codein) as distinct_products
FROM ventes_produits
GROUP BY code_fournisseur, nom_fournisseur
ORDER BY total_rows DESC
`);
console.table(results.rows);
} catch (error) {
console.error("Diagnosis failed:", error);
}
console.log("--- DB DIAGNOSIS End ---");
}
main();