OverloardQ or other PG person, please review
authorMark A. Hershberger <mah@users.mediawiki.org>
Tue, 17 Aug 2010 03:07:27 +0000 (03:07 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Tue, 17 Aug 2010 03:07:27 +0000 (03:07 +0000)
These patches were necessary to get new-installer working on PG for me.  I'm not sure about the ‘create lang' bits — they should maybe be in another step?

includes/installer/DatabaseInstaller.php
includes/installer/PostgresInstaller.php
maintenance/postgres/tables.sql

index 7342fa2..67f2479 100644 (file)
@@ -302,11 +302,11 @@ abstract class DatabaseInstaller {
                if ( !$status->isOK() ) {
                        return false;
                }
-               $conn = $status->value;
-               if ( !$conn->selectDB( $this->getVar( 'wgDBname' ) ) ) {
+
+               if ( !$this->db->selectDB( $this->getVar( 'wgDBname' ) ) ) {
                        return false;
                }
-               return $conn->tableExists( 'cur' ) || $conn->tableExists( 'revision' );
+               return $this->db->tableExists( 'cur' ) || $this->db->tableExists( 'revision' );
        }
 
        /**
index bb812e8..8b3643c 100644 (file)
@@ -18,15 +18,8 @@ class PostgresInstaller extends DatabaseInstaller {
                'wgDBts2schema',
        );
 
-       protected $internalDefaults = array(
-               '_InstallUser' => 'postgres',
-               '_InstallPassword' => '',
-       );
-
        var $minimumVersion = '8.1';
 
-       var $conn;
-
        function getName() {
                return 'postgres';
        }
@@ -80,40 +73,39 @@ class PostgresInstaller extends DatabaseInstaller {
 
                // Try to connect
                if ( $status->isOK() ) {
-                       $status->merge( $this->attemptConnection() );
+                       $status->merge( $this->getConnection() );
                }
                if ( !$status->isOK() ) {
                        return $status;
                }
 
                // Check version
-               $version = $this->conn->getServerVersion();
+               $version = $this->db->getServerVersion();
                if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
                        return Status::newFatal( 'config-postgres-old', $this->minimumVersion, $version );
                }
+
+               $this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
+               $this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
                return $status;
        }
 
-       function attemptConnection() {
+       function getConnection() {
                $status = Status::newGood();
 
                try {
-                       $this->conn = new DatabasePostgres( 
+                       $this->db = new DatabasePostgres(
                                $this->getVar( 'wgDBserver' ),
                                $this->getVar( '_InstallUser' ),
                                $this->getVar( '_InstallPassword' ),
-                               'postgres' );
-                       $status->value = $this->conn;
+                               $this->getVar( 'wgDBname' ) );
+                       $status->value = $this->db;
                } catch ( DBConnectionError $e ) {
                        $status->fatal( 'config-connection-error', $e->getMessage() );
                }
                return $status;
        }
 
-       function getConnection() {
-               return $this->attemptConnection();
-       }
-
        function getSettingsForm() {
                return false;
        }
@@ -126,6 +118,19 @@ class PostgresInstaller extends DatabaseInstaller {
        }
 
        function createTables() {
+               $status = $this->getConnection();
+               if ( !$status->isOK() ) {
+                       return $status;
+       }
+               $this->db->selectDB( $this->getVar( 'wgDBname' ) );
+
+               global $IP;
+               $err = $this->db->sourceFile( "$IP/maintenance/postgres/tables.sql" );
+               if ( $err !== true ) {
+                       //@todo or...?
+                       $this->db->reportQueryError( $err, 0, $sql, __FUNCTION__ );
+               }
+               return Status::newGood();
        }
 
        function getLocalSettings() {
index 60d0413..f45b505 100644 (file)
@@ -72,6 +72,7 @@ CREATE INDEX page_mediawiki_title    ON page (page_title) WHERE page_namespace =
 CREATE INDEX page_random_idx         ON page (page_random);
 CREATE INDEX page_len_idx            ON page (page_len);
 
+CREATE LANGUAGE 'plpgsql';
 CREATE FUNCTION page_deleted() RETURNS TRIGGER LANGUAGE plpgsql AS
 $mw$
 BEGIN