Custom startup command for prisma client for migrations
See original GitHub issueProblem
At my company, we use vault to rotate credentials to postgres. Each generated set of credentials (which is in a sense just a temporary user) corresponds to a PG Role, which is temporary. In effect this means that at the start of every session (instance startup) we have to switch to a permanent role, so that any resources created are OWNED by that one, and not the temporary role.
We do this by simply running:
SET ROLE "permanent-role-name";
The problem lies in our ability to use the new Prisma migrate
is limited because this means that any resources created during the migrations are not owned by the permanent role.
Suggested solutions
Setup a method to execute such procedure prior to running the migrations.
This could be done through a statically defined SQL query/queries in the prisma schema or an environment variable.
It could also be done through a callback function which would pass the prisma client instance as an argument.
Alternatives
Our current “hack” is to run the following after prisma has finished running migrations:
REASSIGN OWNED BY CURRENT_USER TO "permanent-role-name";
But that is not fail-safe, as the service could die right after applying migrations but just before running this step.
Additional context
I do not believe such a feature should take too long to implement, and, given the proper guidance, I would be open to submitting a PR.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Update: We’ve managed to find a workaround, so for anyone having the exact same issue doing the following might be a solution:
Running this command for each temporary role makes postgres automatically run
SET ROLE
at the beginning of every session of the temporary role.I think this is still worth as tracking as a feature request.