/*
This document explains Groovy builder and how it can be leveraged to make life
with Liquibase a bit more fun.
Since a well-documented example is worth a shelf of books, here it is for you.
+-------------+
| MAIN SYNTAX |
+-------------+
*/
//
// Everything starts off with a database change log.
//
databaseChangeLog {
// Preconditions can be added in a precondition block.
// Note that precondition blocks are run in the reverse order from which
// they're added, and all precondition blocks -- no matter where they came
// from -- are executed before any changeSet block is executed.
preConditions {
// Some preconditions have nifty defaults, or you can use the implicit map
// syntax the same way you would use XML attributes.
dbms("mysql")
dbms(type:"mysql")
// "and", "or", and "not" are tags that take closures.
or {
sql("1", "select 1")
sql("0", "select 0")
}
}
// Another name for "preConditionds"
runIf {
runningAs("root") // Just another example
// Next line will search for MyCustomCheckPrecondition in
// "lbdsl.packages.pre" packages. In particular, this will look for a
// class named "MyCustomCheckPrecondition"
my-custom-check(arg1:"foo", arg2:"bar")
}
// Since we're in a Groovy file, you can do whatever Groovy stuff you'd like
def x = 42
println "Hey, I'm loading a file, and the answer is ${42}!"
include("anotherFile.txt") // Just like "anotherFile.txt" was copied into here
// ChangeSets don't need authors specified.
changeSet(1234) {
comment("This is a comment for this change set")
rawSQL(sql:"SELECT 1", comments:"These are the comments for that SQL")
}
// If you *really* want to specify an author, you can
changeSet(2345, "Robert Fischer") {
// A change is looked up by capitalizing, appending "Change",
// and looking through packages
createTable(tableName: "ExampleOneTable")
}
// You can use named arguments to set "alwaysRun", "runOnChange", "filePath",
// "context", and "dbms".
changeSet(3456, alwaysRun:true) {
createTable(tableName: "ExampleTwoTable") {
// In this closure, methods are delegated back to "createTable", so you
// can do whatever you'd like to mangle your class.
addColumn(new ColumnConfig(name: "tint", type: "tinyint"))
}
// Will go hunting for "MyCustomMagicChange" in the specified packages.
myCustomMagic(prop1:"Frodo", prop2:"Bilbo") {
// Unlike normal Liquibase, your custom change has just as much freedom as
// a built-in change. Here, we're calling myCustomMagic.doIt()
doIt()
}
}
}
/*
+------------+
| PROPERTIES |
+------------+
These are the properties that the Groovy builder uses, beyond those used by the core system.
* lbdsl.packages.change: Comma-delimited package to search when look up changes (a.k.a. refactorings) in order of priority. in this package The package "liquibase.change" will always be searched first.
e.g. lbdsl.packages.change=com.my.project.change.package1,com.my.projects.change.package2
* lbdsl.packages.pre: Comma-delimited packages to search when looking up preconditions in order of priority. The package "liquibase.preconditions" will always be searched last.
e.g. lbdsl.packages.pre=com.my.project.preconditions.package1,com.my.projects.preconditions.package2
* lbdsl.parser.suffix.*: Specifies that the suffix (given after "lbdsl.parser.suffix.") should map to the given parser class.
e.g. lbdsl.parser.suffix.foo=com.my.project.parser.AwesomeChangeLogParser
54,55-56 Boti*/