Results of my work on new-installer and Pg.
authorMark A. Hershberger <mah@users.mediawiki.org>
Thu, 3 Feb 2011 04:06:11 +0000 (04:06 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Thu, 3 Feb 2011 04:06:11 +0000 (04:06 +0000)
* NOTE: this commit removes any semblence of tsearch compatibility with pre-8.3 PostgreSQL
* Make new-installer work against PostgreSQL
* Remove SearchPostgres.php's call to pg_fetch_result.  I think this is the only one outside of the vestigtial old installer code.

includes/installer/PostgresInstaller.php
includes/search/SearchPostgres.php
maintenance/postgres/tables.sql

index bf8b6bd..0f3b406 100644 (file)
@@ -70,7 +70,7 @@ class PostgresInstaller extends DatabaseInstaller {
                }
 
                // Try to connect
-               $status->merge( $this->getConnection() );
+               $status->merge( $this->getConnection( 'template1' ) );
                if ( !$status->isOK() ) {
                        return $status;
                }
@@ -107,8 +107,32 @@ class PostgresInstaller extends DatabaseInstaller {
                return $status;
        }
 
+       function getConnection($database = null) {
+               $status = Status::newGood();
+
+               if( is_null( $database ) ) {
+                       $dbname = $this->getVar( 'wgDBname' );
+                       $dbuser = $this->getVar( 'wgDBuser' );
+                       $dbpass = $this->getVar( 'wgDBpassword' );
+               } else {
+                       $dbname = $database;
+                       $dbuser = $this->getVar( '_InstallUser' );
+                       $dbpass = $this->getVar( '_InstallPassword' );
+               }
+
+               try {
+                       $this->db = new DatabasePostgres(
+                               $this->getVar( 'wgDBserver' ),
+                               $dbuser, $dbpass, $dbname );
+                       $status->value = $this->db;
+               } catch ( DBConnectionError $e ) {
+                       $status->fatal( 'config-connection-error', $e->getMessage() );
+               }
+               return $status;
+       }
+
        protected function canCreateAccounts() {
-               $status = $this->getConnection();
+               $status = $this->getConnection( 'template1' );
                if ( !$status->isOK() ) {
                        return false;
                }
@@ -200,7 +224,7 @@ class PostgresInstaller extends DatabaseInstaller {
        }
 
        function setupDatabase() {
-               $status = $this->getConnection();
+               $status = $this->getConnection( 'template1' );
                if ( !$status->isOK() ) {
                        return $status;
                }
@@ -265,7 +289,7 @@ class PostgresInstaller extends DatabaseInstaller {
                        return Status::newGood();
                }
 
-               $status = $this->getConnection();
+               $status = $this->getConnection( 'template1' );
                if ( !$status->isOK() ) {
                        return $status;
                }
@@ -273,12 +297,18 @@ class PostgresInstaller extends DatabaseInstaller {
                $db = $this->getVar( 'wgDBname' );
                $this->db->selectDB( $db );
                $safeuser = $this->db->addIdentifierQuotes( $this->getVar( 'wgDBuser' ) );
+               $safeusercheck = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) );
                $safepass = $this->db->addQuotes( $this->getVar( 'wgDBpassword' ) );
+
+               $rows = $this->db->numRows(
+                       $this->db->query( "SELECT 1 FROM pg_catalog.pg_shadow WHERE usename = $safeusercheck" )
+               );
+               if ( $rows < 1 ) {
                $res = $this->db->query( "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass", __METHOD__ );
-               return $status;
 
-               if ( $res !== true ) {
-                       $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ) );
+                       if ( $res !== true && !( $res instanceOf ResultWrapper ) ) {
+                               $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $res );
+               }
                }
 
                return $status;
index 70997f3..c06978e 100644 (file)
@@ -151,7 +151,8 @@ class SearchPostgres extends SearchEngine {
                        ## TODO: Better output (example to catch: one 'two)
                        die ("Sorry, that was not a valid search string. Please go back and try again");
                }
-               $top = pg_fetch_result($res,0,0);
+               $top = $res->fetchRow();
+               $top = $top[0];
 
                if ($top === "") { ## e.g. if only stopwords are used XXX return something better
                        $query = "SELECT page_id, page_namespace, page_title, 0 AS score ".
index c302361..5edb030 100644 (file)
@@ -9,6 +9,21 @@
 BEGIN;
 SET client_min_messages = 'ERROR';
 
+DROP SEQUENCE IF EXISTS user_user_id_seq;
+DROP SEQUENCE IF EXISTS page_page_id_seq;
+DROP SEQUENCE IF EXISTS revision_rev_id_seq;
+DROP SEQUENCE IF EXISTS page_restrictions_id_seq;
+DROP SEQUENCE IF EXISTS ipblocks_ipb_id_seq;
+DROP SEQUENCE IF EXISTS recentchanges_rc_id_seq;
+DROP SEQUENCE IF EXISTS logging_log_id_seq;
+DROP SEQUENCE IF EXISTS trackbacks_tb_id_seq;
+DROP SEQUENCE IF EXISTS job_job_id_seq;
+DROP SEQUENCE IF EXISTS category_cat_id_seq;
+DROP FUNCTION IF EXISTS page_deleted();
+DROP FUNCTION IF EXISTS ts2_page_title();
+DROP FUNCTION IF EXISTS ts2_page_text();
+DROP FUNCTION IF EXISTS add_interwiki(TEXT,INT,SMALLINT);
+
 CREATE SEQUENCE user_user_id_seq MINVALUE 0 START WITH 0;
 CREATE TABLE mwuser ( -- replace reserved word 'user'
   user_id                   INTEGER  NOT NULL  PRIMARY KEY DEFAULT nextval('user_user_id_seq'),
@@ -495,7 +510,7 @@ CREATE TABLE job (
 CREATE INDEX job_cmd_namespace_title ON job (job_cmd, job_namespace, job_title);
 
 -- Tsearch2 2 stuff. Will fail if we don't have proper access to the tsearch2 tables
--- Note: if version 8.3 or higher, we remove the 'default' arg
+-- Version 8.3 or higher only. Previous versions would need another parmeter for to_tsvector.
 -- Make sure you also change patch-tsearch2funcs.sql if the funcs below change.
 
 ALTER TABLE page ADD titlevector tsvector;
@@ -503,9 +518,9 @@ CREATE FUNCTION ts2_page_title() RETURNS TRIGGER LANGUAGE plpgsql AS
 $mw$
 BEGIN
 IF TG_OP = 'INSERT' THEN
-  NEW.titlevector = to_tsvector('default',REPLACE(NEW.page_title,'/',' '));
+  NEW.titlevector = to_tsvector(REPLACE(NEW.page_title,'/',' '));
 ELSIF NEW.page_title != OLD.page_title THEN
-  NEW.titlevector := to_tsvector('default',REPLACE(NEW.page_title,'/',' '));
+  NEW.titlevector := to_tsvector(REPLACE(NEW.page_title,'/',' '));
 END IF;
 RETURN NEW;
 END;
@@ -520,9 +535,9 @@ CREATE FUNCTION ts2_page_text() RETURNS TRIGGER LANGUAGE plpgsql AS
 $mw$
 BEGIN
 IF TG_OP = 'INSERT' THEN
-  NEW.textvector = to_tsvector('default',NEW.old_text);
+  NEW.textvector = to_tsvector(NEW.old_text);
 ELSIF NEW.old_text != OLD.old_text THEN
-  NEW.textvector := to_tsvector('default',NEW.old_text);
+  NEW.textvector := to_tsvector(NEW.old_text);
 END IF;
 RETURN NEW;
 END;