LP#1715503: make eg_db_config refuse to create DB if min Pg version not met
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 20 Sep 2017 15:48:39 +0000 (11:48 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 20 Sep 2017 21:44:01 +0000 (17:44 -0400)
This patch ensures that eg_db_config --create-database will abort if
the Pg version is not at least 9.4. It also tweaks the version check
to (in principle) work for Pg 10.

This patch also removes some stuff related to support Pg versions
less than 9.4, most notably using contribs rather than extensions.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Open-ILS/src/sql/Pg/000.english.pg91.fts-config.sql [deleted file]
Open-ILS/src/sql/Pg/000.english.pg92.fts-config.sql [deleted symlink]
Open-ILS/src/sql/Pg/000.english.pg93.fts-config.sql [deleted symlink]
Open-ILS/src/sql/Pg/000.english.pg94.fts-config.sql [changed from symlink to file mode: 0000->0644]
Open-ILS/src/sql/Pg/000.english.pg95.fts-config.sql
Open-ILS/src/sql/Pg/000.english.pg96.fts-config.sql
Open-ILS/src/sql/Pg/create_database_contribs.sql [deleted file]
Open-ILS/src/support-scripts/eg_db_config.in

diff --git a/Open-ILS/src/sql/Pg/000.english.pg91.fts-config.sql b/Open-ILS/src/sql/Pg/000.english.pg91.fts-config.sql
deleted file mode 100644 (file)
index 8bae23e..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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;
-
-DO $$
-DECLARE
-lang TEXT;
-BEGIN
-FOR lang IN SELECT substring(pptsd.dictname from '(.*)_stem$') AS lang FROM pg_catalog.pg_ts_dict pptsd JOIN pg_catalog.pg_namespace ppn ON ppn.oid = pptsd.dictnamespace
-WHERE ppn.nspname = 'pg_catalog' AND pptsd.dictname LIKE '%_stem' LOOP
-RAISE NOTICE 'FOUND LANGUAGE %', lang;
-
-EXECUTE 'DROP TEXT SEARCH DICTIONARY IF EXISTS ' || lang || '_nostop CASCADE;
-CREATE TEXT SEARCH DICTIONARY ' || lang || '_nostop (TEMPLATE=pg_catalog.snowball, language=''' || lang || ''');
-COMMENT ON TEXT SEARCH DICTIONARY ' || lang || '_nostop IS ''' ||lang || ' snowball stemmer with no stopwords for ASCII words only.'';
-CREATE TEXT SEARCH CONFIGURATION ' || lang || '_nostop ( COPY = pg_catalog.' || lang || ' );
-ALTER TEXT SEARCH CONFIGURATION ' || lang || '_nostop ALTER MAPPING FOR word, hword, hword_part WITH pg_catalog.simple;
-ALTER TEXT SEARCH CONFIGURATION ' || lang || '_nostop ALTER MAPPING FOR asciiword, asciihword, hword_asciipart WITH ' || lang || '_nostop;';
-
-END LOOP;
-END;
-$$;
-CREATE TEXT SEARCH CONFIGURATION title ( COPY = english_nostop );
-CREATE TEXT SEARCH CONFIGURATION author ( COPY = english_nostop );
-CREATE TEXT SEARCH CONFIGURATION subject ( COPY = english_nostop );
-CREATE TEXT SEARCH CONFIGURATION keyword ( COPY = english_nostop );
-CREATE TEXT SEARCH CONFIGURATION identifier ( COPY = english_nostop );
-CREATE TEXT SEARCH CONFIGURATION series ( COPY = english_nostop );
-CREATE TEXT SEARCH CONFIGURATION "default" ( COPY = english_nostop );
-
-
-COMMIT;
diff --git a/Open-ILS/src/sql/Pg/000.english.pg92.fts-config.sql b/Open-ILS/src/sql/Pg/000.english.pg92.fts-config.sql
deleted file mode 120000 (symlink)
index 0b24fd9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-000.english.pg91.fts-config.sql
\ No newline at end of file
diff --git a/Open-ILS/src/sql/Pg/000.english.pg93.fts-config.sql b/Open-ILS/src/sql/Pg/000.english.pg93.fts-config.sql
deleted file mode 120000 (symlink)
index 0b24fd9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-000.english.pg91.fts-config.sql
\ No newline at end of file
deleted file mode 120000 (symlink)
index 0b24fd90f5cf980c8644bae82aecd795dd8a6017..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1 +0,0 @@
-000.english.pg91.fts-config.sql
\ No newline at end of file
new file mode 100644 (file)
index 0000000000000000000000000000000000000000..8bae23e091aae784cdeca502bf510dee3d6a574d
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+DO $$
+DECLARE
+lang TEXT;
+BEGIN
+FOR lang IN SELECT substring(pptsd.dictname from '(.*)_stem$') AS lang FROM pg_catalog.pg_ts_dict pptsd JOIN pg_catalog.pg_namespace ppn ON ppn.oid = pptsd.dictnamespace
+WHERE ppn.nspname = 'pg_catalog' AND pptsd.dictname LIKE '%_stem' LOOP
+RAISE NOTICE 'FOUND LANGUAGE %', lang;
+
+EXECUTE 'DROP TEXT SEARCH DICTIONARY IF EXISTS ' || lang || '_nostop CASCADE;
+CREATE TEXT SEARCH DICTIONARY ' || lang || '_nostop (TEMPLATE=pg_catalog.snowball, language=''' || lang || ''');
+COMMENT ON TEXT SEARCH DICTIONARY ' || lang || '_nostop IS ''' ||lang || ' snowball stemmer with no stopwords for ASCII words only.'';
+CREATE TEXT SEARCH CONFIGURATION ' || lang || '_nostop ( COPY = pg_catalog.' || lang || ' );
+ALTER TEXT SEARCH CONFIGURATION ' || lang || '_nostop ALTER MAPPING FOR word, hword, hword_part WITH pg_catalog.simple;
+ALTER TEXT SEARCH CONFIGURATION ' || lang || '_nostop ALTER MAPPING FOR asciiword, asciihword, hword_asciipart WITH ' || lang || '_nostop;';
+
+END LOOP;
+END;
+$$;
+CREATE TEXT SEARCH CONFIGURATION title ( COPY = english_nostop );
+CREATE TEXT SEARCH CONFIGURATION author ( COPY = english_nostop );
+CREATE TEXT SEARCH CONFIGURATION subject ( COPY = english_nostop );
+CREATE TEXT SEARCH CONFIGURATION keyword ( COPY = english_nostop );
+CREATE TEXT SEARCH CONFIGURATION identifier ( COPY = english_nostop );
+CREATE TEXT SEARCH CONFIGURATION series ( COPY = english_nostop );
+CREATE TEXT SEARCH CONFIGURATION "default" ( COPY = english_nostop );
+
+
+COMMIT;
index 0b24fd9..38504b5 120000 (symlink)
@@ -1 +1 @@
-000.english.pg91.fts-config.sql
\ No newline at end of file
+000.english.pg94.fts-config.sql
\ No newline at end of file
index 0b24fd9..38504b5 120000 (symlink)
@@ -1 +1 @@
-000.english.pg91.fts-config.sql
\ No newline at end of file
+000.english.pg94.fts-config.sql
\ No newline at end of file
diff --git a/Open-ILS/src/sql/Pg/create_database_contribs.sql b/Open-ILS/src/sql/Pg/create_database_contribs.sql
deleted file mode 100644 (file)
index a2fd1c8..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
--- 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/pgxml.sql
-\i :load_file
-\set load_file :contrib_dir/hstore.sql
-\i :load_file
index a08dda9..dc61d09 100755 (executable)
@@ -32,8 +32,6 @@ my $build_db_sh = '';
 my $offline_file = '';
 my $prefix = '';
 my $sysconfdir = '';
-my $pg_contribdir = '';
-my $create_db_sql_contribs = '';
 my $create_db_sql_extensions = '';
 my @services;
 
@@ -135,7 +133,7 @@ sub get_settings {
        $settings->{pw} = $settings->{pw} || $opensrf_config->findnodes($pw);
 }
 
-=item create_database() - Creates the database using create_database_contribs.sql
+=item create_database() - Creates the database using create_database_extensions.sql
 =cut
 sub create_database {
        my $settings = shift;
@@ -144,18 +142,21 @@ sub create_database {
        $ENV{'PGPASSWORD'} = $settings->{pw};
        $ENV{'PGPORT'} = $settings->{port};
        $ENV{'PGHOST'} = $settings->{host};
-       my @temp = `psql -d postgres -qtc 'show server_version;' | xargs | cut -c1,3`;
+       my @temp = `psql -d postgres -qtc 'show server_version;' | xargs | cut -d. -f 1,2 | tr -d '.'`;
        chomp $temp[0];
        my $pgversion = $temp[0];
        my $cmd;
-       # If it looks like it is 9.1 or greater, use create_database_extensions.sql
-       # Otherwise use create_database_contribs.sql
-       if($pgversion >= '91') {
-               $cmd = 'psql -vdb_name=' . $settings->{db} . ' -d postgres -f ' . $create_db_sql_extensions;
-       } else {
-               $cmd = 'psql -vdb_name=' . $settings->{db} . ' -vcontrib_dir=' . $pg_contribdir .
-                       ' -d postgres -f ' . $create_db_sql_contribs;
+       unless ($pgversion >= '94') {
+        my @message = ();
+               push(@message,
+                       "\n------------------------------------------------------------------------------\n",
+                       "Cannot create database; version of PostgreSQL appears to be less than the\n",
+                       "minimum required of 9.4\n",
+                       "------------------------------------------------------------------------------\n",
+               );
+               die(@message);
        }
+       $cmd = 'psql -vdb_name=' . $settings->{db} . ' -d postgres -f ' . $create_db_sql_extensions;
        my @output = `$cmd 2>&1`;
        if(grep(/(ERROR|No such file or directory)/,@output)) {
                push(@output, "\n------------------------------------------------------------------------------\n",
@@ -267,8 +268,6 @@ GetOptions("create-schema" => \$cschema,
                "update-config" => \$uconfig,
                "config-file=s" => \$config_file,
                "build-db-file=s" => \$build_db_sh,
-               "pg-contrib-dir=s" => \$pg_contribdir,
-               "create-db-sql-contribs=s" => \$create_db_sql_contribs,
                "create-db-sql-extensions=s" => \$create_db_sql_extensions,
                "pg-config=s" => \$pgconfig,
                "admin-user=s" => \$admin_user,
@@ -305,17 +304,6 @@ 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_contribs) {
-       $create_db_sql_contribs = File::Spec->catfile($script_dir, '../sql/Pg/create_database_contribs.sql');
-}
-
 if (!$create_db_sql_extensions) {
        $create_db_sql_extensions = File::Spec->catfile($script_dir, '../sql/Pg/create_database_extensions.sql');
 }