Current section
Files
Jump to
Current section
Files
src/migrant@lib.erl
-module(migrant@lib).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/migrant/lib.gleam").
-export([get_or_make_migration/3, validate_direction/2]).
-file("src/migrant/lib.gleam", 7).
-spec get_or_make_migration(
binary(),
gleam@dict:dict(binary(), migrant@types:migration()),
fun((migrant@types:migration()) -> {ok,
{binary(), migrant@types:migration()}} |
{error, migrant@types:error()})
) -> {ok, {binary(), migrant@types:migration()}} |
{error, migrant@types:error()}.
get_or_make_migration(Name, Migrations, Next) ->
case gleam_stdlib:map_get(Migrations, Name) of
{ok, Migration} ->
Next(Migration);
{error, _} ->
Next({migration, none, none})
end.
-file("src/migrant/lib.gleam", 18).
-spec validate_direction(
binary(),
fun((binary()) -> {ok, {binary(), migrant@types:migration()}} |
{error, migrant@types:error()})
) -> {ok, {binary(), migrant@types:migration()}} |
{error, migrant@types:error()}.
validate_direction(Direction, Next) ->
case Direction of
<<"up"/utf8>> ->
Next(<<"up"/utf8>>);
<<"down"/utf8>> ->
Next(<<"down"/utf8>>);
_ ->
{error,
{filename_error,
<<"Expected format <migraton_name>.<up/down>.sql"/utf8>>}}
end.