diff --git a/attached_assets/{7C6D9420-CCDC-4B7C-8E38-8581900E6E96}_1757341115795.png b/attached_assets/{7C6D9420-CCDC-4B7C-8E38-8581900E6E96}_1757341115795.png new file mode 100644 index 0000000..d36e5a6 Binary files /dev/null and b/attached_assets/{7C6D9420-CCDC-4B7C-8E38-8581900E6E96}_1757341115795.png differ diff --git a/sql/diagnostic_avoirs_production.sql b/sql/diagnostic_avoirs_production.sql new file mode 100644 index 0000000..451ced6 --- /dev/null +++ b/sql/diagnostic_avoirs_production.sql @@ -0,0 +1,55 @@ +-- 🔍 DIAGNOSTIC COMPLET - Table avoirs pour production +-- Copiez-collez ce script dans votre utilitaire SQL pour diagnostiquer le problème + +-- 1. Vérifier si la table existe +SELECT EXISTS ( + SELECT FROM information_schema.tables + WHERE table_schema = 'public' + AND table_name = 'avoirs' +) AS table_exists; + +-- 2. Voir la structure de la table (si elle existe) +SELECT column_name, data_type, is_nullable, column_default +FROM information_schema.columns +WHERE table_name = 'avoirs' +AND table_schema = 'public' +ORDER BY ordinal_position; + +-- 3. Vérifier les contraintes +SELECT conname, contype, confrelid::regclass AS referenced_table +FROM pg_constraint +WHERE conrelid = 'avoirs'::regclass; + +-- 4. Tester une insertion basique pour voir l'erreur exacte +-- ATTENTION: Adaptez les valeurs selon vos données existantes ! +INSERT INTO avoirs ( + supplier_id, + group_id, + invoice_reference, + amount, + comment, + commercial_processed, + created_by +) VALUES ( + 1, -- Utilisez un supplier_id qui existe dans votre table suppliers + 1, -- Utilisez un group_id qui existe dans votre table groups + 'TEST-DIAGNOSTIC-001', + 50.00, + 'Test diagnostic production', + false, + 'admin' -- Utilisez un user ID qui existe dans votre table users +) RETURNING id, created_at; + +-- 5. Si l'insertion échoue, voir les tables liées +SELECT 'suppliers' AS table_name, COUNT(*) AS count FROM suppliers +UNION ALL +SELECT 'groups' AS table_name, COUNT(*) FROM groups +UNION ALL +SELECT 'users' AS table_name, COUNT(*) FROM users; + +-- 6. Voir les premiers enregistrements des tables liées +SELECT 'suppliers' AS source, id, name FROM suppliers LIMIT 3 +UNION ALL +SELECT 'groups' AS source, id::text, name FROM groups LIMIT 3 +UNION ALL +SELECT 'users' AS source, id, COALESCE(username, 'no_username') FROM users LIMIT 3; \ No newline at end of file diff --git a/sql/recreate_avoirs_table.sql b/sql/recreate_avoirs_table.sql new file mode 100644 index 0000000..f4e134d --- /dev/null +++ b/sql/recreate_avoirs_table.sql @@ -0,0 +1,67 @@ +-- 🔧 RECREATION COMPLETE - Table avoirs +-- Si la table existe déjà avec des problèmes, utilisez ce script pour la recréer + +-- 1. Supprimer la table existante (ATTENTION: supprime les données!) +DROP TABLE IF EXISTS avoirs CASCADE; + +-- 2. Recréer la table avec la bonne structure +CREATE TABLE avoirs ( + id SERIAL PRIMARY KEY, + supplier_id INTEGER NOT NULL REFERENCES suppliers(id) ON DELETE CASCADE, + group_id INTEGER NOT NULL REFERENCES groups(id) ON DELETE CASCADE, + invoice_reference VARCHAR(255), + amount DECIMAL(10,2), + comment TEXT, + commercial_processed BOOLEAN DEFAULT FALSE, + status VARCHAR(50) DEFAULT 'En attente de demande' CHECK (status IN ('En attente de demande', 'Demandé', 'Reçu')), + webhook_sent BOOLEAN DEFAULT FALSE, + nocodb_verified BOOLEAN DEFAULT FALSE, + nocodb_verified_at TIMESTAMP, + processed_at TIMESTAMP, + created_by VARCHAR(255) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +-- 3. Créer les index +CREATE INDEX idx_avoirs_supplier_id ON avoirs(supplier_id); +CREATE INDEX idx_avoirs_group_id ON avoirs(group_id); +CREATE INDEX idx_avoirs_created_by ON avoirs(created_by); +CREATE INDEX idx_avoirs_status ON avoirs(status); +CREATE INDEX idx_avoirs_created_at ON avoirs(created_at DESC); + +-- 4. Créer le trigger pour updated_at +CREATE OR REPLACE FUNCTION update_avoirs_updated_at() +RETURNS TRIGGER AS $$ +BEGIN + NEW.updated_at = CURRENT_TIMESTAMP; + RETURN NEW; +END; +$$ language 'plpgsql'; + +CREATE TRIGGER update_avoirs_updated_at_trigger + BEFORE UPDATE ON avoirs + FOR EACH ROW + EXECUTE FUNCTION update_avoirs_updated_at(); + +-- 5. Tester une insertion +INSERT INTO avoirs ( + supplier_id, + group_id, + invoice_reference, + amount, + comment, + commercial_processed, + created_by +) VALUES ( + 1, -- Changez selon vos données + 1, -- Changez selon vos données + 'TEST-CREATION', + 75.50, + 'Test après recréation', + false, + 'admin' -- Changez selon vos données +) RETURNING id, created_at; + +-- 6. Si le test réussit, supprimer l'enregistrement de test +DELETE FROM avoirs WHERE invoice_reference = 'TEST-CREATION'; \ No newline at end of file