template-saas-database-v2/ddl/schemas/storage/06-triggers.sql
Adrian Flores Cortes c1c5892364 fix(ddl): Add storage triggers and fix whatsapp RLS pattern
- Add 06-triggers.sql with trg_files_updated_at and trg_usage_updated_at
  for storage.files and storage.usage tables
- Fix RLS policies in whatsapp schema to use current_setting with true
  parameter to avoid errors when app.current_tenant_id is not set

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 17:18:07 -06:00

22 lines
932 B
SQL

-- =============================================================================
-- TRIGGERS PARA SCHEMA STORAGE
-- =============================================================================
-- Actualiza automaticamente la columna updated_at en las tablas del schema storage
-- Usa la funcion publica set_updated_at() definida en 03-functions.sql
-- Trigger para storage.files
CREATE TRIGGER trg_files_updated_at
BEFORE UPDATE ON storage.files
FOR EACH ROW
EXECUTE FUNCTION public.set_updated_at();
-- Trigger para storage.usage
CREATE TRIGGER trg_usage_updated_at
BEFORE UPDATE ON storage.usage
FOR EACH ROW
EXECUTE FUNCTION public.set_updated_at();
-- Comments
COMMENT ON TRIGGER trg_files_updated_at ON storage.files IS 'Auto-update updated_at timestamp on file record changes';
COMMENT ON TRIGGER trg_usage_updated_at ON storage.usage IS 'Auto-update updated_at timestamp on usage record changes';