Anton
Anton
PPrisma
Created by Anton on 5/21/2024 in #help-and-questions
Pass current user id to Postgres
In our application we've added a trigger that logs changes to tables. As part of the logs we want to store the id of the user who did the change, and the function that's executed by the trigger gets this by calling current_setting('app.current_user_id', true). Hence the logic on the DB side expects the current user id to be passed using this setting app.current_user_id. On the application side of things we want to pass the user id for all queries. We can do this using a client extension that sets the user id when a query is being ran against the DB (Postgres). However this is a bit impractical as the PrismaClient should only be instantiated once in the application for management of the connection pool, and not once per unique user using the application. How can we make Prisma pass the app.current_user_id setting to Postgres, whilst still keeping Prisma managing the connection pool in a good way?
6 replies