Skip to content

Conversation

@eddumelendez
Copy link
Contributor

flyway.locations supports vendor resolution. But, if
flyway.check-location=true is added and there is just one location
with vendor location the current implementation fails. This commit adds
validation for vendor locations.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 23, 2017
@eddumelendez eddumelendez force-pushed the flyway_check_vendor_locations branch from 238a1ed to 5ef5685 Compare September 23, 2017 05:38
Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @eddumelendez

I don't understand why the code was moved to a separate auto-configuration. Can you expand on that please? I am not sure checking vendor location's location is a good thing. You may run your upgrades on a database that do not need a vendor specific script, in which case using the regular one only would make perfect sense?

Perhaps @vpavic has an opinion about that?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Sep 29, 2017
@eddumelendez
Copy link
Contributor Author

I don't understand why the code was moved to a separate auto-configuration. Can you expand on that please?

At the beginning I thought that previous validation (FlywayValidatorAutoConfiguration) would be right but in the process I just realized that if I am using the almost the same datasource configuration for Flyway I should throw a BeanCreationException maybe in the same class FlywayAutoConfiguration. I can rework this if we agreed to merge it.

I am not sure checking vendor location's location is a good thing.

Of course this is not required, we can use the default configuration o a custom one without need for vendor location. But, since this feature about resolve {vendor} was added, if users want to handle scripts just by vendors I think a proper validation for scripts location would be useful.

@snicoll
Copy link
Member

snicoll commented Oct 1, 2017

if users want to handle scripts just by vendors I think a proper validation for scripts location would be useful.

Yes but the problem is that you're not providing a path in your configuration, you are providing a placeholder that's going to be replaced with the database that you are using. If you are using two databases and one of them does not need specific scripts, the startup will fail because the directory does not exist. It means that the use case of this feature is quite narrowed IMO: all the databases that you support must require database specific scripts.

Does that make sense?

@vpavic
Copy link
Contributor

vpavic commented Oct 1, 2017

Thanks for the ping @snicoll.

If you are using two databases and one of them does not need specific scripts, the startup will fail because the directory does not exist.

Unless I'm missing something from the scenario you're describing, there shouldn't be a problem like this since the location validation is still based on finding at least one match in provided locations. The only difference is that the location under validation are now having {vendor} placeholder replaced with an actual value. So having something like flyway.locations=classpath:db/migration/common,classpath:db/migration/{vendor} shouldn't run into problems when running for vendor that doesn't have a specific migration, right? OTOH with only flyway.locations=classpath:db/migration/{vendor} this provides validation capabilities that are currently not possible.

@vpavic
Copy link
Contributor

vpavic commented Nov 6, 2017

If one uses only vendor specific locations things are currently broken by default in 2.0.0.M6 due to #10807 being merged. So IMO either this needs to be addressed or #10807 need to be reverted.

I've just faced this problem while upgrading from 2.0.0.M5 to 2.0.0.M6 with spring.flyway.locations set to db/migration/{vendor}. Initialization fails with:

java.lang.IllegalStateException: Cannot find migrations location in: [db/migration/{vendor}] (please add migrations or check your Flyway configuration)

Setting spring.flyway.check-location to false works around the problem but it's not the greatest user experience.

@wilkinsona wilkinsona added this to the 2.0.0.RC1 milestone Nov 6, 2017
@wilkinsona wilkinsona added for: merge-with-amendments Needs some changes when we merge priority: normal type: enhancement A general enhancement and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Nov 6, 2017
@wilkinsona
Copy link
Member

@eddumelendez It looks like me like the code may be simpler if the validation was performed during the creation of the Flyway bean. That would provide a single place for both replacing the {vendor} placeholder and for validating that at least one of the locations exists. It would also remove the need for the SpringBootFlyway subclass. What do you think?

@eddumelendez
Copy link
Contributor Author

@wilkinsona I will rework this later today 😉

@eddumelendez eddumelendez force-pushed the flyway_check_vendor_locations branch from 5ef5685 to 2ad12fd Compare November 8, 2017 07:00
@eddumelendez eddumelendez changed the base branch from 1.5.x to master November 8, 2017 07:01
private Flyway createFlyway() {
Flyway flyway = new Flyway() {
@Override
public void setLocations(String... locations) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wilkinsona I'm doing so because @ ConfigurationProperties is overriding the value. May the SpringBootFlyway class approach looks better? WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. Of course. I'd forgotten that we still bind directly to the Flyway instance. You're right. Let's keep the SpringBootFlyway class please.

`flyway.locations` supports vendor resolution. But, if
`flyway.check-location=true` is added and there is just one location
with vendor location the current implementation fails. This commit adds
validation for vendor locations.
@eddumelendez eddumelendez force-pushed the flyway_check_vendor_locations branch from 2ad12fd to be93635 Compare November 11, 2017 19:07
philwebb pushed a commit that referenced this pull request Nov 19, 2017
Update location check logic triggered if `flyway.check-location=true`
to resolve any vendor placeholders in `flyway.locations`.

See gh-10387
@philwebb philwebb closed this in 72862b5 Nov 19, 2017
philwebb added a commit that referenced this pull request Nov 19, 2017
…ions

* pr/10387:
  Polish location check with vendor placeholder
  Support location check with vendor placeholder
@philwebb
Copy link
Member

Thanks for updates. I've extracted the resolve logic into its own class and pushed this to master.

philwebb added a commit that referenced this pull request Nov 19, 2017
Fix public constructor accidentally added in commit 72862b5.

See gh-10387
@eddumelendez eddumelendez deleted the flyway_check_vendor_locations branch January 17, 2018 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for: merge-with-amendments Needs some changes when we merge type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants