r111122 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111121‎ | r111122 | r111123 >
Date:23:25, 9 February 2012
Author:asher
Status:ok
Tags:
Comment:
backport of wmf 1.19 schema migration
Modified paths:
  • /branches/wmf/1.18wmf1/maintenance/archives/patch-af_page_user_token-index.sql (added) (history)
  • /branches/wmf/1.18wmf1/maintenance/archives/patch-ar_sha1.sql (added) (history)
  • /branches/wmf/1.18wmf1/maintenance/archives/patch-page_redirect_namespace_len.sql (added) (history)
  • /branches/wmf/1.18wmf1/maintenance/archives/patch-rev_sha1.sql (added) (history)
  • /branches/wmf/1.18wmf1/maintenance/upgrade-1.19wmf1-1.php (added) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/maintenance/upgrade-1.19wmf1-1.php
@@ -0,0 +1,149 @@
 2+<?php
 3+
 4+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 5+
 6+
 7+class SchemaMigration extends Maintenance {
 8+
 9+ public function __construct() {
 10+ parent::__construct();
 11+ $this->mDescription = "Run Schema Migrations for branch against all wikis";
 12+ $this->addOption( 'secondary', 'Run on secondary / non-prod slaves', false, false );
 13+ }
 14+
 15+ function doAllSchemaChanges() {
 16+ global $wgLBFactoryConf, $wgConf;
 17+
 18+ if ( $this->getOption( 'secondary' ) ) {
 19+ require( dirname( __FILE__ ) . '/../../wmf-config/db-secondary.php' );
 20+ }
 21+
 22+ $sectionLoads = $wgLBFactoryConf['sectionLoads'];
 23+ $sectionsByDB = $wgLBFactoryConf['sectionsByDB'];
 24+
 25+ $rootPass = trim( wfShellExec( '/usr/local/bin/mysql_root_pass' ) );
 26+
 27+ // Compile wiki lists
 28+ $wikisBySection = array();
 29+ foreach ( $wgConf->getLocalDatabases() as $wiki ) {
 30+ if ( isset( $sectionsByDB[$wiki] ) ) {
 31+ $wikisBySection[$sectionsByDB[$wiki]][] = $wiki;
 32+ } else {
 33+ $wikisBySection['DEFAULT'][] = $wiki;
 34+ }
 35+ }
 36+
 37+ // Do the upgrades
 38+ foreach ( $sectionLoads as $section => $loads ) {
 39+ $master = true;
 40+ foreach ( $loads as $server => $load ) {
 41+ if ( $master ) {
 42+ echo "Skipping $section master $server\n";
 43+ $master = false;
 44+ continue;
 45+ }
 46+
 47+ $db = new DatabaseMysql(
 48+ $server,
 49+ 'root',
 50+ $rootPass,
 51+ false, /* dbName */
 52+ 0, /* flags, no transactions */
 53+ '' /* prefix */
 54+ );
 55+
 56+ foreach ( $wikisBySection[$section] as $wiki ) {
 57+ $db->selectDB( $wiki );
 58+ $this->upgradeWiki( $db );
 59+ if ( !$this->getOption( 'secondary' ) ) {
 60+ while ( $db->getLag() > 10 ) {
 61+ echo "Waiting for $server to catch up to master.\n";
 62+ sleep( 20 );
 63+ }
 64+ }
 65+ }
 66+ }
 67+ }
 68+
 69+ echo "All done (except masters).\n";
 70+ }
 71+
 72+ function upgradeWiki( $db ) {
 73+ $wiki = $db->getDBname();
 74+ $server = $db->getServer();
 75+ $missing = "";
 76+
 77+ $upgradeLogRow = $db->selectRow( 'updatelog',
 78+ 'ul_key',
 79+ array( 'ul_key' => '1.19wmf1-1' ),
 80+ __FUNCTION__ );
 81+ if ( $upgradeLogRow ) {
 82+ echo $db->getDBname() . ": already done\n";
 83+ return;
 84+ }
 85+
 86+ echo "$server $wiki 1.19wmf1-1";
 87+
 88+ if ( ! $db->indexExists( 'page', 'page_redirect_namespace_len' ) ) {
 89+ echo " page_redirect_namespace_len index";
 90+ $this->sourceUpgradeFile( $db, dirname( __FILE__ ) . '/archives/patch-page_redirect_namespace_len.sql' );
 91+ if ( ! $db->indexExists( 'page', 'page_redirect_namespace_len' ) ) {
 92+ $missing .= " page_redirect_namespace_len";
 93+ }
 94+ }
 95+
 96+ if ( ! $db->fieldExists( 'archive', 'ar_sha1' ) ) {
 97+ echo " ar_sha1";
 98+ $this->sourceUpgradeFile( $db, dirname( __FILE__ ) . '/archives/patch-ar_sha1.sql' );
 99+ if ( ! $db->fieldExists( 'archive', 'ar_sha1' ) ) {
 100+ $missing .= " ar_sha1";
 101+ }
 102+ }
 103+
 104+ if ( $db->fieldExists( 'article_feedback', 'aa_page_id' ) &&
 105+ ! $db->indexExists( 'article_feedback', 'aa_page_user_token' ) ) {
 106+ echo " aa_page_user_token index";
 107+ $this->sourceUpgradeFile( $db, dirname( __FILE__ ) . '/archives/patch-af_page_user_token-index.sql' );
 108+ if (! $db->indexExists( 'article_feedback', 'aa_page_user_token' ) ) {
 109+ $missing .= " aa_page_user_token";
 110+ }
 111+ }
 112+
 113+ if ( $wiki == "enwiki" ) {
 114+ echo " skipping rev_sha1";
 115+ } else {
 116+ if ( ! $db->fieldExists( 'revision', 'rev_sha1' ) ) {
 117+ echo " rev_sha1";
 118+ $this->sourceUpgradeFile( $db, dirname( __FILE__ ) . '/archives/patch-rev_sha1.sql' );
 119+ if ( ! $db->fieldExists( 'revision', 'rev_sha1' ) ) {
 120+ $missing .= " rev_sha1";
 121+ }
 122+ }
 123+ }
 124+
 125+ if ( $missing ) {
 126+ echo " WARN: missing $missing\n";
 127+ } else {
 128+ $db->insert( 'updatelog',
 129+ array( 'ul_key' => '1.19wmf1-1' ),
 130+ __FUNCTION__ );
 131+ echo " ok\n";
 132+ }
 133+ }
 134+
 135+ function sourceUpgradeFile( $db, $file ) {
 136+ if ( !file_exists( $file ) ) {
 137+ echo "File missing: $file\n";
 138+ exit( 1 );
 139+ }
 140+ $db->sourceFile( $file );
 141+ }
 142+
 143+ function execute() {
 144+ $this->doAllSchemaChanges();
 145+ }
 146+}
 147+
 148+$maintClass = "SchemaMigration";
 149+require_once( RUN_MAINTENANCE_IF_MAIN );
 150+
