Jump to content
MediaWiki

Manual:SQL patch file

From mediawiki.org
This page is obsolete. It is being retained for archival purposes. It may document extensions or features that are obsolete and/or no longer supported. Do not rely on the information here being up-to-date.

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:

CREATETABLE/*_*/foo_bar(
-- Primary key
fb_idintunsignedNOTNULLPRIMARYKEYAUTO_INCREMENT,
-- user.user_id of the user who foobared the wiki
fb_userintunsignedNOTNULL,
-- user.user_text of the user who foobared the wiki
fb_user_textvarchar(255),
-- Timestamp of when the wiki was foobared
fb_timestampvarbinary(14)NOTNULLdefaultNULL''
)/*$wgDBTableOptions*/;
CREATEINDEX/*i*/fb_userON/*_*/foo_bar(fb_user);
CREATEINDEX/*i*/fb_user_textON/*_*/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.

[edit ]
Engines
Current
Former
Technical documentation
Configuration
Development
Core tables
Current
Former

AltStyle によって変換されたページ (->オリジナル) /