Kotlin DSL for liquibase.
Inspired by liquibase groovy dsl and gradle kotlin dsl this library allows writing kotlin scripts instead of raw xml for liquibase.
Advantages are quite obvious, starting from more compact and IDE supported scripts to pure kotlin possibilities like extension functions.
Scripts are written in files with standard kotlin script extension kts
.
Entry point for each script is changelog variable.
Nested tags can be created via calling needed methods or by calling closures. These are equivalent:
changelog - {
changeset(1)
.createTable(
"table",
"id" to "number")
}
changelog
.changeset
.id(1)
.createTable
.tableName("table")
.column
.name("id")
.type("number")
Therefore extensions like minus function with closure as argument or createTable function that accepts table name and column pairs are not necessary but simplifies script coding.
Almost all of default extensions are located in
src\main\kotlin\com\tsarev\liquikotlin\extensions\extensions.kt
.
Note: Minus function is mplemented as 'core' function so it is protected member function.
Also, there is one feature except standard xml like DSL. At any place in the script default value can be set to any attribute (not children nodes) like this:
changelog.changeset.sql.splitStatements.setDefault(true)
changelog.changeset.sql.stripComments.setDefault(true)
changelog - {
changeset(5).sql - "select * from dual"
}
or this:
changelog - {
changeset.createTable.schemaName.setDefault("mySchema")
changeset(1).createTable("table", "id" to "number")
}
When default value is set all node declarations will have specified value set to default (value can be explicitly overridden) within closure (or globally if there is no closure).