rebar3_kura
Rebar3 plugin for Kura — auto-generates migration files from schema changes and bootstraps new projects.
Installation
Add the plugin to your rebar.config:
{project_plugins, [
{rebar3_kura, "~> 0.4"}
]}.
{provider_hooks, [
{pre, [{compile, {kura, compile}}]}
]}.Commands
rebar3 kura compile
Runs automatically as a pre-compile hook. Diffs your kura_schema modules against existing migrations and generates new migration files when changes are detected.
$ rebar3 compile
===> kura: generated src/migrations/m20260214120000_create_pets.erlrebar3 kura setup
Bootstraps Kura in a new project:
$ rebar3 kura setup
$ rebar3 kura setup --name my_db # custom repo module nameThis will:
- Check that kura is in your deps
-
Generate a repo module (
APPNAME_repo.erl) with allkura_repo_workerwrappers -
Create the
src/migrations/directory - Check that the provider hook is configured
- Print remaining manual setup steps
Auto-migration
The pre-compile hook detects:
- New tables — schema exists, no migration history
- Added columns — field in schema, not in migration history
- Dropped columns — column in migration history, not in schema
- Type changes — same column name, different type
It does not auto-generate:
drop_tableoperations (destructive — write manually)- Nullable-only changes
- Default value changes
- Primary key changes
Enum handling
Enum fields ({enum, [atom()]}) map to VARCHAR(255). Changing the enum value list doesn't trigger a migration since the underlying column type is unchanged.
How it works
-
Change a schema (e.g., add a field to
pet.erl) -
Run
rebar3 compile - The pre-compile hook diffs schemas against existing migrations
-
If changes are detected, a new migration
.erlfile is generated insrc/migrations/ - The main compile step compiles everything including the new migration
-
Next
rebar3 compile— no diff, no new migration (idempotent)
License
MIT