[open-ils-commits] [GIT] Evergreen ILS branch master updated. 3e3e0bb9a47af4901c3ab5a5ebfdc9fe576f4c26

Evergreen Git git at git.evergreen-ils.org
Thu Aug 18 15:35:29 EDT 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  3e3e0bb9a47af4901c3ab5a5ebfdc9fe576f4c26 (commit)
       via  772fc261f686a569e0339aa5d89a19b03114aed6 (commit)
      from  3dfc7f0005a83e41420b1dc5e36de34f8f263a88 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3e3e0bb9a47af4901c3ab5a5ebfdc9fe576f4c26
Author: Dan Scott <dan at coffeecode.net>
Date:   Thu Aug 18 15:32:53 2011 -0400

    Update README to reflect the --create-database option
    
    Now that eg_db_config.pl is intelligent enough to create the database,
    update the README to free people from the tyranny of having to manually
    issue database creation (and contrib-adding) commands.
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/README b/README
index fe105db..b9c3eb0 100644
--- a/README
+++ b/README
@@ -280,57 +280,59 @@ cpan MARC::File::XML
 cpan UUID::Tiny
 ------------------------------------------------------------------------------
 
-Once the PostgreSQL database server has been installed, you must
-create the database and add the appropriate languages and extensions to
-support Evergreen. Issue the following commands as the `postgres` user to set
-up a database called `evergreen`. Note that the location of the PostgreSQL
-`contrib` packages may vary depending on your distribution. In the following
-commands, we assume that you are working with PostgreSQL 9.0 on a Debian-based
-system:
-
-[source, bash]
-------------------------------------------------------------------------------
-createdb --template template0 --lc-ctype=C --lc-collate=C --encoding UNICODE evergreen
-createlang plperl evergreen
-createlang plperlu evergreen
-psql -f /usr/share/postgresql/9.0/contrib/tablefunc.sql -d evergreen
-psql -f /usr/share/postgresql/9.0/contrib/tsearch2.sql -d evergreen
-psql -f /usr/share/postgresql/9.0/contrib/pgxml.sql -d evergreen
-psql -f /usr/share/postgresql/9.0/contrib/hstore.sql -d evergreen
-------------------------------------------------------------------------------
-
-Once you have created the Evergreen database, you need to create a PostgreSQL
-user to access the database. Issue the following command as the `postgres`
-user to create a new PostgreSQL superuser named `evergreen`. When prompted,
-enter the new user's password:
+You need to create a PostgreSQL superuser to create and access the database.
+Issue the following command as the `postgres` user to create a new PostgreSQL
+superuser named `evergreen`. When prompted, enter the new user's password:
 
 [source, bash]
 ------------------------------------------------------------------------------
 createuser -s -P evergreen
 ------------------------------------------------------------------------------
 
-Once you have created the Evergreen database, you also need to create the
-database schema and configure your configuration files to point at the
+Once you have created the Evergreen superuser, you also need to create the
+database and schema, and configure your configuration files to point at the
 database server. Issue the following command as root from inside the Evergreen
 source directory, replacing <user>, <password>, <hostname>, <port>, and <dbname>
-with the appropriate values for your PostgreSQL database, and <admin-user> and
-<admin-pass> with the values you want for the default Evergreen administrator
-account:
+with the appropriate values for your PostgreSQL database (where <user> and
+<password> are for the PostgreSQL superuser you just created), and replace
+<admin-user> and <admin-pass> with the values you want for the default
+Evergreen administrator account:
 
 [source, bash]
 ------------------------------------------------------------------------------
 perl Open-ILS/src/support-scripts/eg_db_config.pl --update-config \
-       --service all --create-schema --create-offline \
+       --service all --create-database --create-schema --create-offline \
        --user <user> --password <password> --hostname <hostname> --port <port> \
        --database <dbname> --admin-user <admin-user> --admin-pass <admin-pass>
 ------------------------------------------------------------------------------
 
