r26210 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26209‎ | r26210 | r26211 >
Date:14:57, 28 September 2007
Author:greg
Status:old
Tags:
Comment:
Postgres updating:
Map bpchar to char
Don't change default search_path if schema not 'mediawiki' in LocalSettings
Clean up the output of updaters.inc
Make sure we set search_path and others for current session when altering user.
Modified paths:
  • /trunk/phase3/includes/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updaters.inc
@@ -1268,7 +1268,7 @@
12691269
12701270 # Verify that this user is configured correctly
12711271 $safeuser = $wgDatabase->addQuotes($wgDBuser);
1272 - $SQL = "SELECT array_to_string(useconfig,'*') FROM pg_user WHERE usename = $safeuser";
 1272+ $SQL = "SELECT array_to_string(useconfig,'*') FROM pg_catalog.pg_user WHERE usename = $safeuser";
12731273 $config = pg_fetch_result( $wgDatabase->doQuery( $SQL ), 0, 0 );
12741274 $conf = array();
12751275 foreach( explode( '*', $config ) as $c ) {
@@ -1276,18 +1276,25 @@
12771277 $conf[$x] = $y;
12781278 }
12791279 $newpath = array();
1280 - if( !array_key_exists( 'search_path', $conf ) or strpos( $conf['search_path'],$wgDBmwschema ) === false ) {
1281 - print "Adding in schema \"$wgDBmwschema\" to search_path for user \"$wgDBuser\"\n";
1282 - $newpath[$wgDBmwschema] = 1;
 1280+ if( $wgDBmwschema === 'mediawiki' ) {
 1281+ if (!array_key_exists( 'search_path', $conf ) or strpos( $conf['search_path'],$wgDBmwschema ) === false ) {
 1282+ echo "Adding in schema \"$wgDBmwschema\" to search_path for user \"$wgDBuser\"\n";
 1283+ $newpath[$wgDBmwschema] = 1;
 1284+ }
12831285 }
12841286 if( !array_key_exists( 'search_path', $conf ) or strpos( $conf['search_path'],$wgDBts2schema ) === false ) {
1285 - print "Adding in schema \"$wgDBts2schema\" to search_path for user \"$wgDBuser\"\n";
 1287+ echo "Adding in schema \"$wgDBts2schema\" to search_path for user \"$wgDBuser\"\n";
12861288 $newpath[$wgDBts2schema] = 1;
12871289 }
12881290 $searchpath = implode( ',', array_keys( $newpath ) );
12891291 if( strlen( $searchpath ) ) {
12901292 $wgDatabase->doQuery( "ALTER USER $wgDBuser SET search_path = $searchpath" );
 1293+ $wgDatabase->doQuery( "SET search_path = $searchpath" );
12911294 }
 1295+ else {
 1296+ $path = $conf['search_path'];
 1297+ echo "... search_path for user \"$wgDBuser\" looks correct ($path)\n";
 1298+ }
12921299 $goodconf = array(
12931300 'client_min_messages' => 'error',
12941301 'DateStyle' => 'ISO, YMD',
@@ -1296,9 +1303,13 @@
12971304 foreach( array_keys( $goodconf ) AS $key ) {
12981305 $value = $goodconf[$key];
12991306 if( !array_key_exists( $key, $conf ) or $conf[$key] !== $value ) {
1300 - print "Setting $key to '$value' for user \"$wgDBuser\"\n";
 1307+ echo "Setting $key to '$value' for user \"$wgDBuser\"\n";
13011308 $wgDatabase->doQuery( "ALTER USER $wgDBuser SET $key = '$value'" );
 1309+ $wgDatabase->doQuery( "SET $key = '$value'" );
13021310 }
 1311+ else {
 1312+ echo "... default value of \"$key\" is correctly set to \"$value\" for user \"$wgDBuser\"\n";
 1313+ }
13031314 }
13041315
13051316 $newsequences = array(
@@ -1317,6 +1328,7 @@
13181329 );
13191330
13201331 $newcols = array(
 1332+ array("archive", "ar_deleted", "INTEGER NOT NULL DEFAULT 0"),
13211333 array("archive", "ar_len", "INTEGER"),
13221334 array("archive", "ar_page_id", "INTEGER"),
13231335 array("image", "img_sha1", "TEXT NOT NULL DEFAULT ''"),
@@ -1390,58 +1402,51 @@
13911403
13921404 foreach ($newsequences as $ns) {
13931405 if ($wgDatabase->sequenceExists($ns)) {
1394 - echo "... sequence $ns already exists\n";
 1406+ echo "... sequence \"$ns\" already exists\n";
13951407 continue;
13961408 }
13971409
1398 - echo "... create sequence $ns\n";
 1410+ echo "Creating sequence \"$ns\"\n";
13991411 $wgDatabase->query("CREATE SEQUENCE $ns");
14001412 }
14011413
14021414 foreach ($newtables as $nt) {
14031415 if ($wgDatabase->tableExists($nt[0])) {
1404 - echo "... table $nt[0] already exists\n";
 1416+ echo "... table \"$nt[0]\" already exists\n";
14051417 continue;
14061418 }
14071419
1408 - echo "... create table $nt[0]\n";
 1420+ echo "Creating table \"$nt[0]\"\n";
14091421 dbsource(archive($nt[1]));
14101422 }
14111423
14121424 ## Needed before newcols
14131425 if ($wgDatabase->tableExists("archive2")) {
1414 - echo "... convert archive2 back to normal archive table\n";
 1426+ echo "Converting \"archive2\" back to normal archive table\n";
14151427 if ($wgDatabase->ruleExists("archive", "archive_insert")) {
1416 - echo "... drop rule archive_insert\n";
 1428+ echo "Dropping rule \"archive_insert\"\n";
14171429 $wgDatabase->query("DROP RULE archive_insert ON archive");
14181430 }
14191431 if ($wgDatabase->ruleExists("archive", "archive_delete")) {
1420 - echo "... drop rule archive_delete\n";
 1432+ echo "Dropping rule \"archive_delete\"\n";
14211433 $wgDatabase->query("DROP RULE archive_delete ON archive");
14221434 }
1423 -
14241435 dbsource(archive("patch-remove-archive2.sql"));
1425 - } else
1426 - echo "... obsolete archive2 not present\n";
 1436+ }
 1437+ else
 1438+ echo "... obsolete table \"archive2\" does not exist\n";
14271439
14281440 foreach ($newcols as $nc) {
14291441 $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
14301442 if (!is_null($fi)) {
1431 - echo "... column $nc[0].$nc[1] already exists\n";
 1443+ echo "... column \"$nc[0].$nc[1]\" already exists\n";
14321444 continue;
14331445 }
14341446
1435 - echo "... add column $nc[0].$nc[1]\n";
 1447+ echo "Adding column \"$nc[0].$nc[1]\"\n";
14361448 $wgDatabase->query("ALTER TABLE $nc[0] ADD $nc[1] $nc[2]");
14371449 }
14381450
1439 - ## Needed before column changes
1440 - if (is_null($wgDatabase->fieldInfo("archive", "ar_deleted"))) {
1441 - echo "... add archive.ar_deleted\n";
1442 - dbsource(archive("patch-archive-ar_deleted.sql"));
1443 - } else
1444 - echo "... archive.ar_deleted already exists\n";
1445 -
14461451 foreach ($typechanges as $tc) {
14471452 $fi = $wgDatabase->fieldInfo($tc[0], $tc[1]);
14481453 if (is_null($fi)) {
@@ -1450,9 +1455,9 @@
14511456 }
14521457
14531458 if ($fi->type() === $tc[2])
1454 - echo "... $tc[0].$tc[1] is already $tc[2]\n";
 1459+ echo "... column \"$tc[0].$tc[1]\" is already of type \"$tc[2]\"\n";
14551460 else {
1456 - echo "... change $tc[0].$tc[1] from {$fi->type()} to $tc[2]\n";
 1461+ echo "Changing column type of \"$tc[0].$tc[1]\" from \"{$fi->type()}\" to \"$tc[2]\"\n";
14571462 $sql = "ALTER TABLE $tc[0] ALTER $tc[1] TYPE $tc[2]";
14581463 if (strlen($tc[3])) {
14591464 $sql .= " USING $tc[3]";
@@ -1463,65 +1468,78 @@
14641469 }
14651470
14661471 if ($wgDatabase->fieldInfo('oldimage','oi_deleted')->type() !== 'smallint') {
1467 - echo "... change oldimage.oi_deleted to smallint";
1468 - $wgDatabase->query("ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT");
1469 - $wgDatabase->query("ALTER TABLE oldimage ALTER oi_deleted TYPE SMALLINT USING (oi_deleted::smallint)");
1470 - $wgDatabase->query("ALTER TABLE oldimage ALTER oi_deleted SET DEFAULT 0");
 1472+ echo "Changing \"oldimage.oi_deleted\" to type \"smallint\"\n";
 1473+ $wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT" );
 1474+ $wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted TYPE SMALLINT USING (oi_deleted::smallint)" );
 1475+ $wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted SET DEFAULT 0" );
14711476 }
 1477+ else
 1478+ echo "... column \"oldimage.oi_deleted\" is already of type \"smallint\"\n";
14721479
 1480+
14731481 foreach ($newindexes as $ni) {
14741482 if (pg_index_exists($ni[0], $ni[1])) {
1475 - echo "... index $ni[1] on $ni[0] already exists\n";
 1483+ echo "... index \"$ni[1]\" on table \"$ni[0]\" already exists\n";
14761484 continue;
14771485 }
1478 - $wgDatabase->query("CREATE INDEX $ni[1] ON $ni[0] $ni[2]");
1479 - echo "create index $ni[1]\n";
 1486+ echo "Creating index \"$ni[1]\" on table \"$ni[0]\" $ni[2]\n";
 1487+ $wgDatabase->query( "CREATE INDEX $ni[1] ON $ni[0] $ni[2]" );
14801488 }
14811489
14821490 foreach ($newrules as $nr) {
14831491 if ($wgDatabase->ruleExists($nr[0], $nr[1])) {
1484 - echo "... rule $nr[1] on $nr[0] already exists\n";
 1492+ echo "... rule \"$nr[1]\" on table \"$nr[0]\" already exists\n";
14851493 continue;
14861494 }
 1495+ echo "Adding rule \"$nr[1]\" to table \"$nr[0]\"\n";
14871496 dbsource(archive($nr[2]));
14881497 }
14891498
14901499 if ($wgDatabase->hasConstraint("oldimage_oi_name_fkey")) {
1491 - echo "... change oldimage to CASCADE DELETE on image deletion\n";
1492 - $wgDatabase->query("ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey");
1493 - $wgDatabase->query("ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascade ".
1494 - "FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE");
 1500+ echo "Making foriegn key on table \"oldimage\" (to image) a cascade delete\n";
 1501+ $wgDatabase->query( "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" );
 1502+ $wgDatabase->query( "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascade ".
 1503+ "FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE" );
14951504 }
 1505+ else
 1506+ echo "... table \"oldimage\" has correct cascade delete foreign key to image\n";
14961507
14971508 if (!$wgDatabase->triggerExists("page", "page_deleted")) {
1498 - echo "... create page_deleted trigger\n";
 1509+ echo "Adding function and trigger \"page_deleted\" to table \"page\"\n";
14991510 dbsource(archive('patch-page_deleted.sql'));
15001511 }
 1512+ else
 1513+ echo "... table \"page\" has \"page_deleted\" trigger\n";
15011514
15021515 $fi = $wgDatabase->fieldInfo("recentchanges", "rc_cur_id");
15031516 if (!$fi->nullable()) {
1504 - echo "... remove NOT NULL constraint on recentchanges.rc_cur_id\n";
 1517+ echo "Removing NOT NULL constraint from \"recentchanges.rc_cur_id\"\n";
15051518 dbsource(archive('patch-rc_cur_id-not-null.sql'));
15061519 }
 1520+ else
 1521+ echo "... column \"recentchanges.rc_cur_id\" has a NOT NULL constraint\n";
15071522
15081523 $pu = pg_describe_index("pagelink_unique");
15091524 if (!is_null($pu) && ($pu[0] != "pl_from" || $pu[1] != "pl_namespace" || $pu[2] != "pl_title")) {
1510 - echo "... dropping obsolete pagelink_unique index\n";
 1525+ echo "Dropping obsolete version of index \"pagelink_unique index\"\n";
15111526 $wgDatabase->query("DROP INDEX pagelink_unique");
15121527 $pu = null;
1513 - } else
1514 - echo "... obsolete pagelink_unique index not present\n";
 1528+ }
 1529+ else
 1530+ echo "... obsolete version of index \"pagelink_unique index\" does not exist\n";
15151531
15161532 if (is_null($pu)) {
1517 - echo "... adding new pagelink_unique index\n";
 1533+ echo "Creating index \"pagelink_unique index\"\n";
15181534 $wgDatabase->query("CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)");
1519 - } else
1520 - echo "... already have current pagelink_unique index\n";
 1535+ }
 1536+ else
 1537+ echo "... index \"pagelink_unique_index\" aready exists\n";
15211538
15221539 if (pg_fkey_deltype("revision_rev_user_fkey") == 'r') {
1523 - echo "... revision_rev_user_fkey is already ON DELETE RESTRICT\n";
1524 - } else {
1525 - echo "... change revision_rev_user_fkey to ON DELETE RESTRICT\n";
 1540+ echo "... constraint \"revision_rev_user_fkey\" is ON DELETE RESTRICT\n";
 1541+ }
 1542+ else {
 1543+ echo "Changing constraint \"revision_rev_user_fkey\" to ON DELETE RESTRICT\n";
15261544 dbsource(archive('patch-revision_rev_user_fkey.sql'));
15271545 }
15281546
@@ -1529,30 +1547,29 @@
15301548 # Add missing extension tables
15311549 foreach ( $wgExtNewTables as $nt ) {
15321550 if ($wgDatabase->tableExists($nt[0])) {
1533 - echo "... table $nt[0] already exists\n";
 1551+ echo "... table \"$nt[0]\" already exists\n";
15341552 continue;
15351553 }
1536 -
1537 - echo "... create table $nt[0]\n";
 1554+ echo "Creating table \"$nt[0]\"\n";
15381555 dbsource($nt[1]);
15391556 }
15401557 # Add missing extension fields
15411558 foreach ( $wgExtPGNewFields as $nc ) {
15421559 $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
15431560 if (!is_null($fi)) {
1544 - echo "... column $nc[0].$nc[1] already exists\n";
 1561+ echo "... column \"$nc[0].$nc[1]\" already exists\n";
15451562 continue;
15461563 }
1547 -
1548 - echo "... add column $nc[0].$nc[1]\n";
1549 - $wgDatabase->query("ALTER TABLE $nc[0] ADD $nc[1] $nc[2]");
 1564+ echo "Adding column \"$nc[0].$nc[1]\"\n";
 1565+ $wgDatabase->query( "ALTER TABLE $nc[0] ADD $nc[1] $nc[2]" );
15501566 }
15511567 # Add missing extension indexes
15521568 foreach ( $wgExtNewIndexes as $ni ) {
15531569 if (pg_index_exists($ni[0], $ni[1])) {
1554 - echo "... index $ni[1] on $ni[0] already exists\n";
 1570+ echo "... index \"$ni[1]\" on table \"$ni[0]\" already exists\n";
15551571 continue;
15561572 }
 1573+ echo "Creating index \"$ni[1]\" on table \"$ni[0]\"\n";
15571574 dbsource($ni[2]);
15581575 }
15591576
Index: trunk/phase3/includes/DatabasePostgres.php
@@ -20,6 +20,7 @@
2121 CASE WHEN typname = 'int2' THEN 'smallint'
2222 WHEN typname = 'int4' THEN 'integer'
2323 WHEN typname = 'int8' THEN 'bigint'
 24+WHEN typname = 'bpchar' THEN 'char'
2425 ELSE typname END AS typname,
2526 attnotnull, attlen
2627 FROM pg_class, pg_namespace, pg_attribute, pg_type

Follow-up revisions

RevisionCommit summaryAuthorDate
r26257Merged revisions 26134-26247 via svnmerge from...david19:06, 30 September 2007

Status & tagging log