Index: branches/wmf/1.18wmf1/maintenance/upgrade-1.18wmf1-1.php |
— | — | @@ -1,109 +1,128 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -require( dirname( __FILE__ ) . '/commandLine.inc' ); |
| 4 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
5 | 5 | |
6 | | -doAllSchemaChanges(); |
7 | 6 | |
8 | | -function doAllSchemaChanges() { |
9 | | - global $wgLBFactoryConf, $wgConf; |
| 7 | +class SchemaMigration extends Maintenance { |
10 | 8 | |
11 | | - $sectionLoads = $wgLBFactoryConf['sectionLoads']; |
12 | | - $sectionsByDB = $wgLBFactoryConf['sectionsByDB']; |
13 | | - $rootPass = trim( wfShellExec( '/home/wikipedia/bin/mysql_root_pass' ) ); |
| 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 | 14 | |
15 | | - // Compile wiki lists |
16 | | - $wikisBySection = array(); |
17 | | - foreach ( $wgConf->getLocalDatabases() as $wiki ) { |
18 | | - if ( isset( $sectionsByDB[$wiki] ) ) { |
19 | | - $wikisBySection[$sectionsByDB[$wiki]][] = $wiki; |
20 | | - } else { |
21 | | - $wikisBySection['DEFAULT'][] = $wiki; |
22 | | - } |
23 | | - } |
| 15 | + function doAllSchemaChanges() { |
| 16 | + global $wgLBFactoryConf, $wgConf; |
24 | 17 | |
25 | | - // Do the upgrades |
26 | | - foreach ( $sectionLoads as $section => $loads ) { |
27 | | - $master = true; |
28 | | - foreach ( $loads as $server => $load ) { |
29 | | - if ( $master ) { |
30 | | - echo "Skipping $section master $server\n"; |
31 | | - $master = false; |
32 | | - continue; |
33 | | - } |
| 18 | + if ( $this->getOption( 'secondary' ) ) { |
| 19 | + require( dirname( __FILE__ ) . '/../../wmf-config/db-secondary.php' ); |
| 20 | + } |
34 | 21 | |
35 | | - $db = new DatabaseMysql( |
36 | | - $server, |
37 | | - 'root', |
38 | | - $rootPass, |
39 | | - false, /* dbName */ |
40 | | - 0, /* flags, no transactions */ |
41 | | - '' /* prefix */ |
42 | | - ); |
| 22 | + $sectionLoads = $wgLBFactoryConf['sectionLoads']; |
| 23 | + $sectionsByDB = $wgLBFactoryConf['sectionsByDB']; |
43 | 24 | |
44 | | - foreach ( $wikisBySection[$section] as $wiki ) { |
45 | | - $db->selectDB( $wiki ); |
46 | | - upgradeWiki( $db ); |
47 | | - while ( $db->getLag() > 10 ) { |
48 | | - echo "Waiting for $server to catch up to master.\n"; |
49 | | - sleep( 60 ); |
50 | | - } |
51 | | - } |
52 | | - } |
53 | | - } |
| 25 | + $rootPass = trim( wfShellExec( '/home/wikipedia/bin/mysql_root_pass' ) ); |
54 | 26 | |
55 | | - echo "All done (except masters).\n"; |
56 | | -} |
| 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 | + } |
57 | 36 | |
58 | | -function upgradeWiki( $db ) { |
59 | | - $wiki = $db->getDBname(); |
60 | | - $server = $db->getServer(); |
| 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 | + } |
61 | 46 | |
62 | | - $upgradeLogRow = $db->selectRow( 'updatelog', |
63 | | - 'ul_key', |
64 | | - array( 'ul_key' => '1.18wmf1-1' ), |
65 | | - __FUNCTION__ ); |
66 | | - if ( $upgradeLogRow ) { |
67 | | - echo $db->getDBname() . ": already done\n"; |
68 | | - return; |
69 | | - } |
| 47 | + $db = new DatabaseMysql( |
| 48 | + $server, |
| 49 | + 'root', |
| 50 | + $rootPass, |
| 51 | + false, /* dbName */ |
| 52 | + 0, /* flags, no transactions */ |
| 53 | + '' /* prefix */ |
| 54 | + ); |
70 | 55 | |
71 | | - echo "$server $wiki 1.18wmf1-1"; |
| 56 | + foreach ( $wikisBySection[$section] as $wiki ) { |
| 57 | + $db->selectDB( $wiki ); |
| 58 | + $this->upgradeWiki( $db ); |
| 59 | + while ( $db->getLag() > 10 ) { |
| 60 | + echo "Waiting for $server to catch up to master.\n"; |
| 61 | + sleep( 60 ); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + } |
72 | 66 | |
73 | | - sourceUpgradeFile( $db, dirname( __FILE__ ) .'/schema-changes-1.18wmf1-1.sql' ); |
74 | | - |
75 | | - if ( isFlaggedRevsWiki( $wiki ) ) { |
76 | | - echo " FlaggedRevs"; |
77 | | - sourceUpgradeFile( $db, dirname(__FILE__).'/../extensions/FlaggedRevs/schema/mysql/' . |
78 | | - 'patch-fr_page_rev-index-wmf1.8.sql' ); |
79 | | - } |
| 67 | + echo "All done (except masters).\n"; |
| 68 | + } |
80 | 69 | |
81 | | - if ( $db->fieldExists( 'article_feedback', 'aa_page_id' ) ) { |
82 | | - echo " aa_page_id index"; |
83 | | - sourceUpgradeFile( $db, dirname( __FILE__ ) . '/../extensions/ArticleFeedback/sql/AddArticleFeedbackPageIndex.sql' ); |
84 | | - } |
| 70 | + function upgradeWiki( $db ) { |
| 71 | + $wiki = $db->getDBname(); |
| 72 | + $server = $db->getServer(); |
85 | 73 | |
86 | | - $db->insert( 'updatelog', |
87 | | - array( 'ul_key' => '1.18wmf1-1' ), |
88 | | - __FUNCTION__ ); |
89 | | - echo " ok\n"; |
90 | | -} |
| 74 | + $upgradeLogRow = $db->selectRow( 'updatelog', |
| 75 | + 'ul_key', |
| 76 | + array( 'ul_key' => '1.18wmf1-1' ), |
| 77 | + __FUNCTION__ ); |
| 78 | + if ( $upgradeLogRow ) { |
| 79 | + echo $db->getDBname() . ": already done\n"; |
| 80 | + return; |
| 81 | + } |
91 | 82 | |
92 | | -function isFlaggedRevsWiki( $wiki ) { |
93 | | - static $dblist; |
94 | | - global $IP; |
| 83 | + echo "$server $wiki 1.18wmf1-1"; |
95 | 84 | |
96 | | - if ( $dblist === null ) { |
97 | | - $dblist = array_map( 'trim', file( "$IP/../flaggedrevs.dblist" ) ); |
98 | | - } |
99 | | - return in_array( $wiki, $dblist ); |
100 | | -} |
| 85 | + $this->sourceUpgradeFile( $db, dirname( __FILE__ ) .'/schema-changes-1.18wmf1-1.sql' ); |
| 86 | + |
| 87 | + if ( $this->isFlaggedRevsWiki( $wiki ) ) { |
| 88 | + echo " FlaggedRevs"; |
| 89 | + $this->sourceUpgradeFile( $db, dirname(__FILE__).'/../extensions/FlaggedRevs/schema/mysql/' . |
| 90 | + 'patch-fr_page_rev-index-wmf1.8.sql' ); |
| 91 | + } |
101 | 92 | |
102 | | -function sourceUpgradeFile( $db, $file ) { |
103 | | - if ( !file_exists( $file ) ) { |
104 | | - echo "File missing: $file\n"; |
105 | | - exit( 1 ); |
106 | | - } |
107 | | - $db->sourceFile( $file ); |
| 93 | + if ( $db->fieldExists( 'article_feedback', 'aa_page_id' ) ) { |
| 94 | + echo " aa_page_id index"; |
| 95 | + $this->sourceUpgradeFile( $db, dirname( __FILE__ ) . '/../extensions/ArticleFeedback/sql/AddArticleFeedbackPageIndex.sql' ); |
| 96 | + } |
| 97 | + |
| 98 | + $db->insert( 'updatelog', |
| 99 | + array( 'ul_key' => '1.18wmf1-1' ), |
| 100 | + __FUNCTION__ ); |
| 101 | + echo " ok\n"; |
| 102 | + } |
| 103 | + |
| 104 | + function isFlaggedRevsWiki( $wiki ) { |
| 105 | + static $dblist; |
| 106 | + global $IP; |
| 107 | + |
| 108 | + if ( $dblist === null ) { |
| 109 | + $dblist = array_map( 'trim', file( "$IP/../flaggedrevs.dblist" ) ); |
| 110 | + } |
| 111 | + return in_array( $wiki, $dblist ); |
| 112 | + } |
| 113 | + |
| 114 | + function sourceUpgradeFile( $db, $file ) { |
| 115 | + if ( !file_exists( $file ) ) { |
| 116 | + echo "File missing: $file\n"; |
| 117 | + exit( 1 ); |
| 118 | + } |
| 119 | + $db->sourceFile( $file ); |
| 120 | + } |
| 121 | + |
| 122 | + function execute() { |
| 123 | + $this->doAllSchemaChanges(); |
| 124 | + } |
108 | 125 | } |
109 | 126 | |
| 127 | +$maintClass = "SchemaMigration"; |
| 128 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
110 | 129 | |