harmonica - Kotlin Database Migration Tool. This tool makes it really easy to create table, index, add columns, and so on, with Kotlin DSL. - Kotlin Resources

Kotlin Database Migration Tool

License: GPL v3 Download CircleCI Twitter Follow

Gradle Plugin Page: https://plugins.gradle.org/plugin/com.improve_future.harmonica

This is Database Migration Tool, gradle plugin, made with Kotlin. It is made similar to Phinx, Rails.

Now, this tool is for PostgreSQL, MySQL, SQLite and Oracle Database.


With this library, you can write database migration like as follows.

package your.migration

import com.improve_future.harmonica.core.AbstractMigration

 * HolloWorld
class M20180624011127699_HolloWorld : AbstractMigration() {
    override fun up() {
        createTable("table_name") {
            // If you add the next line,
            // the migration doesn't create auto incremental id column.
            // id = false

            // You can easily define columns with their type name.
            boolean("boolean_column", nullable = false, default = true)
            integer("integer_column", default = 1)
            decimal("decimal_column", 5, 2, default = 3)
            varchar("varchar_column", size = 10, nullable = false)
            text("text_column", default = "default value")
            blob("blob_column", default = "abcde".toByteArray())
            date("date_column_1", default = "2019-01-01")
            date("date_column_2", default = Date())
            date("date_column_3", default = LocalDate.of(2018, 2, 2))
            time("time_column_1", default = "11:22:33")
            time("time_column_2", default = Date())
            time("time_column_3", default = LocalTime.now(), nullable = false)
            dateTime("date_tiem_column_1", default = "2011-11-12 12:34:56")
            dateTime("date_time_column_2", default = Date())
            dateTime("date_time_column_3", default = LocalDateTime.now())
            timestamp("timestamp_column_1", default = "2012-10-04 1:2:3")
            timestamp("timestamp_column_2", default = Date())
            timestamp("timestamp_column_3", default = LocalDateTime.now())

        // When you add column, `add*****Column` method works.
            "table_name", "added_boolean",
            default = true, nullable = false
            "table_name", "added_integer", nullable = false
        addDecimalColumn("table_name", "added_decimal_column_name")
            "table_name", "added_boolean_column_name",
            default = "default", nullable = false
        addTextColumn("table_name", "added_text_column_name")
            "table_name", "added_date",
            default = LocalDate.of(2018, 12, 11)

        // When you add index, use `addIndex`.
        createIndex("table_name", "column_name")

        // You can execute SQL directly.
        executeSql("SELECT 1;")

    override fun down() {
        dropIndex("table_name", "table_name_integer_column_idx")

Usage, Command


When you use harmonica, not jarmonica, sometimes it says “The connection has already been closed” and the migrations fail. Then, execute gradlew --stop to clear dead connections.


Pull requests are welcomed!! Please feel free to use it, and to contribute.

Test Project

Test with real database is in different repository, Harmonica Test.

compile "com.github.KenjiOhtsuka:harmonica:1.1.25"

Related Libraries


Strongly typed SQL in Kotlin

Last updated 3 mins ago


Fluent RxJava JDBC extension functions for Kotlin

Last updated 3 mins ago


SQLDelight - Generates typesafe Kotlin APIs from SQL

Last updated 3 mins ago


A handy Database access library in Kotlin

Last updated 3 mins ago


A framework designed around Kotlin providing a full-featured HTTP Framework, Restful HTTP Client, JDBC DSL, Loading Cache, Configurations, Validations, and more

Last updated 3 mins ago