Giter Site home page Giter Site logo

paulkagiri / harmonica Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kenjiohtsuka/harmonica

0.0 0.0 0.0 896 KB

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

License: GNU General Public License v3.0

Kotlin 100.00%

harmonica's Introduction

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 and SQLite.

Overview

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.
        addBooleanColumn(
            "table_name", "added_boolean",
            default = true, nullable = false
        )
        addIntegerColumn(
            "table_name", "added_integer", nullable = false
        )
        addDecimalColumn("table_name", "added_decimal_column_name")
        addVarcharColumn(
            "table_name", "added_boolean_column_name",
            default = "default", nullable = false
        )
        addTextColumn("table_name", "added_text_column_name")
        addDateColumn(
            "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")
        dropTable("table_name")
    }
}

Usage, Command

Caution

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.

Contribute

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

Links

Test Project

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

harmonica's People

Contributors

kenjiohtsuka avatar tumugin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.