Merge "Support rate-limiting thumbnail generation"
[lhc/web/wiklou.git] / includes / installer / PostgresUpdater.php
index 0a319ee..79183da 100644 (file)
@@ -46,9 +46,9 @@ class PostgresUpdater extends DatabaseUpdater {
                        # r15791 Change reserved word table names "user" and "text"
                        array( 'renameTable', 'user', 'mwuser' ),
                        array( 'renameTable', 'text', 'pagecontent' ),
-                       array( 'renameIndex', 'mwuser', 'user_pkey', 'mwuser_pkey'),
+                       array( 'renameIndex', 'mwuser', 'user_pkey', 'mwuser_pkey' ),
                        array( 'renameIndex', 'mwuser', 'user_user_name_key', 'mwuser_user_name_key' ),
-                       array( 'renameIndex', 'pagecontent','text_pkey', 'pagecontent_pkey' ),
+                       array( 'renameIndex', 'pagecontent', 'text_pkey', 'pagecontent_pkey' ),
 
                        # renamed sequences
                        array( 'renameSequence', 'ipblocks_ipb_id_val', 'ipblocks_ipb_id_seq'         ),
@@ -89,7 +89,6 @@ class PostgresUpdater extends DatabaseUpdater {
                        array( 'addTable', 'module_deps',       'patch-module_deps.sql' ),
                        array( 'addTable', 'uploadstash',       'patch-uploadstash.sql' ),
                        array( 'addTable', 'user_former_groups','patch-user_former_groups.sql' ),
-                       array( 'addTable', 'external_user',     'patch-external_user.sql' ),
                        array( 'addTable', 'sites',             'patch-sites.sql' ),
 
                        # Needed before new field
@@ -206,6 +205,8 @@ class PostgresUpdater extends DatabaseUpdater {
                        array( 'changeField', 'templatelinks', 'tl_namespace',    'smallint', 'tl_namespace::smallint' ),
                        array( 'changeField', 'user_newtalk',  'user_ip',         'text',     'host(user_ip)' ),
                        array( 'changeField', 'uploadstash',   'us_image_bits',   'smallint', '' ),
+                       array( 'changeField', 'profiling',     'pf_time',         'float', '' ),
+                       array( 'changeField', 'profiling',     'pf_memory',       'float', '' ),
 
                        # null changes
                        array( 'changeNullableField', 'oldimage', 'oi_bits',       'NULL' ),
@@ -253,9 +254,9 @@ class PostgresUpdater extends DatabaseUpdater {
                        ),
                        'CREATE INDEX cl_sortkey ON "categorylinks" USING "btree" ("cl_to", "cl_sortkey", "cl_from")' ),
                        array( 'checkIndex', 'iwl_prefix_title_from', array(
-                               array('iwl_prefix', 'text_ops', 'btree', 0),
-                               array('iwl_title', 'text_ops', 'btree', 0),
-                               array('iwl_from', 'int4_ops', 'btree', 0),
+                               array( 'iwl_prefix', 'text_ops', 'btree', 0 ),
+                               array( 'iwl_title', 'text_ops', 'btree', 0 ),
+                               array( 'iwl_from', 'int4_ops', 'btree', 0 ),
                        ),
                        'CREATE INDEX iwl_prefix_title_from ON "iwlinks" USING "btree" ("iwl_prefix", "iwl_title", "iwl_from")' ),
                        array( 'checkIndex', 'logging_times', array(
@@ -309,11 +310,11 @@ class PostgresUpdater extends DatabaseUpdater {
                        array( 'checkOiNameConstraint' ),
                        array( 'checkPageDeletedTrigger' ),
                        array( 'checkRevUserFkey' ),
-                       array( 'dropIndex', 'ipblocks', 'ipb_address'),
+                       array( 'dropIndex', 'ipblocks', 'ipb_address' ),
                        array( 'checkIndex', 'ipb_address_unique', array(
                                array( 'ipb_address', 'text_ops', 'btree', 0 ),
-                               array( 'ipb_user',    'int4_ops', 'btree', 0 ),
-                               array( 'ipb_auto',    'int2_ops', 'btree', 0 ),
+                               array( 'ipb_user', 'int4_ops', 'btree', 0 ),
+                               array( 'ipb_auto', 'int2_ops', 'btree', 0 ),
                                array( 'ipb_anon_only', 'int2_ops', 'btree', 0 ),
                        ),
                        'CREATE UNIQUE INDEX ipb_address_unique ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only)' ),
@@ -372,25 +373,25 @@ class PostgresUpdater extends DatabaseUpdater {
                # Add missing extension fields
                foreach ( $wgExtPGNewFields as $fieldRecord ) {
                        $updates[] = array(
-                                       'addPgField', $fieldRecord[0], $fieldRecord[1],
-                                       $fieldRecord[2]
-                               );
+                               'addPgField', $fieldRecord[0], $fieldRecord[1],
+                               $fieldRecord[2]
+                       );
                }
 
                # Change altered columns
                foreach ( $wgExtPGAlteredFields as $fieldRecord ) {
                        $updates[] = array(
-                                       'changeField', $fieldRecord[0], $fieldRecord[1],
-                                       $fieldRecord[2]
-                               );
+                               'changeField', $fieldRecord[0], $fieldRecord[1],
+                               $fieldRecord[2]
+                       );
                }
 
                # Add missing extension indexes
                foreach ( $wgExtNewIndexes as $fieldRecord ) {
                        $updates[] = array(
-                                       'addPgExtIndex', $fieldRecord[0], $fieldRecord[1],
-                                       $fieldRecord[2]
-                               );
+                               'addPgExtIndex', $fieldRecord[0], $fieldRecord[1],
+                               $fieldRecord[2]
+                       );
                }
 
                return $updates;
@@ -404,8 +405,8 @@ SELECT attname, attnum FROM pg_namespace, pg_class, pg_attribute
          AND relname=%s AND nspname=%s
 END;
                $res = $this->db->query( sprintf( $q,
-                               $this->db->addQuotes( $table ),
-                               $this->db->addQuotes( $this->db->getCoreSchema() ) ) );
+                       $this->db->addQuotes( $table ),
+                       $this->db->addQuotes( $this->db->getCoreSchema() ) ) );
                if ( !$res ) {
                        return null;
                }
@@ -413,10 +414,11 @@ END;
                $cols = array();
                foreach ( $res as $r ) {
                        $cols[] = array(
-                                       "name" => $r[0],
-                                       "ord" => $r[1],
-                               );
+                               "name" => $r[0],
+                               "ord" => $r[1],
+                       );
                }
