Table of Contents
Kotlin のデータベースマイグレーションライブラリ Harmonica 1.0.1 をリリースしました。
You can see the code in GitHub.
新機能
- マイグレーションをコンパイル後に実行する
-
以前は Kotlin Script をマイグレーションのスクリプトとして読み込んで、 実行していました。バージョン 1.0.1 では 新しい Gradle のタスク
jarmonicaCreate
,jarmonicaUp
,jarmonicaDown
を追加し、 コンパイル後に Kotlin のマイグレーションコードを実行できるようにしています。In new tasks, db connection is handled better than before commands.
もちろん以前のコマンド
harmonicaUp
,harmonicaDown
,harmonicaCreate
も使用可能です。
使い方
build.gradle
新しいコマンドを使うには、 次のように build.gradle
を記述します。
- 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.
ディレクトリ構成
Set up directory structure. This part is the same as before.
データベース設定
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.
マイグレーション
Now you can execute migration.
Up
Down
注意
PostgreSQL ではテストをしていますが、 MySQL についてはテストを行なっていません。