summaryrefslogtreecommitdiff
path: root/src/db.erl
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2014-05-01 18:02:31 +0200
committerLinus Nordberg <linus@nordu.net>2014-05-01 18:02:31 +0200
commit339656a35441a5d7d02282e6a5c6cdfeaf0571d6 (patch)
tree823cbe7f492c4c3f9bb8ffdc359ddefc1ffcb6e2 /src/db.erl
parent835638e11919d2012ab74bf5e3185732e604d0ff (diff)
Move some records out of public header file. Improve db initialisation some.
Wait for mnesia tables in init() and make the init-functions do some more.
Diffstat (limited to 'src/db.erl')
-rw-r--r--src/db.erl16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/db.erl b/src/db.erl
index b534757..857615c 100644
--- a/src/db.erl
+++ b/src/db.erl
@@ -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, [], []).