-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Ensure data.sql / schema.sql support is disabled automatically when using Flyway/Liquibase #22741
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
Comments
If this issue is open to community contribution, I'm available to work on it. |
@ThomasVitale Thanks very much for the offer. That'd be great, yes please. Let us know if you have any questions. |
@wilkinsona thank you and sorry for the late answer. I looked into the code and it seems that the Line 123 in 558c2b4
I thought about two possible solutions that I'd like to validate with you. |
@ThomasVitale Thanks for taking a look. I think, ideally, |
Good point! Both |
I agree that may not be the cleanest. I think we'd be in danger of duplicating the Flyway and Liquibase auto-configuration conditions in the DataSource initialization auto-configuration. The core team discussed this one yesterday and decided that it's something that should be tackled as part of a broader revamp of DataSource initialization that we'd like to do in 3.0. Thanks anyway for taking a look. |
I think there's a use-case which is being missed here. Both Flyway and Liquibase add some metadata tables for their own use into the database. If you want to control where these tables are located then there's a chicken-and-egg problem. So yes, users should not mix database population methods and it is good that the documentation now makes that clear. However, for the reason mentioned above user may have a legitimate need for executing some SQL code before Flyway or Liquibase kicks in. I think this can easily be added as a feature on both Flyway and Liquibase autoconfiguration. For example I'm imagining that the Liquibase autoconfiguration would be looking for files For example, my -- Create application schema
CREATE SCHEMA IF NOT EXISTS medusa; and I would then set property: spring.liquibase.default-schema=medusa If I wanted to separate application tables from Liquibase meta-tables (wouldn't recommend it), I would then have my -- Create application schema
CREATE SCHEMA IF NOT EXISTS medusa;
CREATE SCHEMA IF NOT EXISTS medusa_meta; and properties set as: spring.liquibase.default-schema=medusa
spring.liquibase.liquibase-schema=medusa_meta In recap: There's a legitimate need to be able to execute some SQL code before Flyway or Liquibase. Such feature would be trivial to implement but I advocate it should part of Flyway / Liquibase autoconfiguration rather than trying to squeeze it into the general DataSource initialization. If such "pre" feature existed on Flyway / Liquibase autoconfiguration then it would be safe for Spring Boot to force Having this "pre" feature on Flyway / Liquibase autoconfiguration would also enable some use-cases where the same database (catalog) is being used for different test environments... which I would say is quite common. The only way to separate such environments would be by using different schemas but then that necessitates the ability to ensure the schema exist prior to executing Flyway / Liquibase. |
Assuming I have understood your use case correctly, it is already supported by Flyway: https://flywaydb.org/documentation/concepts/migrations.html#schema-creation. I think that within the database migration tool itself is the right place for this sort of functionality as it's applicable to anyone using Flyway not just those using Flyway with Spring Boot. |
@wilkinsona. Yes, I think you've understood correctly. Unfortunately I'm using using Liquibase, not Flyway, and wasn't aware of this feature in Flyway. There's no equivalent in Liquibase. Flyway has the "advantage" that it doesn't attempt to be database engine agnostic. Liquibase does indeed attempt to be database engine agnostic and such a feature would open a myriad of questions for them, AFAIU. I can see it has been discussed on several occasions in Liquibase Forum (Ref1, Ref2). It seems like Nathan, the original developer of Liquibase, would like to keep it "clean" and is therefore hesitant. I'll ponder a bit if I agree with you or not that it doesn't belong in Spring Boot. :-) I'll go back to thinking. |
In Flyway, you can also define callbacks (defined in SQL or Java) that let you hook into the Flyway lifecyle and execute specific procedures (for example, before the baseline migration is run or before automatically creating non-existent schemas). https://flywaydb.org/documentation/concepts/callbacks |
@ibrunn I am also working with Liquibase , did you find the solution for this problem? |
@itstannus : Yeah, my solution is the Pre-Liquibase Spring Boot module. But I think you already found it. :-) In a few words it is a Spring Boot autoconfig which essentially fires SQL scripts and guaranteed to execute before Spring Boot invokes Liquibase itself. |
See #20920 for background.
The text was updated successfully, but these errors were encountered: