PostgreSQL: Drop unneeded foreign key constraint
[lhc/web/wiklou.git] / includes / installer / PostgresUpdater.php
index 8404c2d..9e41276 100644 (file)
@@ -415,6 +415,15 @@ class PostgresUpdater extends DatabaseUpdater {
                        array( 'addPgIndex', 'page_props', 'pp_propname_sortkey_page',
                                        '( pp_propname, pp_sortkey, pp_page ) WHERE ( pp_sortkey IS NOT NULL )' ),
                        array( 'addPgField', 'page', 'page_lang', 'TEXT default NULL' ),
+                       array( 'addPgField', 'pagelinks', 'pl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ),
+                       array( 'addPgField', 'templatelinks', 'tl_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ),
+                       array( 'addPgField', 'imagelinks', 'il_from_namespace', 'INTEGER NOT NULL DEFAULT 0' ),
+
+                       // 1.25
+                       array( 'dropTable', 'hitcounter' ),
+                       array( 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ),
+                       array( 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ),
+                       array( 'dropFkey', 'recentchanges', 'rc_cur_id' )
                );
        }
 
@@ -694,7 +703,7 @@ END;
                        $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
                } else {
                        $this->output( "Purging data from cache table '$table'\n" );
-                       $this->db->query("DELETE from $table" );
+                       $this->db->query( "DELETE from $table" );
                        $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 ) ) {
@@ -766,6 +775,24 @@ END;
                }
        }
 
+       protected function dropFkey( $table, $field ) {
+               $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;
+               }
+               $conname = $fi->conname();
+               if ( $fi->conname() ) {
+                       $this->output( "Dropping foreign key constraint on '$table.$field'\n" );
+                       $conclause = "CONSTRAINT \"$conname\"";
+                       $command = "ALTER TABLE $table DROP CONSTRAINT $conname";
+                       $this->db->query( $command );
+               } else {
+                       $this->output( "Foreign key constraint on '$table.$field' already does not exist\n" );
+               };
+       }
+
        protected function changeFkeyDeferrable( $table, $field, $clause ) {
                $fi = $this->db->fieldInfo( $table, $field );
                if ( is_null( $fi ) ) {