Manual:SQL patch file

From MediaWiki.org
Jump to: navigation, 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]

DatabasesManual:Database layout Engines: MySQL/MariaDBManual:MySQLOracleManual:OraclePostgreSQLManual:PostgreSQLSQLiteManual:SQLiteSQL ServerManual:Microsoft SQL Server

Technical documentation: SchemaManual:Database layout (tablesCategory:MediaWiki database tables) – API property associationsAPI:Database field and API property associationsField prefixesDatabase field prefixesPrimary key storage in other fieldsManual:Primary key storage in other fieldsWikimedia extension tablesCategory:Wikimedia extension database tables
Configuration: SettingsManual:Configuration_settings#Database_settingsSharingManual:Shared database
Development: AccessManual:Database accessOptimizationDatabase optimizationPolicyDevelopment policy#Database_patchesUpdaterManual:DatabaseUpdater.phpExtension schema updatesManual:Hooks/LoadExtensionSchemaUpdatesPatch fileManual:SQL patch file

Core tables: archivebot_passwordscategorycategorylinkschange_tagconfigexternallinksfilearchivehitcounterimageimagelinksinterwikiiwlinksipblocksjobl10n_cachelanglinkslogginglog_searchmsg_resourcemsg_resource_linksmodule_depsobjectcacheoldimagepagepagelinkspage_propspage_restrictionsprotected_titlesquerycachequerycachetwoquerycache_inforecentchangesredirectrevisionsearchindexsitessite_identifiers - site_statstag_summarytemplatelinkstexttranscacheupdateloguploadstashuseruser_former_groupsuser_groupsuser_newtalkuser_propertiestag_summaryvalid_tagwatchlist