Kotlin: Database Migration – Harmonica 1.0.1


Here, I announce the new release of Kotlin db migration library, Harmonica 1.0.1.

You can see the code in GitHub.

New Feature

Execute migration after compilation

Before, it reads migration script as Kotlin script and execute it. This time, I added new Gradle tasks, jarmonicaCreate, jarmonicaUp, jarmonicaDown. Those tasks compile Kotlin code as an application, first, and execute the migration.

In new tasks, db connection is handled better than before commands.

Of course you can use old commands, harmonicaUp, harmonicaDown, harmonicaCreate.

How to use

build.gradle

To use new commands, build.gradle must be changed than before.

Plugin preparation
Add dependency in build script dependency and apply the plugin jarmonica
Dependency for compilation
Add some library to dependencies for compilation. If you want to use Exposed, add it, too.

Directory Structure

Set up directory structure. This part is the same as before.

Database Configuration

Put the class Default.

Create Migration

You can create new migration with the following command.

If you want to specify the migration name, use migrationName property.

Then you can see the new migration file as follows.

Migrate Up and Down

Now you can execute migration.

Up

Down

Warning

I checked the library with PostgreSQL. Not with MySQL.