diff --git a/migrations/README.md b/migrations/README.md index 974276f..3b305c8 100644 --- a/migrations/README.md +++ b/migrations/README.md @@ -31,3 +31,40 @@ migrate -database ${POSTGRESQL_URL} -path migrations up ```bash migrate -database ${POSTGRESQL_URL} -path migrations down ``` + +# How to manually change/remove/list triggers and trigger functions + +To list all trigger function, use this query: + +```sql +SELECT n.nspname as schema, + p.proname as function_name +FROM pg_proc p +JOIN pg_namespace n ON p.pronamespace = n.oid +WHERE p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype; +``` + +To list all triggers, use this query: + +```sql +SELECT event_object_schema as table_schema, + event_object_table as table_name, + trigger_name, + action_timing as trigger_time, + event_manipulation as event, + action_statement as definition +FROM information_schema.triggers +ORDER BY table_schema, table_name, trigger_name; +``` + +To drop trigger (if any), use this mutation: + +```sql +DROP TRIGGER IF EXISTS your_trigger_name ON your_table_name; +``` + +To drop trigger function, use this mutation: + +```sql +DROP FUNCTION IF EXISTS your_schema_name.your_trigger_function_name(); +```