[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[6337] branches/1.3/tools/prepare-company-database. pl



Revision: 6337
          http://sourceforge.net/p/ledger-smb/code/6337
Author:   ehuelsmann
Date:     2014-01-01 23:33:19 +0000 (Wed, 01 Jan 2014)
Log Message:
-----------
Make prepare-company-database.pl work (better) with PostgreSQL 9.1
(and a bit more user-friendly by checking available extensions
 instead of failing silently).

Modified Paths:
--------------
    branches/1.3/tools/prepare-company-database.pl

Modified: branches/1.3/tools/prepare-company-database.pl
===================================================================
--- branches/1.3/tools/prepare-company-database.pl	2014-01-01 21:47:43 UTC (rev 6336)
+++ branches/1.3/tools/prepare-company-database.pl	2014-01-01 23:33:19 UTC (rev 6337)
@@ -62,7 +62,7 @@
 my $cc = 'us';
 my $coa="$srcdir/sql/coa/us/chart/General.sql";
 my $gifi=undef;
-my $pgsql_contrib_dir='ignore';
+my $pgsql_contrib_dir=undef;
 my $progress=0;
 my $help=0;
 
@@ -136,7 +136,7 @@
 #
 $ENV{PG_CONTRIB_DIR} = $pgsql_contrib_dir if $pgsql_contrib_dir;
 $ENV{PGUSER} = $owner if $owner;
-$ENV{PGPASS} = $pass if $pass;
+$ENV{PGPASSWORD} = $pass if $pass;
 $ENV{PGDATABASE} = $company if $company;
 $ENV{PGHOST} = $host if $host;
 $ENV{PGPORT} = $port if $port;
@@ -150,6 +150,31 @@
        password => $pass}
 );
 
+my $dbh  = DBI->connect("dbi:Pg:dbname=template1",
+			    $database->{username},
+			    $database->{password}, { AutoCommit => 0 });
+my $sth = $dbh->prepare("SELECT version()");
+$sth->execute();
+my ($pg_dbversion) = $sth->fetchrow_array();
+$sth->finish();
+
+if ($pg_dbversion =~ m/^PostgreSQL (8\.4|9\.0)/) {
+    die "Your database version requires the --pgsql-contrib option"
+	if ! defined $pgsql_contrib_dir;
+} else { # assume 9.1+ (this could however be 8.3-)
+    $sth = $dbh->prepare(
+	"select count(*)=3 from pg_available_extensions()" .
+	" where name in ('btree_gist', 'pg_trgm', 'tablefunc')");
+    $sth->execute();
+    my ($have_required_extensions) = $sth->fetchrow_array();
+    $sth->finish();
+
+    die "You don't have all the required contribs installed (btree_gist," .
+	" pg_trgm, tablefunc)"
+	if ! $have_required_extensions;
+}
+$dbh->disconnect();
+
 # Creating the actual database and loading it.  Note that process_roles is 
 # currently a separate call.  If you don't do that then permissions are never 
 # set up and therefore creating a user and assigning roles become futile 
@@ -167,11 +192,9 @@
 
 my $lsmb = LedgerSMB->new() || die 'could not create new LedgerSMB object';
 $lsmb->{dbh} = DBI->connect("dbi:Pg:dbname=$ENV{PGDATABASE}",
-                                       undef, undef, { AutoCommit => 0 });
-
-# We also have to retrieve the country ID which requires a database query
-
-my $sth = $lsmb->{dbh}->prepare(
+			    $database->{username},
+			    $database->{password}, { AutoCommit => 0 });
+$sth = $lsmb->{dbh}->prepare(
             'SELECT id FROM country WHERE short_name ILIKE ?'
 );
 

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits