View Source migraterl

built with nix Hex.pm Version

A simple forward-only migrations library for Erlang, inspired by DbUp.

Status

Pipeline

Builds

Integrations

Usage

Be aware that this project is a WIP, the API might change.

Assuming you plan to copy your migrations via overlays, like:

   {overlay, [
       {mkdir, "some_dir/migrations"},
       {copy, "some_dir/migrations/*", "\{\{output_dir\}\}/some_dir/migrations/"}
   ]}

Then you want to first fetch the directory from the release itself:

    % (...)
    % Asumming 'Module' is an atom pointing to your Module's name,
    % i.e. ?MODULE
    Dir = code:lib_dir(Module),
    % Or even something like this...
    {ok, AnotherDir} = file:get_cwd(),
    % Then append the actual migration path into the release's directory
    PathSuffix = ["some_dir", "migrations"],
    Path = filename:join([Dir | PathSuffix]),

    % Make sure to also have a connection setup, we only support epgsql for now,
    % the library comes with a default connection (for testing purposes only).
    Conn = migraterl:default_connection(),

    % You can Enable/Disable certain options
    Options = #{repeatable => false},
    
    % Now we can properly setup these migrations as part of our application
    % bootstrap process...
    ok = migraterl:migrate(Conn, Path, Options),

    % (...)

Development

We have devenv setup and everything is based on Nix, you can check our flake.nix to learn how it looks like.

nix develop --impure
# to spawn a postgres database
devenv up

there's also a justfile to manage builds and tests.

# will show all commands supported
just

Testing

# You can either run rebar directly
rebar3 ct
# or
just t

Inspiration