You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to set the spring.flyway.init-sqls property to run a little statement before Flyway does anything with the migration scripts, while re-using the spring.datasource.* properties for the Flyway connection. That doesn't seem to be straight-forward, however.
I have the following in my application.yml:
spring:
datasource:
url: <url>
username: <username>
password: <password>
flyway.init-sqls: SET ROLE '<username>'
Now, in FlywayAutoConfiguration.FlywayConfiguration there's a method that looks like this:
This is the only place where I can find any usage of spring.flyway.init-sqls, but I'm noticing that properties.isCreateDataSource() only returns true if spring.flyway.url or spring.flyway.user are defined. Therefore, the code that uses init-sqls is never reached.
Is this expected behavior? I would have expected that as long as spring.datasource.url or spring.datasource.username is set, it's not necessary to also define spring.flyway.url or spring.flyway.user. It appears to work when I do this:
spring:
datasource:
url: <url>
username: <username>
password: <password>
flyway:
init-sqls: SET ROLE '<username>'
url: ${spring.datasource.url}
I have a workaround for my case, but I'd like to hear if there's something I'm missing?
The text was updated successfully, but these errors were encountered:
Thanks for the report. When Spring Boot's initSql support was added (in Spring Boot 1.1) we were using Flyway 3.0 where it was only possible to specify SQL to initialise a connection when configuring Flyway's data source using a url, username, and password, rather than a DataSource instance. This changed in Flyway 5.2 but we missed it.
I see no reason not to apply spring.flyway.init-sqls irrespective of how the DataSource is being configured. I think we should have done that when we upgraded to 5.2.
I'm trying to set the
spring.flyway.init-sqls
property to run a little statement before Flyway does anything with the migration scripts, while re-using thespring.datasource.*
properties for the Flyway connection. That doesn't seem to be straight-forward, however.I have the following in my application.yml:
Now, in
FlywayAutoConfiguration.FlywayConfiguration
there's a method that looks like this:This is the only place where I can find any usage of
spring.flyway.init-sqls
, but I'm noticing thatproperties.isCreateDataSource()
only returnstrue
ifspring.flyway.url
orspring.flyway.user
are defined. Therefore, the code that usesinit-sqls
is never reached.Is this expected behavior? I would have expected that as long as
spring.datasource.url
orspring.datasource.username
is set, it's not necessary to also definespring.flyway.url
orspring.flyway.user
. It appears to work when I do this:I have a workaround for my case, but I'd like to hear if there's something I'm missing?
The text was updated successfully, but these errors were encountered: