diff options
Diffstat (limited to 'src/db.erl')
-rw-r--r-- | src/db.erl | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -12,27 +12,30 @@ code_change/3]). -include_lib("stdlib/include/qlc.hrl"). +-include("db.hrl"). -include("plop.hrl"). %% @doc Set up a database schema on all nodes that are to be included %% in the "database cluster". Has to be run _before_ mnesia has been %% started. init_db() -> - init_db([]). + init_db([node()]). init_db(Nodes) -> - mnesia:create_schema([node()] ++ Nodes), - init_tables(Nodes). + ok = mnesia:create_schema(Nodes), + rpc:multicall(Nodes, application, start, [mnesia]), + init_tables(Nodes), + rpc:multicall(Nodes, application, stop, [mnesia]). %% @doc Run once, or rather every time you start on a new database. %% If run more than once, we'll get {aborted, {already_exists, TABLE}}. init_tables() -> - init_tables([]). + init_tables([node()]). init_tables(Nodes) -> %% We've once upon a time invoked mnesia:create_schema/1 with the %% nodes that will be part of the database. RamCopies = [], DiscCopies = [], - DiscOnlyCopies = [node()] ++ Nodes, + DiscOnlyCopies = Nodes, mnesia:start(), mnesia:create_table(plop, [{type, set}, {ram_copies, RamCopies}, @@ -48,7 +51,8 @@ dump_to_file(Filename) -> mnesia:dump_to_textfile(Filename). init(_Args) -> - {ok, []}. % TODO: return state + {mnesia:wait_for_tables([plop], 5000), + []}. start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). |