From 743766fbb34ff04df6aaeee594cf921b7ef5d7cc Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Mon, 20 Apr 2009 22:43:42 +0000 Subject: [PATCH] Add $wgExtPGAlteredFields --- RELEASE-NOTES | 3 +++ maintenance/updaters.inc | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index cbaae3af64..849d2b38d2 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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. diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index ddf7ca7821..1e72ffb149 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -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])) { -- 2.20.1