Fix broken merge by 0a792a1dcba26dd70d64e307b301c6
authorsaper <saper@saper.info>
Fri, 13 Apr 2012 18:55:14 +0000 (20:55 +0200)
committersaper <saper@saper.info>
Fri, 13 Apr 2012 18:55:14 +0000 (20:55 +0200)
Changeset 1 of https://gerrit.wikimedia.org/r/#change,3365:
763b57f9f2af131a2d8e65f520a23c00109be0e1

got mis-merged in changeset 2:
f752cf80423615b380cf5612a3f1f68a6b9d0173

And introduced into master wth
0a792a1dcba26dd70d64e307b301c6773279cfc9

Also, marking all new functions as @since 1.19
since we want to have them there later.

Patchset 2: whitespace fixes
Patchset 3: Fix <?php
Patchset 4: rebase to current master

Change-Id: Ic7d940dfec8890de20197128505962375fac4f06

includes/db/DatabasePostgres.php
includes/installer/PostgresUpdater.php
maintenance/postgres/archives/patch-external_user.sql

index d11e13c..fc9c65a 100644 (file)
@@ -7,7 +7,8 @@
  */
 
 class PostgresField implements Field {
-       private $name, $tablename, $type, $nullable, $max_length, $deferred, $deferrable, $conname;
+       private $name, $tablename, $type, $nullable, $max_length, $deferred, $deferrable, $conname,
+               $has_default, $default;
 
        /**
         * @param $db DatabaseBase
@@ -33,6 +34,7 @@ JOIN pg_namespace n ON (n.oid = c.relnamespace)
 JOIN pg_attribute a ON (a.attrelid = c.oid)
 JOIN pg_type t ON (t.oid = a.atttypid)
 LEFT JOIN pg_constraint o ON (o.conrelid = c.oid AND a.attnum = ANY(o.conkey) AND o.contype = 'f')
+LEFT JOIN pg_attrdef d on c.oid=d.adrelid and a.attnum=d.adnum
 WHERE relkind = 'r'
 AND nspname=%s
 AND relname=%s
@@ -60,6 +62,8 @@ SQL;
                $n->deferrable = ( $row->deferrable == 't' );
                $n->deferred = ( $row->deferred == 't' );
                $n->conname = $row->conname;
+               $n->has_default = ( $row->atthasdef === 't' );
+               $n->default = $row->adsrc;
                return $n;
        }
 
@@ -94,6 +98,16 @@ SQL;
        function conname() {
                return $this->conname;
        }
+       /**
+        * @since 1.19
+        */
+       function defaultValue() {
+               if( $this->has_default ) {
+                       return $this->default;
+               } else {
+                       return false;
+               }
+       }
 
 }
 
@@ -101,7 +115,7 @@ SQL;
  * Used to debug transaction processing
  * Only used if $wgDebugDBTransactions is true
  *
