Manual:SQL patch file

You might write an SQL file either for a schema change in the core (see Development_policy#Database_patches, Manual:DatabaseUpdater.php ) or for an extension (see Manual:Hooks/LoadExtensionSchemaUpdates ). See also the general database coding conventions.

Example edit

An SQL file to create a table might look something like this:

CREATE TABLE /*_*/foo_bar(
-- Primary key
-- user.user_id of the user who foobared the wiki
fb_user int unsigned NOT NULL,
-- user.user_text of the user who foobared the wiki
fb_user_text varchar(255),
-- Timestamp of when the wiki was foobared
fb_timestamp varbinary(14) NOT NULL default NULL ''

CREATE INDEX /*i*/fb_user ON /*_*/foo_bar (fb_user);
CREATE INDEX /*i*/fb_user_text ON /*_*/foo_bar (fb_user_text);

Variable replacement edit

The first two need to be used in patch files, as in the example above.

  • /*_*/ will be replaced with $wgDBprefix .
  • /*i*/ is used to identify indexes so their name can be changed via the index alias system. (This was only ever used for a small number of core tables and has been removed in MediaWiki 1.35, so in practice this does not make any difference.)
  • /*$wgDBTableOptions*/ will be replaced with the value of $wgDBTableOptions .
  • /*$wgDBTableOptions*/ is only used for MySQL database backends.

There are other variable replacements but they are not used in practice. See the documentation of Database::replaceVars() for the full list.

External links edit