-This creates the database schema and configures all of the services in
+This creates the database and schema and configures all of the services in
 your `/openils/conf/opensrf.xml` configuration file to point to that database.
 It also creates the configuration files required by the Evergreen cgi-bin
-administration scripts, and set the user name and password for the default
+administration scripts, and sets the user name and password for the default
 Evergreen administrator account to your requested values.
 
+Creating the database on a remote server
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+In a production instance of Evergreen, your PostgreSQL server should be
+installed on a dedicated server. To create the database in that case, you
+can either:
+
+  *  Install the PostgreSQL contrib modules on the machine on which you
+     are installing the Evergreen code, and use the --create-database
+     option from that machine, or
+  *  Copy the `Open-ILS/src/sql/Pg/create-database.sql` script to your
+     PostgreSQL server and invoke it with:
++
+[source, bash]
+------------------------------------------------------------------------------
+psql -vdb_name=<dbname> -vcontrib_dir=`pg_config --sharedir`/contrib
+------------------------------------------------------------------------------
+
+Then you can issue the `eg_db_config.pl` command as above _without_ the
+`--create-database` argument to create your schema and configure your
+configuration files.
+
 Developer instructions:
 -----------------------
 

commit 772fc261f686a569e0339aa5d89a19b03114aed6
Author: Thomas Berezansky <tsbere at mvlc.org>
Date:   Thu Aug 18 12:06:46 2011 -0400

    Add --create-database option to eg_db_config.pl
    
    Uses create_database.sql and superuser rights to do all
    database creation steps other than making a usable superuser
    account to begin with.
    
    Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>

diff --git a/Open-ILS/src/sql/Pg/create_database.sql b/Open-ILS/src/sql/Pg/create_database.sql
new file mode 100644
index 0000000..b3be0f0
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/create_database.sql
@@ -0,0 +1,30 @@
+-- This file is intended to be called by eg_db_config.pl
+
+-- If manually calling:
+-- Connect to the postgres database initially
+-- Specify the database to create as -vdb_name=DATABASE
+-- Specify the postgres contrib directory as -vcontrib_dir=CONTRIBDIR
+-- You can get the contrib directory using pg_config --sharedir and adding a /contrib to it
+
+-- NOTE: This file does not do transactions
+-- This is intentional. Please do not wrap in BEGIN/COMMIT.
+DROP DATABASE IF EXISTS :db_name;
+
+CREATE DATABASE :db_name TEMPLATE template0 ENCODING 'UNICODE' LC_COLLATE 'C' LC_CTYPE 'C';
+
+\connect :db_name
+
+CREATE LANGUAGE plperl;
+CREATE LANGUAGE plperlu;
+
+-- This dance is because :variable/blah doesn't seem to work when doing \i
+-- But it does when doing \set
+-- So we \set to a single variable, then use that single variable with \i
+\set load_file :contrib_dir/tablefunc.sql
+\i :load_file
+\set load_file :contrib_dir/tsearch2.sql
+\i :load_file
+\set load_file :contrib_dir/pgxml.sql
+\i :load_file
+\set load_file :contrib_dir/hstore.sql
+\i :load_file
diff --git a/Open-ILS/src/support-scripts/eg_db_config.pl b/Open-ILS/src/support-scripts/eg_db_config.pl
index 498eaf5..7a3c2a8 100755
--- a/Open-ILS/src/support-scripts/eg_db_config.pl
+++ b/Open-ILS/src/support-scripts/eg_db_config.pl
@@ -31,6 +31,8 @@ my $build_db_sh = '';
 my $offline_file = '';
 my $prefix = '';
 my $sysconfdir = '';
+my $pg_contribdir = '';
+my $create_db_sql = '';
 my @services;
 
 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
@@ -124,6 +126,20 @@ sub get_settings {
 	$settings->{pw} = $settings->{pw} || $opensrf_config->findnodes($pw);
 }
 
