mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Add diagnostic scripts to help troubleshoot database table issues
Add SQL scripts for diagnosing and recreating the 'avoirs' table to address potential production environment inconsistencies. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869/2Jd7tYp
This commit is contained in:
1 parent
8ae757e3a2
commit
0c3e49e19c
3 files changed
+122
No files matched your search
@@ -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;
|
||||
@@ -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';
|
||||
Reference in new issue
Block a user