From e1840e96b02e7d5afcd0167da81c737036340f8a Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Sun, 2 Aug 2015 23:34:58 +0200 Subject: [PATCH] Fix # 48 Allow to change location of the database --- Changes | 1 + lib/LutimModel.pm | 21 ++++++++++++++++++--- lutim.conf.template | 6 ++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index f5584f3..ad6d32a 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,7 @@ Revision history for Lutim - Allow Lutim to be on a sub-directory (like http://example.org/lutim/) (#46 and #57) - Remove deprecated (due to typo) option "provisionning". - Allow to upload svg images (no thumbnail for now, ImageMagick in Debian Jessie don't work with svg) (#47) + - Allow to change location of the database (#48) 0.6 2014-10-03 - Add OpenGraph tags in social page (ex-twitter page) diff --git a/lib/LutimModel.pm b/lib/LutimModel.pm index 09c9b84..7456baa 100644 --- a/lib/LutimModel.pm +++ b/lib/LutimModel.pm @@ -1,10 +1,25 @@ package LutimModel; +use Mojolicious; +use FindBin qw($Bin); +use File::Spec qw(catfile); + +BEGIN { + my $m = Mojolicious->new; + our $config = $m->plugin('Config' => + { + file => File::Spec->catfile($Bin, '..' ,'lutim.conf'), + default => { + db_path => 'lutim.db' + } + } + ); +} # Create database use ORLite { - file => 'lutim.db', + file => $config->{db_path}, unicode => 1, - create => sub { + create => sub { my $dbh = shift; $dbh->do( 'CREATE TABLE lutim ( @@ -25,7 +40,7 @@ use ORLite { height INTEGER)' ); return 1; - } + } }; 1; diff --git a/lutim.conf.template b/lutim.conf.template index 52af1fb..7af278e 100644 --- a/lutim.conf.template +++ b/lutim.conf.template @@ -103,6 +103,12 @@ # optional, defaut is / #prefix => '/', + # define a path to the SQLite database + # you can define it relative to lutim directory or set an absolute path + # remember that it has to be in a directory writable by Lutim user + # optional, default is lutim.db + #db_path => 'lutim.db', + ########################## # Lutim cron jobs settings ##########################