Files
dbmaker/supabase/migrations/002_fix_rls_policies.sql

106 lines
4.4 KiB
SQL

-- Fix RLS policies to allow INSERT, UPDATE, DELETE operations
-- Templates policies
DROP POLICY IF EXISTS "Templates podem ser vistos por todos" ON templates_customizados;
CREATE POLICY "Templates - SELECT para todos" ON templates_customizados
FOR SELECT USING (true);
CREATE POLICY "Templates - INSERT para usuários autenticados" ON templates_customizados
FOR INSERT WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Templates - UPDATE para usuários autenticados" ON templates_customizados
FOR UPDATE USING (auth.role() = 'authenticated')
WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Templates - DELETE para usuários autenticados" ON templates_customizados
FOR DELETE USING (auth.role() = 'authenticated');
-- Clientes policies
DROP POLICY IF EXISTS "Clientes podem ser vistos por todos" ON clientes;
CREATE POLICY "Clientes - SELECT para todos" ON clientes
FOR SELECT USING (true);
CREATE POLICY "Clientes - INSERT para usuários autenticados" ON clientes
FOR INSERT WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Clientes - UPDATE para usuários autenticados" ON clientes
FOR UPDATE USING (auth.role() = 'authenticated')
WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Clientes - DELETE para usuários autenticados" ON clientes
FOR DELETE USING (auth.role() = 'authenticated');
-- Projetos policies
DROP POLICY IF EXISTS "Projetos podem ser vistos por todos" ON projetos;
CREATE POLICY "Projetos - SELECT para todos" ON projetos
FOR SELECT USING (true);
CREATE POLICY "Projetos - INSERT para usuários autenticados" ON projetos
FOR INSERT WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Projetos - UPDATE para usuários autenticados" ON projetos
FOR UPDATE USING (auth.role() = 'authenticated')
WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Projetos - DELETE para usuários autenticados" ON projetos
FOR DELETE USING (auth.role() = 'authenticated');
-- Databooks policies
CREATE POLICY "Databooks - SELECT para todos" ON databooks_mestres
FOR SELECT USING (true);
CREATE POLICY "Databooks - INSERT para usuários autenticados" ON databooks_mestres
FOR INSERT WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Databooks - UPDATE para usuários autenticados" ON databooks_mestres
FOR UPDATE USING (auth.role() = 'authenticated')
WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Databooks - DELETE para usuários autenticados" ON databooks_mestres
FOR DELETE USING (auth.role() = 'authenticated');
-- Secoes policies
CREATE POLICY "Secoes - SELECT para todos" ON secoes_databook
FOR SELECT USING (true);
CREATE POLICY "Secoes - INSERT para usuários autenticados" ON secoes_databook
FOR INSERT WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Secoes - UPDATE para usuários autenticados" ON secoes_databook
FOR UPDATE USING (auth.role() = 'authenticated')
WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Secoes - DELETE para usuários autenticados" ON secoes_databook
FOR DELETE USING (auth.role() = 'authenticated');
-- Configuracoes_pastas policies
CREATE POLICY "Pastas - SELECT para todos" ON configuracoes_pastas
FOR SELECT USING (true);
CREATE POLICY "Pastas - INSERT para usuários autenticados" ON configuracoes_pastas
FOR INSERT WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Pastas - UPDATE para usuários autenticados" ON configuracoes_pastas
FOR UPDATE USING (auth.role() = 'authenticated')
WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Pastas - DELETE para usuários autenticados" ON configuracoes_pastas
FOR DELETE USING (auth.role() = 'authenticated');
-- Documentos_auto_indexados policies
CREATE POLICY "Documentos - SELECT para todos" ON documentos_auto_indexados
FOR SELECT USING (true);
CREATE POLICY "Documentos - INSERT para usuários autenticados" ON documentos_auto_indexados
FOR INSERT WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Documentos - UPDATE para usuários autenticados" ON documentos_auto_indexados
FOR UPDATE USING (auth.role() = 'authenticated')
WITH CHECK (auth.role() = 'authenticated');
CREATE POLICY "Documentos - DELETE para usuários autenticados" ON documentos_auto_indexados
FOR DELETE USING (auth.role() = 'authenticated');