question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom startup command for prisma client for migrations

See original GitHub issue

Problem

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:open
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
paulrostorpcommented, May 3, 2021

Update: We’ve managed to find a workaround, so for anyone having the exact same issue doing the following might be a solution:

ALTER ROLE CURRENT_USER SET ROLE "${process.env.POSTGRES_DATABASE_OWNER}";

Running this command for each temporary role makes postgres automatically run SET ROLE at the beginning of every session of the temporary role.

2reactions
janpiocommented, Apr 12, 2022

I think this is still worth as tracking as a feature request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma Migrate | Database, Schema, SQL Migration Tool
Prisma Migrate is a database migration tool available via the Prisma CLI that integrates with Prisma schema for data modeling.
Read more >
Developing with Prisma Migrate
This guide takes you through a typical development workflow with Prisma Migrate, from defining a schema to committing migrations to source control.
Read more >
Prisma CLI Command Reference
Create migrations from your Prisma schema, apply them to the database, ... It will then generate a customized Prisma Client for your project....
Read more >
Prisma Migrate is Production Ready - Hassle-Free Database ...
prisma db push : Creates the database schema based on the Prisma schema without any migrations. Intended for use while locally prototyping.
Read more >
Seeding your database - Prisma
You manually run the prisma migrate reset CLI command. · The database is reset interactively in the context of using prisma migrate dev...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found