mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +02:00
feat: implement product grid data fetching with schema self-healing and add a database verification script.
This commit is contained in:
1 parent
08d361e980
commit
1b09994087
5 files changed
+133
-1
No files matched your search
@@ -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();
|
||||
@@ -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();
|
||||
Reference in new issue
Block a user