Flyway: SET ROLE not respected in callbacks or initSqls

Created on 1 Jun 2017  路  2Comments  路  Source: flyway/flyway

What version of Flyway are you using?

4.1.2 or later

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin, SBT plugin, ANT tasks)

cli and Java

What database are you using (type & version)?

PG 9.6.2

What operating system are you using?

Linux

What did you do?

(Please include the content causing the issue, any relevant configuration settings, and the command you ran)

I have a beforeMigrate.sql that looks like this:

SET ROLE migration_user;

And then many regular migrations which need to be run as the user migration_user.

What did you expect to see?

I expect to see the entire migration session run as user migration_user, so that this role owns all of the created objects.

What did you see instead?

In fixing #1537, this RESET ROLE was added, which undoes the callback and any initSqls which use SET ROLE. I think this is unexpected.

PostgreSQL won't fix

Most helpful comment

beforeEachMigrate.sql does not seem to be executed before schema_version creation. How can I ensure schema_version is created by the given user?
It would be great if this statement was controlled with some configuration flag:
jdbcTemplate.execute("RESET ROLE");

All 2 comments

Place it in beforeEachMigrate.sql instead and it should work as expected.

beforeEachMigrate.sql does not seem to be executed before schema_version creation. How can I ensure schema_version is created by the given user?
It would be great if this statement was controlled with some configuration flag:
jdbcTemplate.execute("RESET ROLE");

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tarciosaraiva picture tarciosaraiva  路  3Comments

axelfontaine picture axelfontaine  路  4Comments

flyway picture flyway  路  4Comments

Omie picture Omie  路  4Comments

expeditioneer picture expeditioneer  路  4Comments