mirror of
https://github.com/UzixLS/migresia.git
synced 2025-07-19 07:11:28 +03:00
Refactor to use precompiled migrations.
This commit is contained in:
@ -25,16 +25,13 @@
|
||||
-module(migresia).
|
||||
|
||||
-export([start_all_mnesia/0,
|
||||
list_nodes/0,
|
||||
list_migrations/0,
|
||||
ensure_started/1,
|
||||
check/1,
|
||||
migrate/0,
|
||||
migrate/1,
|
||||
rollback/1,
|
||||
rollback/2,
|
||||
rollback_last/0,
|
||||
rollback_last/1]).
|
||||
list_nodes/0,
|
||||
list_migrations/0,
|
||||
ensure_started/1,
|
||||
check/1,
|
||||
migrate/1,
|
||||
rollback/2,
|
||||
rollback_last/1]).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
@ -49,7 +46,7 @@ start_all_mnesia() ->
|
||||
Err
|
||||
end.
|
||||
|
||||
list_nodes() ->
|
||||
list_nodes() ->
|
||||
mnesia:table_info(schema, disc_copies).
|
||||
|
||||
list_migrations() ->
|
||||
@ -68,7 +65,7 @@ handle_err(Results, Bad) ->
|
||||
if Bad /= [] -> io:format(" => Error, bad nodes: ~p~n", [Bad]) end,
|
||||
{error, mnesia_not_started}.
|
||||
|
||||
-spec ensure_started(atom()) -> ok | {error, any()}.
|
||||
-spec ensure_started(atom()) -> ok | {error, any()}.
|
||||
ensure_started(App) ->
|
||||
case application:start(App) of
|
||||
ok -> ok;
|
||||
@ -88,14 +85,10 @@ check(App) ->
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
-type migration_dir() :: default | file:filename().
|
||||
-type migration_dir() :: file:filename().
|
||||
-type migration_source() :: atom() | {rel_relative_dir, migration_dir()}.
|
||||
-type migration_sources() :: migration_source(). %% | [migration_source()].
|
||||
|
||||
-spec migrate() -> ok | {error, any()}.
|
||||
migrate() ->
|
||||
migrate({rel_relative_dir, default}).
|
||||
|
||||
-spec migrate(migration_sources()) -> ok | {error, any()}.
|
||||
migrate(Srcs) ->
|
||||
try
|
||||
@ -121,10 +114,6 @@ apply_ups(Srcs, Loaded) ->
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
-spec rollback(integer()) -> ok | {error, any()}.
|
||||
rollback(Time) ->
|
||||
rollback({rel_relative_dir, default}, Time).
|
||||
|
||||
-spec rollback(migration_sources(), integer()) -> ok | {error, any()}.
|
||||
rollback(Srcs, Time) ->
|
||||
try
|
||||
@ -148,10 +137,5 @@ apply_downs(Srcs, Loaded, Time) ->
|
||||
rpc:multicall(nodes(), migresia_migrations, list_applied_ups, [Srcs, Time]),
|
||||
lists:foreach(fun migresia_migrations:execute_down/1, Loaded).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
-spec rollback_last() -> ok | {error, any()}.
|
||||
rollback_last() -> rollback(migresia_migrations:get_ts_before_last()).
|
||||
|
||||
-spec rollback_last(migration_sources()) -> ok | {error, any()}.
|
||||
rollback_last(Srcs) -> rollback(Srcs, migresia_migrations:get_ts_before_last()).
|
||||
|
Reference in New Issue
Block a user