Add $wgExtPGAlteredFields
authorGreg Sabino Mullane <greg@users.mediawiki.org>
Mon, 20 Apr 2009 22:43:42 +0000 (22:43 +0000)
committerGreg Sabino Mullane <greg@users.mediawiki.org>
Mon, 20 Apr 2009 22:43:42 +0000 (22:43 +0000)
RELEASE-NOTES
maintenance/updaters.inc

index cbaae3a..849d2b3 100644 (file)
@@ -169,6 +169,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   {{REVISIONTIMESTAMP}}  (and friends) and {{REVISIONUSER}} magic words
 * (bug 18529) New hook: SoftwareInfo for adding information about the software
   to Special:Version
+* Added $wgExtPGAlteredFields to allow extensions to easily alter the data 
+  type of columns when using the Postgres backend.
+
 
 === Bug fixes in 1.15 ===
 * (bug 16968) Special:Upload no longer throws useless warnings.
index ddf7ca7..1e72ffb 100644 (file)
@@ -176,7 +176,8 @@ $wgUpdates = array(
 # $wgDBtype should be checked to specifiy the proper file
 $wgExtNewTables = array(); // table, dir
 $wgExtNewFields = array(); // table, column, dir
-$wgExtPGNewFields = array(); // table, column attributes; for PostgreSQL
+$wgExtPGNewFields = array(); // table, column, column attributes; for PostgreSQL
+$wgExtPGAlteredFields = array(); // table, column, new type, conversion method; for PostgreSQL
 $wgExtNewIndexes = array(); // table, index, dir
 
 # Helper function: check if the given key is present in the updatelog table.
@@ -1807,7 +1808,7 @@ function do_postgres_updates() {
                dbsource(archive('patch-ipb_address_unique.sql'));
        }
 
-       global $wgExtNewTables, $wgExtPGNewFields, $wgExtNewIndexes;
+       global $wgExtNewTables, $wgExtPGNewFields, $wgExtPGAlteredFields, $wgExtNewIndexes;
        # Add missing extension tables
        foreach ( $wgExtNewTables as $nt ) {
                if ($wgDatabase->tableExists($nt[0])) {
@@ -1827,6 +1828,26 @@ function do_postgres_updates() {
                wfOut( "Adding column \"$nc[0].$nc[1]\"\n" );
                $wgDatabase->query( "ALTER TABLE $nc[0] ADD $nc[1] $nc[2]" );
        }
+       # Change altered columns
+       foreach ( $wgExtPGAlteredFields as $nc ) {
+               $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
+               if (is_null($fi)) {
+                       wfOut( "WARNING! Column \"$nc[0].$nc[1]\" does not exist but had an alter request! Please report this.\n" );
+                       continue;
+               }
+               $oldtype = $fi->type();
+               $newtype = strtolower( $nc[2] );
+               if ($oldtype === $newtype) {
+                       wfOut( "... column \"$nc[0].$nc[1]\" has correct type of \"$newtype\"\n" );
+                       continue;
+               }
+               $command = "ALTER TABLE $nc[0] ALTER $nc[1] TYPE $nc[2]";
+               if ( isset( $nc[3] ) ) {
+                       $command .= " USING $nc[3]";
+               }
+               wfOut( "Altering column \"$nc[0].$nc[1]\" from type \"$oldtype\" to \"$newtype\"\n" );
+               $wgDatabase->query( $command );
+       }
        # Add missing extension indexes
        foreach ( $wgExtNewIndexes as $ni ) {
                if (pg_index_exists($ni[0], $ni[1])) {