Topic on User talk:Anomie/Abstract schema

runMaintenanceScript

2
MaxSem (talkcontribs)

What's the use case for bool runMaintenanceScript( string $className ) in SchemaOperations? Why can't generic Maintenance::runChild() be used?

Anomie (talkcontribs)

Because every operation in the schema change data structure has to be a call of a method on SchemaOperations. And also because Maintenance::runChild() doesn't actually run the script, something still needs to call ->execute().

The actual implementation in a SchemaOperationsBase class could look something like

public function runMaintenanceScript( $className ) {
    $task = $this->maintenance->runChild( $className );
    return $task->execute();
}

Except I hope to put all the new code except the "MediaWiki integration" bits somewhere under includes/libs/rdbms, and MW's Maintenance class isn't (currently) a library that could be depended on by a librarized rdbms.

If nothing else I suppose update.php could inject a callback with the above code into the SchemaOperations instance when it's setting everything up.

More generally, I want to be able to define something like (from https://gerrit.wikimedia.org/r/c/393929/)

protected function migrateArchiveText() {
    if ( $this->db->fieldExists( 'archive', 'ar_text', __METHOD__ ) ) {
        $this->output( "Migrating archive ar_text to modern storage.\n" );
        $task = $this->maintenance->runChild( MigrateArchiveText::class, 'migrateArchiveText.php' );   
        $task->setForce();     
        if ( $task->execute() ) {
            $this->applyPatch( 'patch-drop-ar_text.sql', false,
                'Dropping ar_text and ar_flags columns' );
        }              
    }          
}

in the generic syntax. In the current proposal that could be an entry like this in the schema updates array

[
    'name' => 'Migrate archive ar_text to modern storage',
    'order' => '1.31.0-wmf.??+core+1',
    'check' => [ 'fieldExists', 'archive', 'ar_text' ],
    'operations' => [
        [ 'runMaintenanceScript', 'MigrateArchiveText' ],
        [ 'setColumnDefault', 'archive', 'ar_text_id', 0 ],
        [ 'setColumnNullable', 'archive', 'ar_text_id', false ],
        [ 'dropColumn', 'archive', 'ar_flags' ],
        [ 'dropColumn', 'archive', 'ar_text' ],
    ],
]

(although the "setForce()" bit in the original would still need an equivalent)

Reply to "runMaintenanceScript"