-- Vérification RLS pour FACTURATION et INFORMATIONS
-- Tables critiques: invoices, organization_details, productions

-- ==========================================
-- RÉSULTATS VÉRIFICATION (16 octobre 2025)
-- ==========================================
-- AVANT FIX:
-- - invoices: RLS ✅ (4 policies)
-- - organization_details: RLS ❌ (0 policies) → CRITIQUE
-- - productions: RLS ✅ (4 policies)
--
-- APRÈS FIX (fix-rls-organization-details.sql):
-- - invoices: RLS ✅ (4 policies)
-- - organization_details: RLS ✅ (4 policies) → CORRIGÉ
-- - productions: RLS ✅ (4 policies)
--
-- STATUT: 🟢 EXCELLENT - Toutes les tables protégées
-- ==========================================

-- 1️⃣ VÉRIFICATION RLS ACTIVÉE
SELECT 
  schemaname,
  tablename,
  rowsecurity AS rls_enabled
FROM pg_tables
WHERE tablename IN ('invoices', 'organization_details', 'productions')
ORDER BY tablename;

-- 2️⃣ POLITIQUES RLS EXISTANTES
SELECT 
  schemaname,
  tablename,
  policyname,
  permissive,
  roles,
  cmd,
  qual,
  with_check
FROM pg_policies
WHERE tablename IN ('invoices', 'organization_details', 'productions')
ORDER BY tablename, cmd, policyname;

-- 3️⃣ INDEX SUR org_id
SELECT
  schemaname,
  tablename,
  indexname,
  indexdef
FROM pg_indexes
WHERE tablename IN ('invoices', 'organization_details', 'productions')
  AND indexdef ILIKE '%org_id%'
ORDER BY tablename, indexname;
