Skip to content

darkMechanicum/liquikotlin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Liquikotlin

Kotlin DSL for liquibase.

TL;DR

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.

Description

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).

Links

  1. https://github.com/liquibase/liquibase-groovy-dsl
  2. https://github.com/gradle/kotlin-dsl