From 0a93752af67fe6d31ba279c11e376ce5c145a4c3 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 22 Apr 2007 14:04:06 +0000 Subject: [PATCH] * Removed mysql5 SQL files, obviously we're collectively incapable of keeping them up to date. They were littered with errors. The only deliberate difference appears to be the table character set, which can be adjusted programatically using a variable. * Added table option variable to the SQL patch files, so now upgrading a non-standard schema won't leave your database horribly corrupted. * Added sql.php, for sourcing SQL files with MediaWiki variable substitution. * Disable MySQL's strict mode at session start for MySQL 4.1+, to avoid the various problems that occur when it is on. --- config/index.php | 75 +- includes/Database.php | 42 +- includes/DefaultSettings.php | 5 + maintenance/archives/patch-categorylinks.sql | 2 +- maintenance/archives/patch-externallinks.sql | 2 +- maintenance/archives/patch-filearchive.sql | 2 +- maintenance/archives/patch-interwiki.sql | 2 +- maintenance/archives/patch-ipb_anon_only.sql | 2 +- maintenance/archives/patch-job.sql | 2 +- maintenance/archives/patch-langlinks.sql | 2 +- maintenance/archives/patch-linkscc.sql | 2 +- maintenance/archives/patch-linktables.sql | 8 +- maintenance/archives/patch-logging.sql | 2 +- maintenance/archives/patch-math.sql | 2 +- maintenance/archives/patch-objectcache.sql | 2 +- .../archives/patch-page_restrictions.sql | 2 +- maintenance/archives/patch-pagelinks.sql | 2 +- maintenance/archives/patch-parsercache.sql | 2 +- maintenance/archives/patch-querycache.sql | 2 +- maintenance/archives/patch-querycacheinfo.sql | 2 +- maintenance/archives/patch-querycachetwo.sql | 2 +- maintenance/archives/patch-redirect.sql | 2 +- maintenance/archives/patch-templatelinks.sql | 2 +- maintenance/archives/patch-transcache.sql | 2 +- maintenance/archives/patch-user_groups.sql | 2 +- maintenance/archives/patch-user_rights.sql | 2 +- maintenance/archives/patch-userlevels.sql | 4 +- maintenance/archives/patch-validate.sql | 2 +- maintenance/mysql5/tables-binary.sql | 1158 ----------------- maintenance/mysql5/tables.sql | 1149 ---------------- maintenance/sql.php | 67 + maintenance/tables.sql | 64 +- 32 files changed, 221 insertions(+), 2397 deletions(-) delete mode 100644 maintenance/mysql5/tables-binary.sql delete mode 100644 maintenance/mysql5/tables.sql create mode 100644 maintenance/sql.php diff --git a/config/index.php b/config/index.php index b392a6d7c2..e1ec6acaed 100644 --- a/config/index.php +++ b/config/index.php @@ -226,6 +226,26 @@ class ConfigData { function getSitename() { return $this->getEncoded( $this->Sitename ); } function getSysopName() { return $this->getEncoded( $this->SysopName ); } function getSysopPass() { return $this->getEncoded( $this->SysopPass ); } + + function setSchema( $schema ) { + $this->DBschema = $schema; + switch ( $this->DBschema ) { + case 'mysql5': + $this->DBTableOptions = 'ENGINE=InnoDB, DEFAULT CHARSET=utf8'; + $this->DBmysql5 = 'true'; + break; + case 'mysql5-binary': + $this->DBTableOptions = 'ENGINE=InnoDB, DEFAULT CHARSET=binary'; + $this->DBmysql5 = 'true'; + break; + default: + $this->DBTableOptions = 'TYPE=InnoDB'; + $this->DBmysql5 = 'false'; + } + # Set the global for use during install + global $wgDBTableOptions; + $wgDBTableOptions = $this->DBTableOptions; + } } ?> @@ -522,10 +542,7 @@ print "
  • Environment check ## MySQL specific: $conf->DBprefix = importPost( "DBprefix" ); - $conf->DBschema = importPost( "DBschema", "mysql4" ); - $conf->DBmysql5 = ($conf->DBschema == "mysql5" || - $conf->DBschema == "mysql5-binary") - ? "true" : "false"; + $conf->setSchema( importPost( "DBschema", "mysql4" ) ); $conf->LanguageCode = importPost( "LanguageCode", "en" ); ## Postgres specific: @@ -813,6 +830,32 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) { print "
  • There are already MediaWiki tables in this database. Checking if updates are needed...
  • \n"; + # Determine existing default character set + if ( $wgDatabase->tableExists( "revision" ) ) { + $revision = $wgDatabase->escapeLike( $conf->DBprefix . 'revision' ); + $res = $wgDatabase->query( "SHOW TABLE STATUS LIKE '$revision'" ); + $row = $wgDatabase->fetchObject( $res ); + if ( !$row ) { + echo "
  • SHOW TABLE STATUS query failed!
  • \n"; + $existingSchema = false; + } elseif ( preg_match( '/^latin1/', $row->Collation ) ) { + $existingSchema = 'mysql4'; + } elseif ( preg_match( '/^utf8/', $row->Collation ) ) { + $existingSchema = 'mysql5'; + } elseif ( preg_match( '/^binary/', $row->Collation ) ) { + $existingSchema = 'mysql5-binary'; + } else { + $existingSchema = false; + echo "
  • Warning: Unrecognised existing collation
  • \n"; + } + if ( $existingSchema && $existingSchema != $conf->DBschema ) { + print "
  • Warning: you requested the {$conf->DBschema} schema, " . + "but the existing database has the $existingSchema schema. This upgrade script ". + "can't convert it, so it will remain $existingSchema.
  • \n"; + $conf->setSchema( $existingSchema ); + } + } + # Create user if required (todo: other databases) if ( $conf->Root && $conf->DBtype == 'mysql') { $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 ); @@ -828,33 +871,18 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { dbsource( "../maintenance/users.sql", $wgDatabase ); } } - print "
    \n";
    +			print "
    \n";
     			chdir( ".." );
     			flush();
     			do_all_updates();
     			chdir( "config" );
     			print "
    \n"; - print "
  • Finished update checks.
  • \n"; + print "