Manual:SQL patch file

From MediaWiki.org
Jump to navigation Jump to search

Other languages:
English • ‎español • ‎français • ‎日本語 • ‎polski • ‎português • ‎português do Brasil

You might write an SQL file either for a schema change in the core (see Development_policy#Database_patches, Manual:DatabaseUpdater.phpManual:DatabaseUpdater.php) or for an extension (see Manual:Hooks/LoadExtensionSchemaUpdatesManual:Hooks/LoadExtensionSchemaUpdates).

Example[edit]

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

BEGIN;
 
CREATE TABLE /*_*/foo_bar(
-- Primary key
fb_id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
-- 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 ''
)/*$wgDBTableOptions*/;

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

Variable replacement[edit]

/*_*/ will be replaced with $wgDBprefixManual:$wgDBprefix. /*i*/ will be replaced with an index prefix. /*$wgDBTableOptions*/ will be replaced with the value of $wgDBTableOptionsManual:$wgDBTableOptions. These three need to be used in patch files, as in the example above. There are other variable replacements but they are not used in practice. See the documentation of DatabaseBase::replaceVars() for the full list.

External links[edit]