+=item create_database() - Creates the database using create_database.sql
+=cut
+sub create_database {
+	my $settings = shift;
+
+	$ENV{'PGUSER'} = $settings->{user};
+	$ENV{'PGPASSWORD'} = $settings->{pw};
+	$ENV{'PGPORT'} = $settings->{port};
+	$ENV{'PGHOST'} = $settings->{host};
+	my $cmd = 'psql -vdb_name=' . $settings->{db} . ' -vcontrib_dir=' . $pg_contribdir .
+		' -d postgres -f ' . $create_db_sql;
+	system($cmd);
+}
+
 =item create_schema() - Creates the database schema by calling build-db.sh
 =cut
 sub create_schema {
@@ -164,15 +180,21 @@ sub set_admin_account {
 }
 
 my $offline;
+my $cdatabase;
 my $cschema;
 my $uconfig;
+my $pgconfig;
 my %settings;
 
 GetOptions("create-schema" => \$cschema, 
+		"create-database" => \$cdatabase,
 		"create-offline" => \$offline,
 		"update-config" => \$uconfig,
 		"config-file=s" => \$config_file,
 		"build-db-file=s" => \$build_db_sh,
+		"pg-contrib-dir=s" => \$pg_contribdir,
+		"create-db-sql=s" => \$create_db_sql,
+		"pg-config" => \$pgconfig,
 		"admin-user=s" => \$admin_user,
 		"admin-password=s" => \$admin_pw,
 		"service=s" => \@services,
@@ -207,25 +229,38 @@ if (!$build_db_sh) {
 	$build_db_sh = File::Spec->catfile($script_dir, '../sql/Pg/build-db.sh');
 }
 
+if (!$pg_contribdir) {
+	$pgconfig = 'pg_config' if(!$pgconfig);
+	my @temp = `$pgconfig --sharedir`;
+	chomp $temp[0];
+	$pg_contribdir = File::Spec->catdir($temp[0], 'contrib');
+}
+
+if (!$create_db_sql) {
+	$create_db_sql = File::Spec->catfile($script_dir, '../sql/Pg/create_database.sql');
+}
+
 if (!$offline_file) {
 	$offline_file = File::Spec->catfile($sysconfdir, 'offline-config.pl');
 }
 
 unless (-e $build_db_sh) { die "Error: $build_db_sh does not exist. \n"; }
 unless (-e $config_file) { die "Error: $config_file does not exist. \n"; }
+unless (-d $pg_contribdir || !$cdatabase) { die "Error: $pg_contribdir does not exist. \n"; }
 
 if ($uconfig) { update_config(\@services, \%settings); }
 
 # Get our settings from the config file
 get_settings(\%settings);
 
+if ($cdatabase) { create_database(\%settings); }
 if ($cschema) { create_schema(\%settings); }
 if ($admin_user && $admin_pw) {
 	set_admin_account($admin_user, $admin_pw, \%settings);
 }
 if ($offline) { create_offline_config($offline_file, \%settings); }
 
-if ((!$cschema && !$uconfig && !$offline && !$admin_pw) || $help) {
+if ((!$cdatabase && !$cschema && !$uconfig && !$offline && !$admin_pw) || $help) {
 	print <<HERE;
 
 SYNOPSIS
@@ -261,6 +296,10 @@ COMMANDS
         Creates the Evergreen database schema according to the settings in
         the file specified by --config-file.  
 
+    --create-database
+        Creates the database itself, provided the user and password options
+        represent a superuser.
+
 SERVICE OPTIONS
     --service
         Specify "all" or one or more of the following services to update:

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/src/sql/Pg/create_database.sql      |   30 ++++++++++++
 Open-ILS/src/support-scripts/eg_db_config.pl |   41 ++++++++++++++++-
 README                                       |   64 +++++++++++++------------
 3 files changed, 103 insertions(+), 32 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/create_database.sql


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list