<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -5,3 +5,5 @@ Mnesia.nonode@nohost/
 *.log
 #*#
 .#*
+twoorl.mnesia/
+twoorl_stats</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,6 @@
 {&quot;src/twoorl.erl&quot;, [{outdir, &quot;./ebin&quot;}]}.
+{&quot;src/twoorl_sup.erl&quot;, [{outdir, &quot;./ebin&quot;}]}.
+{&quot;src/twoorl_server.erl&quot;, [{outdir, &quot;./ebin&quot;}]}.
 {&quot;src/twoorl_util.erl&quot;, [{outdir, &quot;./ebin&quot;}]}.
 {&quot;elib/rfc4627/*&quot;, [{outdir, &quot;./ebin&quot;}]}.
 {&quot;elib/twitter_client/*&quot;, [{outdir, &quot;./ebin&quot;}]}.
\ No newline at end of file</diff>
      <filename>Emakefile</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,8 @@
 all: code
 
 code: clean
-	erl -s make all load -run twoorl init_mysql -run twoorl compile -s init stop
+	## erl -s make all load -run twoorl init_mysql -run twoorl compile -s init stop
+	erl -s make all load -s init stop
 
 clean:
 	rm -fv ebin/*.beam twoorl.rel twoorl.script twoorl.boot erl_crash.dump *.log *.access</diff>
      <filename>Makefile</filename>
    </modified>
    <modified>
      <diff>@@ -16,6 +16,6 @@ To run in embedded mode:
 $ make clean &amp;&amp; make &amp;&amp; make init
 $ erl -sname twoorlapp -setcookie twoorl -mnesia dir &quot;'twoorl.mnesia'&quot; -yaws embedded true -pa ebin -boot start_sasl
 1&gt; [application:start(X) || X &lt;- [inets, crypto, mnesia, twoorl]].
-2&gt; twoorl:start().
+[ok, ok, ok, ok]
 
 # Nick Gerakines</diff>
      <filename>README.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,14 +1,19 @@
 {application, twoorl, [
   {description, &quot;Twoorl is an open-source Twitter clone.&quot;},
   {vsn, &quot;0.3&quot;},
-  {modules, [
-    twoorl,
-    twoorl_server,
-    twoorl_sup
-  ]},
+  {modules, [twoorl, twoorl_server, twoorl_sup]},
   {registered, [twoorl]},
-  {env, []},
   {applications, [kernel, stdlib, sasl, crypto, inets, mnesia]},
   {mod, {twoorl, []}},
-  {start_phases, []}
+  {env, [
+    {dbconns, [
+        {&quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;, &quot;twoorl&quot;, 3}
+    ]},
+    {tables, [session]}
+  ]},
+  {start_phases, [
+    {mysql, []},
+    {mnesia, []},
+    {compile, []}
+  ]}
 ]}.</diff>
      <filename>ebin/twoorl.app</filename>
    </modified>
    <modified>
      <diff>@@ -26,13 +26,54 @@
 start(_Type, _Args) -&gt;
     twoorl_sup:start_link([]).
 
-start() -&gt;
-    application:start(inets),
-    init_mnesia(),
-    TablesInfo = [{session, [{attributes, record_info(fields, session)}]}],
-    create_mnesia_tables(TablesInfo),
-    init_mysql(),
-    compile().
+start_phase(mysql, _, _) -&gt;
+    {ok, DBConfig} = application:get_env(twoorl, dbconns),
+    [begin
+        mysql_connect(PoolSize, Hostname, User, Password, Database, true)
+    end || {Hostname, User, Password, Database, PoolSize} &lt;- DBConfig],
+    ok;
+
+start_phase(compile, _, _) -&gt;
+    twoorl:compile(),
+    ok;
+
+%% Having the mnesia store on a separate but connected node with a module
+%% to handle its maintenance would move a lot of this foo out of the
+%% application stack. Eventually that really needs to happen. -- nkg
+start_phase(mnesia, _, _) -&gt;
+    %% Mnesia should have been started already, because of that the schema
+    %% is in memory if the schema doesn't already exist on disc. If so we
+    %% change the type so that it writes to the mnesia dir we set. -- nkg
+    case mnesia:table_info(schema, storage_type) of
+        ram_copies -&gt; 
+            mnesia:change_table_copy_type(schema, node(), disc_copies);
+        _ -&gt;
+            ok
+    end,
+    ExistingTables = mnesia:system_info(tables) -- [schema],
+    {ok, Tables} = application:get_env(twoorl, tables),
+    [begin
+        create_table(session)
+    end || Table &lt;- Tables, not lists:member(Table, ExistingTables)],
+    ok.
+
+create_table(session) -&gt;
+    mnesia:create_table(session, [{attributes, record_info(fields, session)}]),
+    ok.
+
+mysql_connect(0, _, _, _, _, _) -&gt; ok;
+mysql_connect(PoolSize, Hostname, User, Password, Database, true) -&gt;
+    erlydb:start(mysql, [
+        {hostname, Hostname},
+        {username, User},
+        {password, Password},
+        {database, Database},
+        {logfun, fun twoorl_util:log/4}
+    ]),
+	mysql_connect(PoolSize - 1, Hostname, User, Password, Database, false);
+mysql_connect(PoolSize, Hostname, User, Password, Database, false) -&gt;
+    mysql:connect(erlydb_mysql, Hostname, undefined, User, Password, Database, true),
+    mysql_connect(PoolSize - 1, Hostname, User, Password, Database, false).
 
 compile() -&gt;
     compile([]).
@@ -44,15 +85,28 @@ compile_update() -&gt;
     compile([{last_compile_time, auto}]).
 
 compile(Opts) -&gt;
-    erlyweb:compile(compile_dir(auto),
+    erlyweb:compile(compile_dir(default),
 		    [{erlydb_driver, mysql}, {erlydb_timeout, 20000} | Opts]).
 
+compile_dir(auto) -&gt;
+    {ok, CWD} = file:get_cwd(), CWD;
+compile_dir(default) -&gt;
+    ?APP_PATH;
+compile_dir(appconfig) -&gt;
+    {ok, CDir} = application:get_env(twoorl, compile_dir),
+    CDir;
 compile_dir(Dir) -&gt;
-    case Dir of
-        auto -&gt; {ok, CWD} = file:get_cwd(), CWD;
-        default -&gt; ?APP_PATH;
-        _ -&gt; Dir
-    end.
+    Dir.
+
+%% --- The rest of these functions will be deprecated --- %%
+
+start() -&gt;
+    application:start(inets),
+    init_mnesia(),
+    TablesInfo = [{session, [{attributes, record_info(fields, session)}]}],
+    create_mnesia_tables(TablesInfo),
+    init_mysql(),
+    compile().
 
 init_mnesia() -&gt;
     ?L(&quot;creating schema&quot;),
@@ -98,7 +152,6 @@ create_table(Table, Def) -&gt;
             exit(Err2)
     end.
 
-
 init_mysql() -&gt;
     erlydb:start(mysql,
 		 [{hostname, ?DB_HOSTNAME},</diff>
      <filename>src/twoorl.erl</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 %% We really need to move this stuff out of this file -- nkg.
 -define(DB_HOSTNAME, &quot;localhost&quot;).
 -define(DB_USERNAME, &quot;root&quot;).
--define(DB_PASSWORD, &quot;asd123&quot;).
+-define(DB_PASSWORD, &quot;password&quot;).
 -define(DB_DATABASE, &quot;twoorl&quot;).
 -define(DB_POOL_SIZE, 50).
 %-define(APP_PATH, &quot;/home/yariv/apps//twoorl&quot;).</diff>
      <filename>src/twoorl_app.hrl</filename>
    </modified>
    <modified>
      <diff>@@ -28,5 +28,5 @@ start_link(Args) -&gt;
 
 init(Args) -&gt;
     {ok, {{one_for_one, 10, 10}, [
-        {twoorl_yaws, {twoorl_server, start_link, [Args]}, permanent, 2000, worker, [twoorl_server]}
+        {twoorl_yaws, {twoorl_server, start_link, [Args]}, permanent, 20000, worker, [twoorl_server]}
     ]}}.</diff>
      <filename>src/twoorl_sup.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>61eccf7d6389c3c505210c943fe7406883f188c6</id>
    </parent>
  </parents>
  <author>
    <name>Nick Gerakines</name>
    <email>nick@gerakines.net</email>
  </author>
  <url>http://github.com/yariv/twoorl/commit/0678c070f2a874fe7e2a00392f2ae07932f91284</url>
  <id>0678c070f2a874fe7e2a00392f2ae07932f91284</id>
  <committed-date>2008-06-09T21:19:34-07:00</committed-date>
  <authored-date>2008-06-09T21:19:34-07:00</authored-date>
  <message>Added mnesia, mysql and compile start phases. Moved misc but mutable config to twoorl.app. Made a number of changes to remove the application dependancy to twoorl:start/0, deprecated a lot of stuff.</message>
  <tree>8aaa07f080224041fdccefda73552918877e9421</tree>
  <committer>
    <name>Nick Gerakines</name>
    <email>nick@gerakines.net</email>
  </committer>
</commit>
