liquibase / liquibase-gradle-plugin

A Gradle plugin for Liquibase
Other
200 stars 59 forks source link

Pass defaultSchemaName via command line #48

Closed snebjorn closed 5 years ago

snebjorn commented 5 years ago

I'm trying to pass --defaultSchemaName=FOO via the command line.

How do I do that?

I tried

None work and the docs doesn't seem to explain how to pass args :(

stevesaliman commented 5 years ago

There are a couple of ways to tell Liquibase the default schema name you want. The plugin does it with a method in the activity of the liquibase block of build.gradle, where any method is assumed to be a command line argument to Liquibase. You can then use Gradle properties to alter the behavior from build to build.

If the default schema name is the same in all builds, you can use something like the following with no need for Gradle properties:

liquibase {
  activities {
    main {
      changeLogFile 'src/main/db/main.groovy'
      defaultSchemaName 'FOO'
      url project.ext.mainUrl
      username project.ext.username
      password project.ext.password
    }
  }
}

If the default schema name could change from build to build, you could invoke Gradle with -PdefaultSchemaName=FOO and use a liquibase block like this:

liquibase {
  activities {
    main {
      changeLogFile 'src/main/db/main.groovy'
      defaultSchemaName project.ext.defaultSchemaName
      url project.ext.mainUrl
      username project.ext.username
      password project.ext.password
    }
  }
}

If the option only needs to be there some of the time, you could do something like this:

liquibase {
  activities {
    main {
      changeLogFile 'src/main/db/main.groovy'
      url project.ext.mainUrl
      username project.ext.mainUsername
      password project.ext.mainPassword
      if ( project.ext.defaultSchemaName ) {
        defaultSchemaName project.ext.defaultSchemaName
      }
    }
  }
}

Then the schema name would only be sent to Liquibase when -PdefaultSchemaName=FOO was part of the Gradle command.

Note that the Gradle property can be named anything. You could use -PschemaName=FOO and it would work just fine as long as it matches the project.ext property used as the argument of the defaultSchemaName method of the activity.