-
Notifications
You must be signed in to change notification settings - Fork 39
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
Prevent compile task being triggered prior to a flyway task being run #10
Comments
I think |
This is a tricky one. If I change it to something like |
The |
I think the only solution is to enable flyway on a different project. |
I had a similar issue and creating a separate sub-project seems to be a good option - e.g.
Then you can set up a task to run whichever flyway tasks you need in the top level project - this is to run the flyway clean and migrate tasks on compile for example:
|
@nafg has a plan that I have been dreaming about. Check where the actual migration is and select the classpath "mode" accordingly. But after I get some updates done. |
@stevewillcock has a great interim solution that will work for many use cases. Perhaps I can stick that in the docs? |
Wait what? All I said is that separate subprojects are demonstrably necessary to prevent a logical dependency cycle. That's what @stevewillcock said too, adding that you can also write a custom task for convenience. Personally I don't bother, it's easy enough to have the root project aggregate it and access the task that way, or else just use the subprojects prefix, for example you can run |
The cycle is that code migrations can depend on application code, but application code can depend on generated code, which depends on the database, which depends on migrations, which include code migrations. The only way out of it is that any code migrations have to be upstream of the generated code. Even SQL migrations are an issue because at runtime they are not read from their source location -- the runtime classpath is elsewhere, and typically resources are copied there as part of the compile step. The only other option is that during development, it could read SQL migrations from a file location based on the sbt resource directory setting. |
How about the solution in #33? I also added a test for it. |
Many flyway users also generate code from the schema. They have to take care to "Prevent compile task being triggered prior to a flyway task being run sbt#10" Adapted the example in the readme accordingly, so that many can avoid this pitfall.
SBT insists on compiling sources when running a flyway task. This is problematic for people who use code generators such as Slick and can mean a simple operation like flywayClean being very slow due to the compilation that gets triggered. I am really not sure why SBT is triggering the compile or how to prevent it. Ideas welcome.
The text was updated successfully, but these errors were encountered: