Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using a different role before applying the migration #909

Open
Kjir opened this issue Mar 31, 2023 · 0 comments
Open

Support using a different role before applying the migration #909

Kjir opened this issue Mar 31, 2023 · 0 comments

Comments

@Kjir
Copy link

Kjir commented Mar 31, 2023

In the Postgres databases I manage, the privileges are managed through a set of roles, which cannot be used to login. Instead each login user is assigned roles and to perform the various operations you need to SET ROLE <admin_role> before.
My understanding is that this is a pretty common way to manage permissions in Postgres.

Unfortunately this is not compatible with migrate.

Ideally, there would be a -role <role> option, which would run SET ROLE <role> before performing any of the other queries.

One workaround is to specify SET ROLE <role> at the top of every migration file. This should work on the default schema, however it will fail if the queries are to be run on a different schema.

For example:

migrate -database "postgresql://user:<pwd>@postgres-db/mydb?search_path=some_schema" -path db/migrations  up
2023/03/31 14:42:02 error: sql: Scan error on column index 0, name "current_schema": converting NULL to string is unsupported in line 0: SELECT CURRENT_SCHEMA()

I do not know if other databases have similar concepts to manage permissions or if this problem only arises with Postgres.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant