I need to set up a “audit” table in the database, where changes to records trigger an insert on some other table. Writing the trigger is not an issue.
Ideally, I would try to store also some sort of “current user” on the audit, which is known for instance in a specific plug. Here is the issue: I see no way to tell Ecto that all connections that are checked out from the pool should have an “initial” command sent like
set session 'myapp.current_user' = 'abcdef12-1234-1234-12345678abcdcdef';.
The problem is threefold:
- How to hook into connection checkout
- How to ensure that the connection is not held for too much time
- How to pass it down for instance to a liveview (maybe it’s just a restatement of 1+2, because the liveview is long-lived, and the connection should not be held)
Does anyone have any suggestion on how to approach the problem?
Than you beforehand!!