Skip to content

Commit

Permalink
feat: update readme with info how to drop trigger and trigger funcitons
Browse files Browse the repository at this point in the history
  • Loading branch information
mgierada committed Jun 19, 2024
1 parent 7cfdc64 commit 3c8ec40
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions migrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```

0 comments on commit 3c8ec40

Please sign in to comment.