- * @since 1.20
+ * @since 1.19
  * @ingroup Database
  */
 class PostgresTransactionState {
@@ -317,7 +331,6 @@ class DatabasePostgres extends DatabaseBase {
        }
 
        protected function doQuery( $sql ) {
-               global $wgDebugDBTransactions;
                if ( function_exists( 'mb_convert_encoding' ) ) {
                        $sql = mb_convert_encoding( $sql, 'UTF-8' );
                }
@@ -526,6 +539,68 @@ class DatabasePostgres extends DatabaseBase {
                return false;
        }
 
+       /**
+        * Returns is of attributes used in index
+        *
+        * @since 1.19
+        * @return Array
+        */
+       function indexAttributes ( $index, $schema = false ) {
+               if ( $schema === false )
+                       $schema = $this->getCoreSchema();
+               /*
+                * A subquery would be not needed if we didn't care about the order
+                * of attributes, but we do
+                */
+               $sql = <<<__INDEXATTR__
+
+                       SELECT opcname,
+                               attname,
+                               i.indoption[s.g] as option,
+                               pg_am.amname
+                       FROM
+                               (SELECT generate_subscripts(isub.indkey, 1) AS g
+                                       FROM
+                                               pg_index isub
+                                       JOIN pg_class cis
+                                               ON cis.oid=isub.indexrelid
+                                       JOIN pg_namespace ns
+                                               ON cis.relnamespace = ns.oid
+                                       WHERE cis.relname='$index' AND ns.nspname='$schema') AS s,
+                               pg_attribute,
+                               pg_opclass opcls,
+                               pg_am,
+                               pg_class ci
+                               JOIN pg_index i
+                                       ON ci.oid=i.indexrelid
+                               JOIN pg_class ct
+                                       ON ct.oid = i.indrelid
+                               JOIN pg_namespace n
+                                       ON ci.relnamespace = n.oid
+                               WHERE
+                                       ci.relname='$index' AND n.nspname='$schema'
+                                       AND     attrelid = ct.oid
+                                       AND     i.indkey[s.g] = attnum
+                                       AND     i.indclass[s.g] = opcls.oid
+                                       AND     pg_am.oid = opcls.opcmethod
+__INDEXATTR__;
+               $res = $this->query($sql, __METHOD__);
+               $a = array();
+               if ( $res ) {
+                       foreach ( $res as $row ) {
+                               $a[] = array(
+                                       $row->attname,
+                                       $row->opcname,
+                                       $row->amname,
+                                       $row->option);
+                       }
+               } else {
+                       return null;
+               }
+               return $a;
+       }
+
+
        function indexUnique( $table, $index, $fname = 'DatabasePostgres::indexUnique' ) {
                $sql = "SELECT indexname FROM pg_indexes WHERE tablename='{$table}'".
                        " AND indexdef LIKE 'CREATE UNIQUE%(" .
@@ -750,14 +825,19 @@ class DatabasePostgres extends DatabaseBase {
                # Replace reserved words with better ones
                switch( $name ) {
                        case 'user':
-                               return 'mwuser';
+                               return $this->realTableName( 'mwuser', $format );
                        case 'text':
-                               return 'pagecontent';
+                               return $this->realTableName( 'pagecontent', $format );
                        default:
-                               return parent::tableName( $name, $format );
+                               return $this->realTableName( $name, $format );
                }
        }
 
+       /* Don't cheat on installer */
+       function realTableName( $name, $format = 'quoted' ) {
+               return parent::tableName( $name, $format );
+       }
+
        /**
         * Return the next in a sequence, save the value for retrieval via insertId()
         * @return null
@@ -844,7 +924,7 @@ class DatabasePostgres extends DatabaseBase {
         *
         * This should really be handled by PHP PostgreSQL module
         *
-        * @since 1.20
+        * @since 1.19
         * @param $text   string: postgreql array returned in a text form like {a,b}
         * @param $output string
         * @param $limit  int
@@ -896,7 +976,7 @@ class DatabasePostgres extends DatabaseBase {
         * Return current schema (executes SELECT current_schema())
         * Needs transaction
         *
-        * @since 1.20
+        * @since 1.19
         * @return string return default schema for the current session
         */
        function getCurrentSchema() {
@@ -912,7 +992,7 @@ class DatabasePostgres extends DatabaseBase {
         *
         * @seealso getSearchPath()
         * @seealso setSearchPath()
-        * @since 1.20
+        * @since 1.19
         * @return array list of actual schemas for the current sesson
         */
        function getSchemas() {
@@ -929,7 +1009,7 @@ class DatabasePostgres extends DatabaseBase {
         * (like "$user").
         * Needs transaction
         *
-        * @since 1.20
+        * @since 1.19
         * @return array how to search for table names schemas for the current user
         */
        function getSearchPath() {
@@ -942,7 +1022,7 @@ class DatabasePostgres extends DatabaseBase {
        /**
         * Update search_path, values should already be sanitized
         * Values may contain magic keywords like "$user"
-        * @since 1.20
+        * @since 1.19
         *
         * @param $search_path array list of schemas to be searched by default
         */
@@ -960,7 +1040,7 @@ class DatabasePostgres extends DatabaseBase {
         *
         * This will be also called by the installer after the schema is created
         *
-        * @since 1.20
+        * @since 1.19
         * @param desired_schema string
         */
        function determineCoreSchema( $desired_schema ) {
@@ -993,7 +1073,7 @@ class DatabasePostgres extends DatabaseBase {
        /**
         * Return schema name fore core MediaWiki tables
         *
-        * @since 1.20
+        * @since 1.19
         * @return string core schema name
         */
        function getCoreSchema() {
@@ -1032,7 +1112,7 @@ class DatabasePostgres extends DatabaseBase {
                if ( !$schema ) {
                        $schema = $this->getCoreSchema();
                }
-               $table = $this->tableName( $table, 'raw' );
+               $table = $this->realTableName( $table, 'raw' );
                $etable = $this->addQuotes( $table );
                $eschema = $this->addQuotes( $schema );
                $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
index 1bb3b9b..0d27c5a 100644 (file)
@@ -35,10 +35,6 @@ class PostgresUpdater extends DatabaseUpdater {
                        array( 'renameIndex', 'mwuser', 'user_user_name_key', 'mwuser_user_name_key' ),
                        array( 'renameIndex', 'pagecontent','text_pkey', 'pagecontent_pkey' ),
 
-                       # new sequences
-                       array( 'addSequence', 'logging_log_id_seq'          ),
-                       array( 'addSequence', 'page_restrictions_pr_id_seq' ),
-
                        # renamed sequences
                        array( 'renameSequence', 'ipblocks_ipb_id_val', 'ipblocks_ipb_id_seq'         ),
                        array( 'renameSequence', 'rev_rev_id_val',      'revision_rev_id_seq'         ),
@@ -79,7 +75,7 @@ class PostgresUpdater extends DatabaseUpdater {
                        array( 'addTable', 'uploadstash',       'patch-uploadstash.sql' ),
                        array( 'addTable', 'user_former_groups','patch-user_former_groups.sql' ),
                        array( 'addTable', 'config',            'patch-config.sql' ),
-                       array( 'addTable', 'external_user','patch-external_user.sql' ),
+                       array( 'addTable', 'external_user',     'patch-external_user.sql' ),
 
                        # Needed before new field
                        array( 'convertArchive2' ),
@@ -152,7 +148,7 @@ class PostgresUpdater extends DatabaseUpdater {
                        array( 'changeField', 'image',         'img_size',        'integer',  '' ),
                        array( 'changeField', 'image',         'img_width',       'integer',  '' ),
                        array( 'changeField', 'image',         'img_height',      'integer',  '' ),
-                       array( 'changeField', 'interwiki',     'iw_local',        'smallint', 'iw_local::smallint DEFAULT 0' ),
+                       array( 'changeField', 'interwiki',     'iw_local',        'smallint', 'iw_local::smallint' ),
                        array( 'changeField', 'interwiki',     'iw_trans',        'smallint', 'iw_trans::smallint DEFAULT 0' ),
                        array( 'changeField', 'ipblocks',      'ipb_auto',        'smallint', 'ipb_auto::smallint DEFAULT 0' ),
                        array( 'changeField', 'ipblocks',      'ipb_anon_only',   'smallint', "CASE WHEN ipb_anon_only=' ' THEN 0 ELSE ipb_anon_only::smallint END DEFAULT 0" ),
index 242e4fa..6058a70 100644 (file)
@@ -4,11 +4,3 @@ CREATE TABLE external_user (
 );
 
 CREATE UNIQUE INDEX eu_external_id ON external_user (eu_external_id);
-
-CREATE TABLE external_user (
-  eu_local_id     INTEGER  NOT NULL  PRIMARY KEY,
-  eu_external_id TEXT
-);
-
-CREATE UNIQUE INDEX eu_external_id ON external_user (eu_external_id);
-