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

Cannot exclude objects from "diff" #56

Closed
tkruemmel opened this issue Feb 1, 2019 · 1 comment
Closed

Cannot exclude objects from "diff" #56

tkruemmel opened this issue Feb 1, 2019 · 1 comment

Comments

@tkruemmel
Copy link

I wrote a custom gradle task, to use the diff command. I would like to exclude the tables where Liquibase stores its information from the "diff" command. Here is my code:
`task diffFixedDBvsEntities(type: JavaExec) {
group = "liquibase"

classpath sourceSets.main.runtimeClasspath
main = "liquibase.integration.commandline.Main"

args "--changeLogFile=" + '/home/tom/IdeaProjects/demoLiquibaseGit/src/main/resources/db.changelog/db.changelog-master.yaml'
args "--referenceUrl=" + "hibernate:spring:demoLiquibaseGit.domain.entity?dialect=org.hibernate.dialect.MySQL5Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
args "--username=" + "db"
args "--password=" + "db"
args "--url=" + "jdbc:mariadb://localhost:3306/db?useUnicode=yes&characterEncoding=UTF-8"
args "--referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver"
args "--classpath=src/main"
args "diff"
args "--diffExcludeObjects=table_DATABASECHANGELOG"

}`

And here is the error I am getting:
Unexpected error running Liquibase: Unknown option: 'diffExcludeObjects' liquibase.exception.CommandLineParsingException: Unknown option: 'diffExcludeObjects' at liquibase.integration.commandline.Main.parseOptionArgument(Main.java:818) at liquibase.integration.commandline.Main.parseOptions(Main.java:764) at liquibase.integration.commandline.Main.run(Main.java:177) at liquibase.integration.commandline.Main.main(Main.java:129)

I used the documentation for the maven task, because I thought this would be the way to go.

@stevesaliman
Copy link
Collaborator

Your custom task is actually completely separate from the Liquibase Gradle plugin. Your task uses JavaExec to run Liquibase as if you had run it from the command line. The best documentation to follow would be here: http://www.liquibase.org/documentation/command_line.html. If you want to keep your task the way it is, --diffExcludeObjects should become excludeObjects=DATABASECHANGELOG (if you're using the default table). This option is helpfully excluded from the official documentation...

There is another way that does use the plugin. You could have a liquibase block in your build.gradle that looks like this:

liquibase {
  activities {
    main {
      changeLogFile 'src/main/db/main.groovy'
      url project.ext.mainUrl
      username project.ext.mainUsername
      password project.ext.mainPassword
    }
    diffMain {
      changeLogFile 'src/main/resources/db.changelog/db.changelog-master.yaml'
      referenceUrl 'hibernate:spring:demoLiquibaseGit.domain.entity?dialect=org.hibernate.dialect.MySQL5Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
      username project.ext.mainUsername
      password  project.ext.mainPassword
      url 'jdbc:mariadb://localhost:3306/db?useUnicode=yes&characterEncoding=UTF-8'
      referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
      excludeObjects 'DATABASECHANGELOG'
    }
  }
  runList = project.ext.runList
}

You'd probably also want runList=main in gradle.properties so that by default it only runs normal Liquibase tasks. You could then run your diff with gradle diff -PrunList=diffMain

Two things to keep in mind:

  1. The method names inside an activity, like url or username are a direct match to the comnand line arguments of Liquibase.
  2. There is nothing special about activity names. I use main and diffMain but you can call them whatever you want, as long as you reference them correctly in the runList.

I hope this helps.

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

No branches or pull requests

2 participants