Index: trunk/phase3/maintenance/updaters.inc |
— | — | @@ -1268,7 +1268,7 @@ |
1269 | 1269 | |
1270 | 1270 | # Verify that this user is configured correctly |
1271 | 1271 | $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"; |
1273 | 1273 | $config = pg_fetch_result( $wgDatabase->doQuery( $SQL ), 0, 0 ); |
1274 | 1274 | $conf = array(); |
1275 | 1275 | foreach( explode( '*', $config ) as $c ) { |
— | — | @@ -1276,18 +1276,25 @@ |
1277 | 1277 | $conf[$x] = $y; |
1278 | 1278 | } |
1279 | 1279 | $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 | + } |
1283 | 1285 | } |
1284 | 1286 | 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"; |
1286 | 1288 | $newpath[$wgDBts2schema] = 1; |
1287 | 1289 | } |
1288 | 1290 | $searchpath = implode( ',', array_keys( $newpath ) ); |
1289 | 1291 | if( strlen( $searchpath ) ) { |
1290 | 1292 | $wgDatabase->doQuery( "ALTER USER $wgDBuser SET search_path = $searchpath" ); |
| 1293 | + $wgDatabase->doQuery( "SET search_path = $searchpath" ); |
1291 | 1294 | } |
| 1295 | + else { |
| 1296 | + $path = $conf['search_path']; |
| 1297 | + echo "... search_path for user \"$wgDBuser\" looks correct ($path)\n"; |
| 1298 | + } |
1292 | 1299 | $goodconf = array( |
1293 | 1300 | 'client_min_messages' => 'error', |
1294 | 1301 | 'DateStyle' => 'ISO, YMD', |
— | — | @@ -1296,9 +1303,13 @@ |
1297 | 1304 | foreach( array_keys( $goodconf ) AS $key ) { |
1298 | 1305 | $value = $goodconf[$key]; |
1299 | 1306 | 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"; |
1301 | 1308 | $wgDatabase->doQuery( "ALTER USER $wgDBuser SET $key = '$value'" ); |
| 1309 | + $wgDatabase->doQuery( "SET $key = '$value'" ); |
1302 | 1310 | } |
| 1311 | + else { |
| 1312 | + echo "... default value of \"$key\" is correctly set to \"$value\" for user \"$wgDBuser\"\n"; |
| 1313 | + } |
1303 | 1314 | } |
1304 | 1315 | |
1305 | 1316 | $newsequences = array( |
— | — | @@ -1317,6 +1328,7 @@ |
1318 | 1329 | ); |
1319 | 1330 | |
1320 | 1331 | $newcols = array( |
| 1332 | + array("archive", "ar_deleted", "INTEGER NOT NULL DEFAULT 0"), |
1321 | 1333 | array("archive", "ar_len", "INTEGER"), |
1322 | 1334 | array("archive", "ar_page_id", "INTEGER"), |
1323 | 1335 | array("image", "img_sha1", "TEXT NOT NULL DEFAULT ''"), |
— | — | @@ -1390,58 +1402,51 @@ |
1391 | 1403 | |
1392 | 1404 | foreach ($newsequences as $ns) { |
1393 | 1405 | if ($wgDatabase->sequenceExists($ns)) { |
1394 | | - echo "... sequence $ns already exists\n"; |
| 1406 | + echo "... sequence \"$ns\" already exists\n"; |
1395 | 1407 | continue; |
1396 | 1408 | } |
1397 | 1409 | |
1398 | | - echo "... create sequence $ns\n"; |
| 1410 | + echo "Creating sequence \"$ns\"\n"; |
1399 | 1411 | $wgDatabase->query("CREATE SEQUENCE $ns"); |
1400 | 1412 | } |
1401 | 1413 | |
1402 | 1414 | foreach ($newtables as $nt) { |
1403 | 1415 | if ($wgDatabase->tableExists($nt[0])) { |
1404 | | - echo "... table $nt[0] already exists\n"; |
| 1416 | + echo "... table \"$nt[0]\" already exists\n"; |
1405 | 1417 | continue; |
1406 | 1418 | } |
1407 | 1419 | |
1408 | | - echo "... create table $nt[0]\n"; |
| 1420 | + echo "Creating table \"$nt[0]\"\n"; |
1409 | 1421 | dbsource(archive($nt[1])); |
1410 | 1422 | } |
1411 | 1423 | |
1412 | 1424 | ## Needed before newcols |
1413 | 1425 | if ($wgDatabase->tableExists("archive2")) { |
1414 | | - echo "... convert archive2 back to normal archive table\n"; |
| 1426 | + echo "Converting \"archive2\" back to normal archive table\n"; |
1415 | 1427 | if ($wgDatabase->ruleExists("archive", "archive_insert")) { |
1416 | | - echo "... drop rule archive_insert\n"; |
| 1428 | + echo "Dropping rule \"archive_insert\"\n"; |
1417 | 1429 | $wgDatabase->query("DROP RULE archive_insert ON archive"); |
1418 | 1430 | } |
1419 | 1431 | if ($wgDatabase->ruleExists("archive", "archive_delete")) { |
1420 | | - echo "... drop rule archive_delete\n"; |
| 1432 | + echo "Dropping rule \"archive_delete\"\n"; |
1421 | 1433 | $wgDatabase->query("DROP RULE archive_delete ON archive"); |
1422 | 1434 | } |
1423 | | - |
1424 | 1435 | 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"; |
1427 | 1439 | |
1428 | 1440 | foreach ($newcols as $nc) { |
1429 | 1441 | $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]); |
1430 | 1442 | if (!is_null($fi)) { |
1431 | | - echo "... column $nc[0].$nc[1] already exists\n"; |
| 1443 | + echo "... column \"$nc[0].$nc[1]\" already exists\n"; |
1432 | 1444 | continue; |
1433 | 1445 | } |
1434 | 1446 | |
1435 | | - echo "... add column $nc[0].$nc[1]\n"; |
| 1447 | + echo "Adding column \"$nc[0].$nc[1]\"\n"; |
1436 | 1448 | $wgDatabase->query("ALTER TABLE $nc[0] ADD $nc[1] $nc[2]"); |
1437 | 1449 | } |
1438 | 1450 | |
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 | | - |
1446 | 1451 | foreach ($typechanges as $tc) { |
1447 | 1452 | $fi = $wgDatabase->fieldInfo($tc[0], $tc[1]); |
1448 | 1453 | if (is_null($fi)) { |
— | — | @@ -1450,9 +1455,9 @@ |
1451 | 1456 | } |
1452 | 1457 | |
1453 | 1458 | 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"; |
1455 | 1460 | 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"; |
1457 | 1462 | $sql = "ALTER TABLE $tc[0] ALTER $tc[1] TYPE $tc[2]"; |
1458 | 1463 | if (strlen($tc[3])) { |
1459 | 1464 | $sql .= " USING $tc[3]"; |
— | — | @@ -1463,65 +1468,78 @@ |
1464 | 1469 | } |
1465 | 1470 | |
1466 | 1471 | 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" ); |
1471 | 1476 | } |
| 1477 | + else |
| 1478 | + echo "... column \"oldimage.oi_deleted\" is already of type \"smallint\"\n"; |
1472 | 1479 | |
| 1480 | + |
1473 | 1481 | foreach ($newindexes as $ni) { |
1474 | 1482 | 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"; |
1476 | 1484 | continue; |
1477 | 1485 | } |
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]" ); |
1480 | 1488 | } |
1481 | 1489 | |
1482 | 1490 | foreach ($newrules as $nr) { |
1483 | 1491 | 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"; |
1485 | 1493 | continue; |
1486 | 1494 | } |
| 1495 | + echo "Adding rule \"$nr[1]\" to table \"$nr[0]\"\n"; |
1487 | 1496 | dbsource(archive($nr[2])); |
1488 | 1497 | } |
1489 | 1498 | |
1490 | 1499 | 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" ); |
1495 | 1504 | } |
| 1505 | + else |
| 1506 | + echo "... table \"oldimage\" has correct cascade delete foreign key to image\n"; |
1496 | 1507 | |
1497 | 1508 | 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"; |
1499 | 1510 | dbsource(archive('patch-page_deleted.sql')); |
1500 | 1511 | } |
| 1512 | + else |
| 1513 | + echo "... table \"page\" has \"page_deleted\" trigger\n"; |
1501 | 1514 | |
1502 | 1515 | $fi = $wgDatabase->fieldInfo("recentchanges", "rc_cur_id"); |
1503 | 1516 | 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"; |
1505 | 1518 | dbsource(archive('patch-rc_cur_id-not-null.sql')); |
1506 | 1519 | } |
| 1520 | + else |
| 1521 | + echo "... column \"recentchanges.rc_cur_id\" has a NOT NULL constraint\n"; |
1507 | 1522 | |
1508 | 1523 | $pu = pg_describe_index("pagelink_unique"); |
1509 | 1524 | 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"; |
1511 | 1526 | $wgDatabase->query("DROP INDEX pagelink_unique"); |
1512 | 1527 | $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"; |
1515 | 1531 | |
1516 | 1532 | if (is_null($pu)) { |
1517 | | - echo "... adding new pagelink_unique index\n"; |
| 1533 | + echo "Creating index \"pagelink_unique index\"\n"; |
1518 | 1534 | $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"; |
1521 | 1538 | |
1522 | 1539 | 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"; |
1526 | 1544 | dbsource(archive('patch-revision_rev_user_fkey.sql')); |
1527 | 1545 | } |
1528 | 1546 | |
— | — | @@ -1529,30 +1547,29 @@ |
1530 | 1548 | # Add missing extension tables |
1531 | 1549 | foreach ( $wgExtNewTables as $nt ) { |
1532 | 1550 | if ($wgDatabase->tableExists($nt[0])) { |
1533 | | - echo "... table $nt[0] already exists\n"; |
| 1551 | + echo "... table \"$nt[0]\" already exists\n"; |
1534 | 1552 | continue; |
1535 | 1553 | } |
1536 | | - |
1537 | | - echo "... create table $nt[0]\n"; |
| 1554 | + echo "Creating table \"$nt[0]\"\n"; |
1538 | 1555 | dbsource($nt[1]); |
1539 | 1556 | } |
1540 | 1557 | # Add missing extension fields |
1541 | 1558 | foreach ( $wgExtPGNewFields as $nc ) { |
1542 | 1559 | $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]); |
1543 | 1560 | if (!is_null($fi)) { |
1544 | | - echo "... column $nc[0].$nc[1] already exists\n"; |
| 1561 | + echo "... column \"$nc[0].$nc[1]\" already exists\n"; |
1545 | 1562 | continue; |
1546 | 1563 | } |
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]" ); |
1550 | 1566 | } |
1551 | 1567 | # Add missing extension indexes |
1552 | 1568 | foreach ( $wgExtNewIndexes as $ni ) { |
1553 | 1569 | 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"; |
1555 | 1571 | continue; |
1556 | 1572 | } |
| 1573 | + echo "Creating index \"$ni[1]\" on table \"$ni[0]\"\n"; |
1557 | 1574 | dbsource($ni[2]); |
1558 | 1575 | } |
1559 | 1576 | |
Index: trunk/phase3/includes/DatabasePostgres.php |
— | — | @@ -20,6 +20,7 @@ |
21 | 21 | CASE WHEN typname = 'int2' THEN 'smallint' |
22 | 22 | WHEN typname = 'int4' THEN 'integer' |
23 | 23 | WHEN typname = 'int8' THEN 'bigint' |
| 24 | +WHEN typname = 'bpchar' THEN 'char' |
24 | 25 | ELSE typname END AS typname, |
25 | 26 | attnotnull, attlen |
26 | 27 | FROM pg_class, pg_namespace, pg_attribute, pg_type |