From a586545a2f140c4557fd3636a6e2647fa93d5c95 Mon Sep 17 00:00:00 2001 From: Christopher Phillips Date: Fri, 22 Nov 2013 12:15:18 -0500 Subject: [PATCH] Changing out to use a locally implemented ensure_started rather than be reliant on 16B01 OTP --- src/migresia.erl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/migresia.erl b/src/migresia.erl index 8dfc74a..4635797 100644 --- a/src/migresia.erl +++ b/src/migresia.erl @@ -24,7 +24,7 @@ -module(migresia). --export([create_new_migration/2, check/1, migrate/1, list_nodes/0]). +-export([create_new_migration/2, check/1, migrate/1, list_nodes/0, ensure_started/1]). -define(TABLE, schema_migrations). @@ -77,12 +77,12 @@ execute_up({Module, Short}) -> -spec start_mnesia(boolean()) -> ok | {error, any()}. start_mnesia(RemoteToo) -> io:format("Starting Mnesia...~n", []), - case application:ensure_started(mnesia) of + case ensure_started(mnesia) of Other when Other /= ok -> io:format(" => Error:~p~n", [Other]), Other; ok -> case RemoteToo of false -> ok; - true -> {ResultList, BadNodes} = rpc:multicall(list_nodes(), application, ensure_started, [mnesia]), + true -> {ResultList, BadNodes} = rpc:multicall(list_nodes(), migresia, ensure_started, [mnesia]), BadStatuses = [X || X <- ResultList, X /= ok], if BadNodes /= [] -> io:format(" => Error:~p~n", [not_all_nodes_running]), {error, not_all_nodes_running}; BadStatuses /= [] -> io:format(" => Error:~p~n", [BadStatuses]), {error, BadStatuses}; @@ -92,4 +92,12 @@ start_mnesia(RemoteToo) -> end. list_nodes() -> - mnesia:table_info(schema, disc_copies). \ No newline at end of file + mnesia:table_info(schema, disc_copies). + +-spec ensure_started(atom()) -> ok | {error, any()}. +ensure_started(App) -> + case application:start(App) of + ok -> ok; + {error,{already_started,App}} -> ok; + A -> A + end. \ No newline at end of file