[ 'addField', 'mwuser', 'user_password_expires', 'patch-user_password_expires.sql' ],
// 1.24
- [ 'addField', 'page', 'page_lang', 'patch-page-page_lang.sql' ],
+ [ 'addField', 'page', 'page_lang', 'patch-page_page_lang.sql' ],
// 1.25
[ 'dropTable', 'hitcounter' ],
[ 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ],
[ 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ],
- // Constraint updates
- [ 'updateConstraints', 'category_types', 'categorylinks', 'cl_type' ],
- [ 'updateConstraints', 'major_mime', 'filearchive', 'fa_major_mime' ],
- [ 'updateConstraints', 'media_type', 'filearchive', 'fa_media_type' ],
- [ 'updateConstraints', 'major_mime', 'oldimage', 'oi_major_mime' ],
- [ 'updateConstraints', 'media_type', 'oldimage', 'oi_media_type' ],
- [ 'updateConstraints', 'major_mime', 'image', 'img_major_mime' ],
- [ 'updateConstraints', 'media_type', 'image', 'img_media_type' ],
- [ 'updateConstraints', 'media_type', 'uploadstash', 'us_media_type' ],
- // END: Constraint updates
+ // scripts were updated in 1.27 due to SQL errors; retaining old updatekeys so that people
+ // updating from 1.23->1.25->1.27 do not execute these scripts twice even though the
+ // updatekeys no longer make sense as they are.
+ [ 'updateSchema', 'categorylinks', 'cl_type-category_types-ck',
+ 'patch-categorylinks-constraints.sql' ],
+ [ 'updateSchema', 'filearchive', 'fa_major_mime-major_mime-ck',
+ 'patch-filearchive-constraints.sql' ],
+ [ 'updateSchema', 'oldimage', 'oi_major_mime-major_mime-ck',
+ 'patch-oldimage-constraints.sql' ],
+ [ 'updateSchema', 'image', 'img_major_mime-major_mime-ck', 'patch-image-constraints.sql' ],
+ [ 'updateSchema', 'uploadstash', 'us_media_type-media_type-ck',
+ 'patch-uploadstash-constraints.sql' ],
[ 'modifyField', 'image', 'img_major_mime',
'patch-img_major_mime-chemical.sql' ],
[ 'dropTable', 'msg_resource_links' ],
[ 'dropTable', 'msg_resource' ],
[ 'addField', 'watchlist', 'wl_id', 'patch-watchlist-wl_id.sql' ],
+ [ 'dropField', 'mwuser', 'user_options', 'patch-drop-user_options.sql' ],
+ [ 'addTable', 'bot_passwords', 'patch-bot_passwords.sql' ],
+ [ 'addField', 'pagelinks', 'pl_from_namespace', 'patch-pl_from_namespace.sql' ],
+ [ 'addField', 'templatelinks', 'tl_from_namespace', 'patch-tl_from_namespace.sql' ],
+ [ 'addField', 'imagelinks', 'il_from_namespace', 'patch-il_from_namespace.sql' ],
+ [ 'dropIndex', 'categorylinks', 'cl_collation', 'patch-kill-cl_collation_index.sql' ],
+ [ 'addIndex', 'categorylinks', 'cl_collation_ext',
+ 'patch-add-cl_collation_ext_index.sql' ],
+ [ 'dropField', 'recentchanges', 'rc_cur_time', 'patch-drop-rc_cur_time.sql' ],
+ [ 'addField', 'page_props', 'pp_sortkey', 'patch-pp_sortkey.sql' ],
+ [ 'updateSchema', 'oldimage', 'oldimage varchar', 'patch-oldimage-schema.sql' ],
+ [ 'updateSchema', 'filearchive', 'filearchive varchar', 'patch-filearchive-schema.sql' ],
+ [ 'updateSchema', 'image', 'image varchar', 'patch-image-schema.sql' ],
+ [ 'updateSchema', 'recentchanges', 'recentchanges-drop-fks',
+ 'patch-recentchanges-drop-fks.sql' ],
+ [ 'updateSchema', 'logging', 'logging-drop-fks', 'patch-logging-drop-fks.sql' ],
+ [ 'updateSchema', 'archive', 'archive-drop-fks', 'patch-archive-drop-fks.sql' ],
+
+ // 1.28
+ [ 'addIndex', 'recentchanges', 'rc_name_type_patrolled_timestamp',
+ 'patch-add-rc_name_type_patrolled_timestamp_index.sql' ],
];
}
+ protected function applyPatch( $path, $isFullPath = false, $msg = null ) {
+ $prevScroll = $this->db->scrollableCursor( false );
+ $prevPrep = $this->db->prepareStatements( false );
+ parent::applyPatch( $path, $isFullPath, $msg );
+ $this->db->scrollableCursor( $prevScroll );
+ $this->db->prepareStatements( $prevPrep );
+ }
+
/**
- * Drops unnamed and creates named constraints following the pattern
- * <column>_ckc
+ * General schema update for a table that touches more than one field or requires
+ * destructive actions (such as dropping and recreating the table).
*
- * @param string $constraintType
- * @param string $table Name of the table to which the field belongs
- * @param string $field Name of the field to modify
- * @return bool False if patch is skipped.
+ * @param string $table
+ * @param string $updatekey
+ * @param string $patch
+ * @param bool $fullpath
*/
- protected function updateConstraints( $constraintType, $table, $field ) {
- global $wgDBname, $wgDBmwschema;
-
- if ( !$this->doTable( $table ) ) {
- return true;
- }
-
- $this->output( "...updating constraints on [$table].[$field] ..." );
- $updateKey = "$field-$constraintType-ck";
+ protected function updateSchema( $table, $updatekey, $patch, $fullpath = false ) {
if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
- $this->output( "...$table table does not exist, skipping modify field patch.\n" );
- return true;
- } elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) {
- $this->output( "...$field field does not exist in $table table, " .
- "skipping modify field patch.\n" );
- return true;
- } elseif ( $this->updateRowExists( $updateKey ) ) {
- $this->output( "...$field in table $table already patched.\n" );
- return true;
- }
-
- # After all checks passed, start the update
- $this->insertUpdateRow( $updateKey );
- $path = 'named_constraints.sql';
- $constraintMap = [
- 'category_types' =>
- "($field in('page', 'subcat', 'file'))",
- 'major_mime' =>
- "($field in('unknown', 'application', 'audio', 'image', 'text', 'video'," .
- " 'message', 'model', 'multipart'))",
- 'media_type' =>
- "($field in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA'," .
- "'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))"
- ];
- $constraint = $constraintMap[$constraintType];
-
- # and hack-in those variables that should be replaced
- # in our template file right now
- $this->db->setSchemaVars( [
- 'tableName' => $table,
- 'fieldName' => $field,
- 'checkConstraint' => $constraint,
- 'wgDBname' => $wgDBname,
- 'wgDBmwschema' => $wgDBmwschema,
- ] );
-
- # Full path from file name
- $path = $this->db->patchPath( $path );
-
- # No need for a cursor allowing result-iteration; just apply a patch
- # store old value for re-setting later
- $wasScrollable = $this->db->scrollableCursor( false );
+ $this->output( "...$table table does not exist, skipping schema update patch.\n" );
+ } elseif ( $this->updateRowExists( $updatekey ) ) {
+ $this->output( "...$table already had schema updated by $patch.\n" );
+ } else {
+ $this->insertUpdateRow( $updatekey );
- # Apply patch
- $this->db->sourceFile( $path );
-
- # Reset DB instance to have original state
- $this->db->setSchemaVars( false );
- $this->db->scrollableCursor( $wasScrollable );
-
- $this->output( "done.\n" );
+ return $this->applyPatch( $patch, $fullpath, "Updating schema of table $table" );
+ }
return true;
}