DO $$ 
DECLARE 
    r RECORD;
BEGIN
    FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = 'steelbook') 
    LOOP
        -- Habilitar RLS
        EXECUTE 'ALTER TABLE steelbook.' || quote_ident(r.tablename) || ' ENABLE ROW LEVEL SECURITY;';
        
        -- Criar política de permissão global para usuários logados
        EXECUTE 'DROP POLICY IF EXISTS "Auth_ALL_' || r.tablename || '" ON steelbook.' || quote_ident(r.tablename) || ';';
        EXECUTE 'CREATE POLICY "Auth_ALL_' || r.tablename || '" ON steelbook.' || quote_ident(r.tablename) || ' FOR ALL USING (auth.role() = ''authenticated'');';
    END LOOP;
END $$;
