diff options
author | Linus Nordberg <linus@nordu.net> | 2014-04-30 14:24:35 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2014-04-30 14:24:35 +0200 |
commit | 2abe2e5ef5f0bfa1ce526055cbb4ee64e075eea3 (patch) | |
tree | 1baf12b17d9591cda15ccfcd12b0e6c0b9c4ef7b /src/db.erl | |
parent | 7c5a0789ba80f890c868e81b981315dd53e9dd94 (diff) |
Add init functions, for testing.
Diffstat (limited to 'src/db.erl')
-rw-r--r-- | src/db.erl | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -2,7 +2,8 @@ -behaviour(gen_server). %% API. --export([start_link/0, stop/0, init_tables/0]). +-export([start_link/0, stop/0]). +-export([init_db/0, init_db/1, init_tables/0, init_tables/1]). -export([add/1, find/1]). %% API for testing. -export([dump/1, destroy_tables/0, info_tables/0, dump_to_file/1]). @@ -13,14 +14,25 @@ -include_lib("stdlib/include/qlc.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(Nodes) -> + mnesia:create_schema([node()] ++ Nodes), + init_tables(Nodes). + %% @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(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()], + DiscOnlyCopies = [node()] ++ Nodes, mnesia:start(), mnesia:create_table(plop, [{type, set}, {ram_copies, RamCopies}, |