Files
LogiFlow/debug_production.sql
T
michaelschal c45bda21c5 Improve financial records processing and add production debugging tools
Update schema for financial records to allow optional fields and introduce a SQL script for detailed production debugging of financial data and related entities.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869/2Jd7tYp
2025-09-08 14:49:09 +00:00

77 lines
2.8 KiB
PL/PgSQL

-- 🔍 DIAGNOSTIC PRODUCTION COMPLET - Module Avoirs
-- Copiez-collez ce script dans votre utilitaire SQL pour diagnostic précis
BEGIN;
-- SECTION 1: STRUCTURE DES TABLES
SELECT 'VÉRIFICATION STRUCTURE TABLES' AS section_title;
-- Table avoirs - structure exacte
SELECT 'STRUCTURE_AVOIRS' AS check_type, column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = 'avoirs' AND table_schema = 'public'
ORDER BY ordinal_position;
-- Table suppliers - structure exacte
SELECT 'STRUCTURE_SUPPLIERS' AS check_type, column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'suppliers' AND table_schema = 'public'
ORDER BY ordinal_position;
-- Table groups - structure exacte
SELECT 'STRUCTURE_GROUPS' AS check_type, column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'groups' AND table_schema = 'public'
ORDER BY ordinal_position;
-- Table users - structure exacte
SELECT 'STRUCTURE_USERS' AS check_type, column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'users' AND table_schema = 'public'
ORDER BY ordinal_position;
-- SECTION 2: CONTRAINTES
SELECT 'CONTRAINTES_AVOIRS' AS check_type, conname AS constraint_name, contype AS type,
confrelid::regclass AS referenced_table
FROM pg_constraint
WHERE conrelid = 'avoirs'::regclass;
-- SECTION 3: DONNÉES EXISTANTES
SELECT 'COMPTES_TABLES' AS check_type, 'suppliers' AS table_name, COUNT(*) AS count FROM suppliers
UNION ALL
SELECT 'COMPTES_TABLES', 'groups', COUNT(*) FROM groups
UNION ALL
SELECT 'COMPTES_TABLES', 'users', COUNT(*) FROM users
UNION ALL
SELECT 'COMPTES_TABLES', 'avoirs', COUNT(*) FROM avoirs;
-- SECTION 4: EXEMPLES DE DONNÉES (si elles existent)
-- Suppliers
SELECT 'EXEMPLES_SUPPLIERS' AS check_type, id, name FROM suppliers LIMIT 3;
-- Groups
SELECT 'EXEMPLES_GROUPS' AS check_type, id, name FROM groups LIMIT 3;
-- Users
SELECT 'EXEMPLES_USERS' AS check_type, id,
COALESCE(username, 'no_username') AS username,
role
FROM users LIMIT 3;
-- SECTION 5: TEST DE COMPATIBILITÉ
-- Test si on peut insérer avec des champs NULL
SELECT 'TEST_COMPATIBILITÉ' AS check_type,
CASE
WHEN (SELECT is_nullable FROM information_schema.columns
WHERE table_name = 'avoirs' AND column_name = 'invoice_reference') = 'YES'
THEN 'invoice_reference_NULLABLE'
ELSE 'invoice_reference_NOT_NULL'
END AS invoice_ref_status,
CASE
WHEN (SELECT is_nullable FROM information_schema.columns
WHERE table_name = 'avoirs' AND column_name = 'amount') = 'YES'
THEN 'amount_NULLABLE'
ELSE 'amount_NOT_NULL'
END AS amount_status;
ROLLBACK; -- Ne pas sauvegarder, c'est juste du diagnostic