Merge "tests related to API block action and its gettoken"
[lhc/web/wiklou.git] / includes / installer / PostgresUpdater.php
index d4412cb..f5f8c41 100644 (file)
@@ -27,6 +27,11 @@ class PostgresUpdater extends DatabaseUpdater {
         */
        protected function getCoreUpdateList() {
                return array(
+                       # rename tables 1.7.3
+                       # r15791 Change reserved word table names "user" and "text"
+                       array( 'renameTable', 'user', 'mwuser'),
+                       array( 'renameTable', 'text', 'pagecontent'),
+
                        # new sequences
                        array( 'addSequence', 'logging_log_id_seq'          ),
                        array( 'addSequence', 'page_restrictions_pr_id_seq' ),
@@ -63,6 +68,7 @@ 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', 'config',            'patch-config.sql' ),
 
                        # Needed before new field
                        array( 'convertArchive2' ),
@@ -164,6 +170,7 @@ class PostgresUpdater extends DatabaseUpdater {
                        array( 'changeField', 'revision',      'rev_minor_edit',  'smallint', 'rev_minor_edit::smallint DEFAULT 0' ),
                        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', '' ),
 
                        # null changes
                        array( 'changeNullableField', 'oldimage', 'oi_bits',       'NULL' ),
@@ -406,7 +413,8 @@ END;
        protected function renameTable( $old, $new ) {
                if ( $this->db->tableExists( $old ) ) {
                        $this->output( "Renaming table $old to $new\n" );
-                       $old = $this->db->addQuotes( $old );
+                       $old = $this->db->realTableName( $old, "quoted" );
+                       $new = $this->db->realTableName( $new, "quoted" );
                        $this->db->query( "ALTER TABLE $old RENAME TO $new" );
                }
        }
@@ -508,9 +516,15 @@ END;
                }
                $this->output( "Altering column '$table.$field' to be DEFERRABLE INITIALLY DEFERRED\n" );
                $conname = $fi->conname();
-               $command = "ALTER TABLE $table DROP CONSTRAINT $conname";
-               $this->db->query( $command );
-               $command = "ALTER TABLE $table ADD CONSTRAINT $conname FOREIGN KEY ($field) REFERENCES $clause DEFERRABLE INITIALLY DEFERRED";
+               if ( $fi->conname() ) {
+                       $conclause = "CONSTRAINT \"$conname\"";
+                       $command = "ALTER TABLE $table DROP CONSTRAINT $conname";
+                       $this->db->query( $command );
+               } else {
+                       $this->output( "Column '$table.$field' does not have a foreign key constraint, will be added\n" );
+                       $conclause = "";
+               }
+               $command = "ALTER TABLE $table ADD $conclause FOREIGN KEY ($field) REFERENCES $clause DEFERRABLE INITIALLY DEFERRED";
                $this->db->query( $command );
        }