Skip to content
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

enabling loading of extenssions #36

Closed
wants to merge 1 commit into from
Closed

Conversation

amexboy
Copy link

@amexboy amexboy commented Sep 13, 2018

Unless there is a complex logic we need to do to parse the groovy change, we can look up the liquibases registry to find the appropriate change.

What I did was to look up the change in the methodMissing callback as that is the perfect place to look for it.

Also minor changes to the build file to enable publishing to mavenLocal

@amexboy amexboy mentioned this pull request Sep 13, 2018
@stevesaliman
Copy link
Collaborator

Thank you for the contribution. I'll take a look at it as soon as I get the chance.

I am curious about one thing: What does the maven-publish plugin do that we can't already do with gradlew install?

@amexboy
Copy link
Author

amexboy commented Sep 21, 2018

Thank you for the contribution. I'll take a look at it as soon as I get the chance.

I am curious about one thing: What does the maven-publish plugin do that we can't already do with gradlew install?

I couldn't figure out how to publish to my local maven. Should I remove?

@stevesaliman
Copy link
Collaborator

I had some time to take a deeper look at the code.

I really like the idea of getting changes from the registry. In fact, I think all changes should be fetched from the registry. This could be done easily enough by putting the registry lookup in its own helper and having all methods, including methodMissing use that helper. This would work for most use cases, but it does leave a couple of challenges...

First, how would we process external changes that have nested elements? The DSL represents nested elements as closures, but I can't think of any way to up a delegate for the closures in external changes. For now this could be a documented limitation since it lets us process more than we used to be able to handle.

Second, the new DSL code will ignore certain invalid change set code. For example,
addAutoIncrement(tableName: 'myTable') { def x = 4 } currently complains because a closure is not valid for the addAutoIncrement change, but the new code would not complain. I don't like this because the code should not report success if it doesn't do everything it was asked to do. I think I could work around that problem by having a list of changes that support closures and throwing an exception if a given change has a closure and isn't on the list.

There are a couple of other bugs in the DSL I need to look into, but then I can look into this further. I think we can make this work.

@amexboy
Copy link
Author

amexboy commented Oct 7, 2018 via email

@stevesaliman
Copy link
Collaborator

Here is what I think I want to do:

  1. Create a method that takes a change name and returns an instance of a change. The exact class would be looked up from the registry.

  2. Change all methods that currently instantiate a Change class to call this new helper method. This means that a lot of methods that sent or received Class arguments would be refactored to use a name instead.

  3. Change methodMissing to try to get a change from the registry. If it can't find one, or the arguments passed to methodMissing are more than just a map, then we could fail as before.

IMHO, I think when users put something in a changelog they intend for Liquibase to do something with it, and Liquibase should not report success if it didn't run everything the user intended.

I should have some time over the weekend to work on this.

@stevesaliman
Copy link
Collaborator

I've implemented this fix, and resolved a few other issues at the same time:

  1. I implemented a lookupChange method as discussed before.

  2. I changed makeColumnarChange and makeChangeFromMap to use the new method.

  3. I implemented a methodMissing method. It will only handle changes with no arguments, or a single map argument. Anything else will throw an exception to let users know that they've asked us to process a change we can't parse. I also fixed a bug that was causing errors in the way changes were added to a rollback.

  4. I eliminated all of the standard changes that take a single map and had no special processing. They can flow through methodMissing now.

  5. I fixed the test that was failing because of the unexpected debug output from the Liquibase registry lookup - I did it by adding a logback-test.xml file to send the output to stderr instead of stdout.

  6. I moved the sample extension from src/main to src/test so we weren't shipping it with the DSL, but we could still use it to test the processing of extension based changes.

The changes are pushed, but I want to look into a possible Spring Boot bug before I make a release.

@amexboy
Copy link
Author

amexboy commented Oct 15, 2018 via email

@stevesaliman
Copy link
Collaborator

I just released version 2.0.2 of the Groovy DSL with the changes that allow extension provided changes to be loaded. Thank you for all of your help on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants