5
I’m just getting started with the Flyway
in the Java
along with the Spring Boot
and I currently have an activity that tells me to do the Flyway
execute the migrate()
only when a certain endpoint is executed and with the database properties (Url, user, password) that is sent.
The problem is, the Flyway
is currently running the migrate()
when the project gives startup and with the properties of datasource
which I specify in the file application.properties
, I took a look at the Docs from Spring Boot
and saw that to create a class that implements the FlywayMigrationStrategy
which gives me greater control over the Flyway
but it’s still not what I want, I still can’t, for example, call a method by passing a parameter to specify the datasource
of the database and that method migrate()
with the datasource
that I passed by parameter.
I’ve looked in many places, Spring Boot and Flyway for example, but I couldn’t find the answer, someone can give me a light?
Edit 1:
I managed to execute the migrate()
creating a variable of the type ClassicConfiguration
and setting the datasource
on it and then using the object constructor Flyway
passing the ClassicConfiguration
as parameter and passing this object Flyway
as a parameter for the migrate()
.
Only I’m having a problem that I can’t run my project Spring Boot
without a datasource
configured by a class @Configuration
of Java
or by file application.properties
.
The intention is for him to execute the project and do the migrate()
only when a specific endpoint is executed (the endpoint in question would execute the migrate()
with the parameters for connection to the database of the endpoint itself), and so soon after save the datasource
that was used in the migrate()
in the session so that the same user can make other requests without problems. It would be an application multi-tenacy
.
right buddy, it worked, but now, as I call the method
migrate()
passing thedatasource
per parameter?– Bruno Eduardo
You want to run Migration by passing which parameters?
– nullptr
the parameters of an object
Datasource
-Url -Password -User– Bruno Eduardo
@Brunoeduardo edited the answer
– nullptr
Okay, buddy, I think I got it and I’m going to try to do this tomorrow because I’m running out of time, but so, I was able to do something similar (I even edited the question explaining that upstairs) only that I had some problems, I couldn’t run the project without a configured initial datasource, until I was able to run the
migrate()
by endpoint put the next request I do that needs to make a connection to the error bank saying that thedatasource
not configured, if you can help me with that I would appreciate very friend.– Bruno Eduardo
To move up the project without datasource you need to disable autoconfiguration, but this is already the subject of another question :) I think your original question was answered only with the
spring.flyway.enabled=false
– nullptr
in fact it was answered in parts, let’s say that it does not matter if I manage to execute the project without flyway executing migrate() if the project does not execute, and also I’ve seen a question like this here in stackoverflow even about disabling autoconfiguration using exclude to not run the datasource Autoconfiguration class, only that doing so gives an error in Jdbctemplate that I use here, but I have to do some more research on that
– Bruno Eduardo
but still it was worth for giving me a north friend
– Bruno Eduardo