Manual:SQL patch file

From MediaWiki.org
Jump to: navigation, search

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).

Example[edit | edit source]

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(256),
-- 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;

External links[edit | edit source]

Databases Engines: MySQLOraclePostgreSQLSQLite
Technical documentation: Schema (tables) – API property associationsField prefixesPrimary key storage in other fieldsWikimedia extension tables
Configuration: SettingsSharing
Development: AccessOptimizationPolicyUpdaterExtension schema updatesPatch file
Core tables: archivecategorycategorylinkschange_tagconfigexternallinksfilearchivehitcounterimageimagelinksinterwikiiwlinksipblocksjobl10n_cachelanglinkslogginglog_searchmsg_resourcemsg_resource_linksmodule_depsobjectcacheoldimagepagepagelinkspage_propspage_restrictionsprotected_titlesquerycachequerycachetwoquerycache_inforecentchangesredirectrevisionsearchindexsitessite_statstag_summarytemplatelinkstexttranscacheupdateloguploadstashuseruser_former_groupsuser_groupsuser_newtalkuser_propertiesvalid_tagwatchlist