+
                return $cols;
        }
 
@@ -486,11 +488,12 @@ END;
                if ( !( $row = $this->db->fetchRow( $r ) ) ) {
                        return null;
                }
+
                return $row[0];
        }
 
        function ruleDef( $table, $rule ) {
-       $q = <<<END
+               $q = <<<END
 SELECT definition FROM pg_rules
        WHERE schemaname = %s
          AND tablename = %s
@@ -509,6 +512,7 @@ END;
                        return null;
                }
                $d = $row[0];
+
                return $d;
        }
 
@@ -516,7 +520,7 @@ END;
                if ( !$this->db->sequenceExists( $ns ) ) {
                        $this->output( "Creating sequence $ns\n" );
                        $this->db->query( "CREATE SEQUENCE $ns" );
-                       if( $pkey !== false ) {
+                       if ( $pkey !== false ) {
                                $this->setDefault( $table, $pkey, '"nextval"(\'"' . $ns . '"\'::"regclass")' );
                        }
                }
@@ -525,6 +529,7 @@ END;
        protected function renameSequence( $old, $new ) {
                if ( $this->db->sequenceExists( $new ) ) {
                        $this->output( "...sequence $new already exists.\n" );
+
                        return;
                }
                if ( $this->db->sequenceExists( $old ) ) {
@@ -539,7 +544,7 @@ END;
                        $old = $this->db->realTableName( $old, "quoted" );
                        $new = $this->db->realTableName( $new, "quoted" );
                        $this->db->query( "ALTER TABLE $old RENAME TO $new" );
-                       if( $patch !== false ) {
+                       if ( $patch !== false ) {
                                $this->applyPatch( $patch );
                        }
                }
@@ -551,6 +556,7 @@ END;
                // First requirement: the table must exist
                if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
                        $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
+
                        return;
                }
 
@@ -558,17 +564,19 @@ END;
                if ( $this->db->indexExists( $table, $new, __METHOD__ ) ) {
                        $this->output( "...index $new already set on $table table.\n" );
                        if ( !$skipBothIndexExistWarning
-                               && $this->db->indexExists( $table, $old, __METHOD__ ) )
-                       {
+                               && $this->db->indexExists( $table, $old, __METHOD__ )
+                       {
                                $this->output( "...WARNING: $old still exists, despite it has been renamed into $new (which also exists).\n" .
                                        "            $old should be manually removed if not needed anymore.\n" );
                        }
+
                        return;
                }
 
                // Third requirement: the old index must exist
                if ( !$this->db->indexExists( $table, $old, __METHOD__ ) ) {
                        $this->output( "...skipping: index $old doesn't exist.\n" );
+
                        return;
                }
 
@@ -579,6 +587,7 @@ END;
                $fi = $this->db->fieldInfo( $table, $field );
                if ( !is_null( $fi ) ) {
                        $this->output( "...column '$table.$field' already exists\n" );
+
                        return;
                } else {
                        $this->output( "Adding column '$table.$field'\n" );
@@ -593,9 +602,9 @@ END;
                        exit( 1 );
                }
 
-               if ( $fi->type() === $newtype )
+               if ( $fi->type() === $newtype ) {
                        $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
-               else {
+               else {
                        $this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" );
                        $sql = "ALTER TABLE $table ALTER $field TYPE $newtype";
                        if ( strlen( $default ) ) {
@@ -639,8 +648,7 @@ END;
                        if ( 'NULL' === $null ) {
                                $this->output( "Changing '$table.$field' to allow NULLs\n" );
                                $this->db->query( "ALTER TABLE $table ALTER $field DROP NOT NULL" );
-                       }
-                       else {
+                       } else {
                                $this->output( "...column '$table.$field' is already set as NOT NULL\n" );
                        }
                }
@@ -672,6 +680,7 @@ END;
                $fi = $this->db->fieldInfo( $table, $field );
                if ( is_null( $fi ) ) {
                        $this->output( "WARNING! Column '$table.$field' does not exist but it should! Please report this.\n" );
+
                        return;
                }
                if ( $fi->is_deferred() && $fi->is_deferrable() ) {
@@ -745,7 +754,7 @@ END;
        protected function dropIndex( $table, $index, $patch = '', $fullpath = false ) {
                if ( $this->db->indexExists( $table, $index ) ) {
                        $this->output( "Dropping obsolete index '$index'\n" );
-                       $this->db->query( "DROP INDEX \"". $index ."\"" );
+                       $this->db->query( "DROP INDEX \"" . $index . "\"" );
                }
        }
 
@@ -753,7 +762,7 @@ END;
                $pu = $this->db->indexAttributes( $index );
                if ( !empty( $pu ) && $pu != $should_be ) {
                        $this->output( "Dropping obsolete version of index '$index'\n" );
-                       $this->db->query( "DROP INDEX \"". $index ."\"" );
+                       $this->db->query( "DROP INDEX \"" . $index . "\"" );
                        $pu = array();
                } else {
                        $this->output( "...no need to drop index '$index'\n" );