DB Migration Tool
in Kotlin
Kenji Otsuka
My Experience
I’ve been writing
server application
in Kotlin from 2016.
Basically, I use
Spring Boot framework
with Database.
Usually, web application uses Database such as , .
Common Server Structure
How do you set up the database?
Popular Migration Tool
Sometimes people use Flyway.
• I wanted to write Rails, Phinx, Laravel like migration.
Migration Sample in Rails
Write migration as code.
create_table, drop_table, change_table, add_index, …
Migration Sample in Phinx
Write migration as code.
table, addColumn, foreignKey, addIndex, …
I started to create db
migration tool in
Kotlin.
Features I had to create
• Execution from Gradle command
line
• gradlew migrateUp
• gradlew migrateDown
• gradlew createMigration
• Kotlin DSL
• createTable, createIndex, etc
What I created
https://github.com/KenjiOhtsuka/harmonica
How to use
Create Migration
gradlew jarmonicaCreate
override fun up() {
createTable("table_name") {
integer("column_1")
varchar("column_2")
}
}
override fun down() {
dropTable("table_name")
}
Migrate up
gradlew jarmonicaUp
> Task :jarmonicaUp
== [Start] Migrate up 20180624011127699 ==
Create Table: table_name
== [End] Migrate up 20180624011127699 ==
Compile the program, execute all the migration which
are not executed.
Migrate down
gradlew jarmonicaDown
> Task :jarmonicaDown
== [Start] Migrate down 20180624011127699 ==
Drop Table: table_name
== [End] Migrate down 20180624011127699 ==
Compile the program, migrate back the migration of
current version.
Migrate back only one migration.
Environment configuration
Here is Default class. If you define other class, such
as NotDefault, you can use it as follows.
gradlew jarmonicaUp –Penv=NotDefault
class Default: DbConfig({
dbms = Dbms.PostgreSQL
user = "developer"
password = "developer"
host = "127.0.0.1"
dbName = "harmonica_test"
})
Kotlin db migration tool

Kotlin db migration tool