Jump to content

Manual talk:Hooks/LoadExtensionSchemaUpdates

Add topic
From mediawiki.org
Latest comment: 7 years ago by Samwilson in topic sql directory

An extension schema update function

[edit]

What if I want to have an extension run a function? Right now, I use this code, which sucks because it runs the function on every page load, rather than just when update.php is run:

public static function SchemaUpdates( $updater ) {
        $updater->addExtensionUpdate( array( 'modifyField', 'revision', 'rev_id',
	        dirname( __FILE__ ) . '/patches/patch-rev_id-one-quadrillion.sql', true ) );

	// Update the updatelog so that when update.php is run, it doesn't run a bunch of updates
	// that will populate the revision table endlessly because it's going to the quadrillion
	// FIXME: This adds unnecessary database hits
	$dbw = wfGetDB( DB_MASTER );
	$keys = array(
		'populate rev_parent_id',
		'populate rev_len and ar_len',
		'populate rev_sha1',
	);
	foreach ( $keys as $key ) {
		if ( !$dbw->selectRow( 'updatelog', array( 'ul_key'),
			array( 'ul_key' => $key ) ) ) {
			$dbw->insert( 'updatelog', array( 'ul_key' => $key ),
				__METHOD__, 'IGNORE' );
		}
	}
        return true;

Leucosticte (talk) 01:50, 24 March 2014 (UTC)Reply

Database Prefix?

[edit]

How do you take care of the database prefix ($wgDBprefix) with $updater->addExtensionIndex? --77.246.193.30 19:10, 5 September 2014 (UTC)Reply

Okay, found it here --77.246.193.30 19:35, 5 September 2014 (UTC)Reply

sql directory

[edit]

I just added a note about using the sql/ directory for extensions' SQL files. This isn't the only name that's used, but it's the most common:

find mediawiki-extensions/ -name '*.sql'  | xargs -I{} dirname {} | xargs -I{} basename {} | sort | uniq -c | sort -nr
   241 sql
   112 db_patches
    60 db
    57 patches
    48 mysql
    36 archives
    33 Incremental
    29 postgres
    23 schema-changes
    14 snippets
    13 oracle

Sam Wilson 05:26, 21 September 2017 (UTC)Reply