--- /dev/null
+/*
+ * Copyright (C) 2004-2008 Georgia Public Library Service
+ * Copyright (C) 2008 Equinox Software, Inc., Laurentian University
+ * Mike Rylander <miker@esilibrary.com>
+ * Dan Scott <dscott@laurentian.ca>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+BEGIN;
+
+SET search_path = public, pg_catalog;
+
+CREATE OR REPLACE FUNCTION oils_tsearch2 () RETURNS TRIGGER AS $$
+BEGIN
+ NEW.index_vector = to_tsvector((TG_ARGV[0])::regconfig, NEW.value);
+ RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+DROP TEXT SEARCH DICTIONARY IF EXISTS english_nostop CASCADE;
+
+CREATE TEXT SEARCH DICTIONARY english_nostop (TEMPLATE=pg_catalog.snowball, language='english');
+COMMENT ON TEXT SEARCH DICTIONARY english_nostop IS 'English snowball stemmer with no stopwords for ASCII words only.';
+
+CREATE TEXT SEARCH CONFIGURATION title ( COPY = pg_catalog.english );
+ALTER TEXT SEARCH CONFIGURATION title ALTER MAPPING FOR word, hword, hword_part WITH pg_catalog.simple;
+ALTER TEXT SEARCH CONFIGURATION title ALTER MAPPING FOR asciiword, asciihword, hword_asciipart WITH english_nostop;
+CREATE TEXT SEARCH CONFIGURATION author ( COPY = title );
+CREATE TEXT SEARCH CONFIGURATION subject ( COPY = title );
+CREATE TEXT SEARCH CONFIGURATION keyword ( COPY = title );
+CREATE TEXT SEARCH CONFIGURATION identifier ( COPY = title );
+CREATE TEXT SEARCH CONFIGURATION series ( COPY = title );
+CREATE TEXT SEARCH CONFIGURATION "default" ( COPY = title );
+
+COMMIT;
--- /dev/null
+-- 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;
+
+CREATE EXTENSION tablefunc;
+CREATE EXTENSION tsearch2;
+CREATE EXTENSION xml2;
+CREATE EXTENSION hstore;
my $sysconfdir = '';
my $pg_contribdir = '';
my $create_db_sql = '';
+my $create_db_sql_9_1 = '';
my @services;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$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);
+ my @temp = `psql -qtc 'show server_version;' | xargs | cut -c1,3`;
+ chomp $temp[0];
+ my $pgversion = $temp[0];
+ my $cmd;
+ # If it looks like it is 9.1 or greater, use create_database_9_1.sql
+ # Otherwise use create_database.sql
+ if($pgversion >= '91') {
+ $cmd = 'psql -vdb_name=' . $settings->{db} . ' -d postgres -f ' . $create_db_sql_9_1;
+ } else {
+ $cmd = 'psql -vdb_name=' . $settings->{db} . ' -vcontrib_dir=' . $pg_contribdir .
+ ' -d postgres -f ' . $create_db_sql;
+ }
+ my @output = `$cmd 2>&1`;
+ if(grep(/(ERROR|No such file or directory)/,@output)) {
+ push(@output, "\n------------------------------------------------------------------------------\n",
+ "There was a problem creating the database.\n",
+ "See above for more information.\n");
+ if(grep/unsupported language/, @output) {
+ push(@output, "\nYou may need to install the postgresql plperl package on the database server.\n");
+ }
+ if(grep/No such file or directory/, @output) {
+ if($pgversion >= '91') {
+ push(@output, "\nYou may need to install the postgresql contrib package on the database server.\n");
+ } else {
+ push(@output, "\nYou may need to install the postgresql contrib package on this server.\n");
+ }
+ }
+ push(@output, "------------------------------------------------------------------------------\n");
+ die(@output);
+ }
}
=item create_schema() - Creates the database schema by calling build-db.sh
"build-db-file=s" => \$build_db_sh,
"pg-contrib-dir=s" => \$pg_contribdir,
"create-db-sql=s" => \$create_db_sql,
+ "create-db-sql-9-1=s" => \$create_db_sql_9_1,
"pg-config=s" => \$pgconfig,
"admin-user=s" => \$admin_user,
"admin-password=s" => \$admin_pw,
$create_db_sql = File::Spec->catfile($script_dir, '../sql/Pg/create_database.sql');
}
+if (!$create_db_sql_9_1) {
+ $create_db_sql_9_1 = File::Spec->catfile($script_dir, '../sql/Pg/create_database_9_1.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); }