Kotlin: Database Migration – Harmonica 1.0.10


Here, I announce the new release of Harmonica, Kotlin database migration library. The version is 1.0.10.

In this article, gradlew command is written in Unix style but this tool can also be used in Windows OS. Of course I checked in Windows.

New Main Feature

It can be used for MySQL, too.

Before, it is not completely tested for MySQL. But now, it was tested and it can be used.

Decimal column is intoroduced.

Before, it can’t handle decimal column completely. Now we can use decimal column with precision and scale.

addColumn function.

addColumn function is introduced.

Seze of VARCHAR can be set.

Before, it couldn’t be set.

step parameter is introduced.

Before, jarmonicaUp executes all remain migrations and jarmonicaDown reverts only one migration. But now, step parameter can be used as follows and control migration more flexibly.

NOT NULL constraint can be added.

NOT NULL constraint can be added as follows.

DEFAULT keyword can be used.

DEFAULT keyword can be used as follows.

Fix migration package in the migration jarmonicaCreate creates.

Before, jarmonicaCreate creates migration file without package description and it can’t be executed by jarmonicaUp as it is.. Now, jarmonicaCreate insert package description into new migration and jarmonicaUp can use its package.

And there are some bug fixes.

How to Use

I will explain required configuration. Harmonica Test can be other example.

Set up build.gradle

Set up build.gradle as follows.

Some package such as “org.reflections.reflections” are required. In addition, you can use Exposed if you want.

Directory Structure

Set up directory structure.

Configuration File

Default.kt and other environment configuration file must be as follows.

If you want to use other database configuration file, use env parameter with Harmonica command (-Penv=OtherEnvironment).

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 get the following file.

Migrate Up or Down

Up

Migrate up with the command.

As default, all migration which are not executed will be executed. If you want to specify the number of migrations to be executed, use step parameter.

Down

If you want to revert migration, migrate down with the command.

As default, only one migration will be reverted. If you want to specify the number of migrations to be reverted, use step parameter.