Index: branches/wmf/1.18wmf1/maintenance/archives/patch-rev_sha1.sql
@@ -0,0 +1,3 @@
 2+-- Adding rev_sha1 field
 3+ALTER TABLE /*$wgDBprefix*/revision
 4+ ADD rev_sha1 varbinary(32) NOT NULL default '';
Index: branches/wmf/1.18wmf1/maintenance/archives/patch-ar_sha1.sql
@@ -0,0 +1,3 @@
 2+-- Adding ar_sha1 field
 3+ALTER TABLE /*$wgDBprefix*/archive
 4+ ADD ar_sha1 varbinary(32) NOT NULL default '';
Index: branches/wmf/1.18wmf1/maintenance/archives/patch-af_page_user_token-index.sql
@@ -0,0 +1,3 @@
 2+ALTER TABLE article_feedback
 3+ ADD INDEX aa_page_user_token (aa_page_id, aa_user_text, aa_user_anon_token, aa_revision),
 4+ DROP INDEX aa_user_page_revision;
Index: branches/wmf/1.18wmf1/maintenance/archives/patch-page_redirect_namespace_len.sql
@@ -0,0 +1,7 @@
 2+--
 3+-- Add the page_redirect_namespace_len index
 4+--
 5+
 6+CREATE INDEX /*i*/page_redirect_namespace_len ON /*_*/page (page_is_redirect, page_namespace, page_len);
 7+
 8+

Status & tagging log