* simplified file description header or load.php
[lhc/web/wiklou.git] / maintenance / tables.sql
index 64d3f85..2661b84 100644 (file)
@@ -86,6 +86,8 @@ CREATE TABLE /*_*/user (
   
   -- Newline-separated list of name=value defining the user
   -- preferences
+  -- Now obsolete in favour of user_properties table;
+  -- old values will be migrated from here transparently.
   user_options blob NOT NULL,
   
   -- This is a timestamp which is updated when a user
@@ -160,8 +162,10 @@ CREATE UNIQUE INDEX /*i*/ug_user_group ON /*_*/user_groups (ug_user,ug_group);
 CREATE INDEX /*i*/ug_group ON /*_*/user_groups (ug_group);
 
 
+--
 -- Stores notifications of user talk page changes, for the display
 -- of the "you have new messages" box
+--
 CREATE TABLE /*_*/user_newtalk (
   -- Key to user.user_id
   user_id int NOT NULL default 0,
@@ -178,6 +182,29 @@ CREATE INDEX /*i*/un_user_id ON /*_*/user_newtalk (user_id);
 CREATE INDEX /*i*/un_user_ip ON /*_*/user_newtalk (user_ip);
 
 
+--
+-- User preferences and perhaps other fun stuff. :)
+-- Replaces the old user.user_options blob, with a couple nice properties:
+--
+-- 1) We only store non-default settings, so changes to the defauls
+--    are now reflected for everybody, not just new accounts.
+-- 2) We can more easily do bulk lookups, statistics, or modifications of
+--    saved options since it's a sane table structure.
+--
+CREATE TABLE /*_*/user_properties (
+  -- Foreign key to user.user_id
+  up_user int NOT NULL,
+  
+  -- Name of the option being saved. This is indexed for bulk lookup.
+  up_property varbinary(32) NOT NULL,
+  
+  -- Property value as a string.
+  up_value blob
+) /*$wgDBTableOptions*/;
+
+CREATE UNIQUE INDEX /*i*/user_properties_user_property ON /*_*/user_properties (up_user,up_property);
+CREATE INDEX /*i*/user_properties_property ON /*_*/user_properties (up_property);
+
 --
 -- Core of the wiki: each page has an entry here which identifies
 -- it by title and contains some essential metadata.
@@ -390,6 +417,7 @@ CREATE TABLE /*_*/archive (
 
 CREATE INDEX /*i*/name_title_timestamp ON /*_*/archive (ar_namespace,ar_title,ar_timestamp);
 CREATE INDEX /*i*/ar_usertext_timestamp ON /*_*/archive (ar_user_text,ar_timestamp);
+CREATE INDEX /*i*/ar_page_revid ON /*_*/archive (ar_namespace, ar_title, ar_rev_id);
 
 
 --
@@ -462,29 +490,48 @@ CREATE TABLE /*_*/categorylinks (
   -- all such pages are in namespace 14 (NS_CATEGORY).
   cl_to varchar(255) binary NOT NULL default '',
   
-  -- The title of the linking page, or an optional override
-  -- to determine sort order. Sorting is by binary order, which
-  -- isn't always ideal, but collations seem to be an exciting
-  -- and dangerous new world in MySQL... The sortkey is updated
-  -- if no override exists and cl_from is renamed.
-  --
-  -- Truncate so that the cl_sortkey key fits in 1000 bytes 
-  -- (MyISAM 5 with server_character_set=utf8)
-  cl_sortkey varchar(70) binary NOT NULL default '',
+  -- A binary string obtained by applying a sortkey generation algorithm
+  -- (Language::convertToSortkey()) to page_title, or cl_sortkey_prefix . "\0"
+  -- . page_title if cl_sortkey_prefix is nonempty.
+  cl_sortkey varbinary(255) NOT NULL default '',
+
+  -- A prefix for the raw sortkey manually specified by the user, either via
+  -- [[Category:Foo|prefix]] or {{defaultsort:prefix}}.  If nonempty, it's
+  -- concatenated with a null followed by the page title before the sortkey
+  -- conversion algorithm is run.  We store this so that we can update
+  -- collations without reparsing all pages.
+  cl_sortkey_prefix varchar(255) binary NOT NULL default '',
   
   -- This isn't really used at present. Provided for an optional
   -- sorting method by approximate addition time.
-  cl_timestamp timestamp NOT NULL
+  cl_timestamp timestamp NOT NULL,
+
+  -- Stores $wgCategoryCollation at the time cl_sortkey was generated.  This
+  -- can be used to install new collation versions, tracking which rows are not
+  -- yet updated.  '' means no collation, this is a legacy row that needs to be
+  -- updated by updateCollation.php.  In the future, it might be possible to
+  -- specify different collations per category.
+  cl_collation varbinary(32) NOT NULL default '',
+
+  -- Stores whether cl_from is a category, file, or other page, so we can
+  -- paginate the three categories separately.  This never has to be updated
+  -- after the page is created, since none of these page types can be moved to
+  -- any other.
+  cl_type ENUM('page', 'subcat', 'file') NOT NULL default 'page'
 ) /*$wgDBTableOptions*/;
 
 CREATE UNIQUE INDEX /*i*/cl_from ON /*_*/categorylinks (cl_from,cl_to);
 
--- We always sort within a given category...
-CREATE INDEX /*i*/cl_sortkey ON /*_*/categorylinks (cl_to,cl_sortkey,cl_from);
+-- We always sort within a given category, and within a given type.  FIXME:
+-- Formerly this index didn't cover cl_type (since that didn't exist), so old
+-- callers won't be using an index: fix this?
+CREATE INDEX /*i*/cl_sortkey ON /*_*/categorylinks (cl_to,cl_type,cl_sortkey,cl_from);
 
 -- Not really used?
 CREATE INDEX /*i*/cl_timestamp ON /*_*/categorylinks (cl_to,cl_timestamp);
 
+-- For finding rows with outdated collation
+CREATE INDEX /*i*/cl_collation ON /*_*/categorylinks (cl_collation);
 
 -- 
 -- Track all existing categories.  Something is a category if 1) it has an en-
@@ -548,6 +595,20 @@ CREATE INDEX /*i*/el_to ON /*_*/externallinks (el_to(60), el_from);
 CREATE INDEX /*i*/el_index ON /*_*/externallinks (el_index(60));
 
 
+--
+-- Track external user accounts, if ExternalAuth is used
+--
+CREATE TABLE /*_*/external_user (
+  -- Foreign key to user_id
+  eu_local_id int unsigned NOT NULL PRIMARY KEY,
+
+  -- Some opaque identifier provided by the external database
+  eu_external_id varchar(255) binary NOT NULL
+) /*$wgDBTableOptions*/;
+
+CREATE UNIQUE INDEX /*i*/eu_external_id ON /*_*/external_user (eu_external_id);
+
+
 -- 
 -- Track interlanguage links
 --
@@ -566,6 +627,24 @@ CREATE UNIQUE INDEX /*i*/ll_from ON /*_*/langlinks (ll_from, ll_lang);
 CREATE INDEX /*i*/ll_lang ON /*_*/langlinks (ll_lang, ll_title);
 
 
+-- 
+-- Track inline interwiki links
+--
+CREATE TABLE /*_*/iwlinks (
+  -- page_id of the referring page
+  iwl_from int unsigned NOT NULL default 0,
+  
+  -- Interwiki prefix code of the target
+  iwl_prefix varbinary(20) NOT NULL default '',
+
+  -- Title of the target, including namespace
+  iwl_title varchar(255) binary NOT NULL default ''
+) /*$wgDBTableOptions*/;
+
+CREATE UNIQUE INDEX /*i*/iwl_from ON /*_*/iwlinks (iwl_from, iwl_prefix, iwl_title);
+CREATE UNIQUE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
+
+
 --
 -- Contains a single row with some aggregate info
 -- on the state of the site.
@@ -611,7 +690,7 @@ CREATE UNIQUE INDEX /*i*/ss_row_id ON /*_*/site_stats (ss_row_id);
 -- Stores an ID for every time any article is visited;
 -- depending on $wgHitcounterUpdateFreq, it is
 -- periodically cleared and the page_counter column
--- in the page table updated for the all articles
+-- in the page table updated for all the articles
 -- that have been visited.)
 --
 CREATE TABLE /*_*/hitcounter (
@@ -723,7 +802,7 @@ CREATE TABLE /*_*/image (
   -- the minor parts are not required to adher to any standard
   -- but should be consistent throughout the database
   -- see http://www.iana.org/assignments/media-types/
-  img_minor_mime varbinary(32) NOT NULL default "unknown",
+  img_minor_mime varbinary(100) NOT NULL default "unknown",
   
   -- Description field as entered by the uploader.
   -- This is displayed in image upload history and logs.
@@ -741,9 +820,9 @@ CREATE TABLE /*_*/image (
 ) /*$wgDBTableOptions*/;
 
 CREATE INDEX /*i*/img_usertext_timestamp ON /*_*/image (img_user_text,img_timestamp);
--- Used by Special:Imagelist for sort-by-size
+-- Used by Special:ListFiles for sort-by-size
 CREATE INDEX /*i*/img_size ON /*_*/image (img_size);
--- Used by Special:Newimages and Special:Imagelist
+-- Used by Special:Newimages and Special:ListFiles
 CREATE INDEX /*i*/img_timestamp ON /*_*/image (img_timestamp);
 -- Used in API and duplicate search
 CREATE INDEX /*i*/img_sha1 ON /*_*/image (img_sha1);
@@ -775,7 +854,7 @@ CREATE TABLE /*_*/oldimage (
   oi_metadata mediumblob NOT NULL,
   oi_media_type ENUM("UNKNOWN", "BITMAP", "DRAWING", "AUDIO", "VIDEO", "MULTIMEDIA", "OFFICE", "TEXT", "EXECUTABLE", "ARCHIVE") default NULL,
   oi_major_mime ENUM("unknown", "application", "audio", "image", "text", "video", "message", "model", "multipart") NOT NULL default "unknown",
-  oi_minor_mime varbinary(32) NOT NULL default "unknown",
+  oi_minor_mime varbinary(100) NOT NULL default "unknown",
   oi_deleted tinyint unsigned NOT NULL default 0,
   oi_sha1 varbinary(32) NOT NULL default ''
 ) /*$wgDBTableOptions*/;
@@ -825,7 +904,7 @@ CREATE TABLE /*_*/filearchive (
   fa_bits int default 0,
   fa_media_type ENUM("UNKNOWN", "BITMAP", "DRAWING", "AUDIO", "VIDEO", "MULTIMEDIA", "OFFICE", "TEXT", "EXECUTABLE", "ARCHIVE") default NULL,
   fa_major_mime ENUM("unknown", "application", "audio", "image", "text", "video", "message", "model", "multipart") default "unknown",
-  fa_minor_mime varbinary(32) default "unknown",
+  fa_minor_mime varbinary(100) default "unknown",
   fa_description tinyblob,
   fa_user int unsigned default 0,
   fa_user_text varchar(255) binary,
@@ -966,7 +1045,7 @@ CREATE TABLE /*_*/math (
   math_html text,
   
   -- MathML output from texvc, if any
-  math_mathml text  
+  math_mathml text
 ) /*$wgDBTableOptions*/;
 
 CREATE UNIQUE INDEX /*i*/math_inputhash ON /*_*/math (math_inputhash);
@@ -1008,6 +1087,12 @@ CREATE TABLE /*_*/interwiki (
   -- insertion.
   iw_url blob NOT NULL,
   
+  -- The URL of the file api.php
+  iw_api blob NOT NULL,
+
+  -- The name of the database (for a connection to be established with wfGetLB( 'wikiid' ))
+  iw_wikiid varchar(64) NOT NULL,
+  
   -- A boolean value indicating whether the wiki is in this project
   -- (used, for example, to detect redirect loops)
   iw_local bool NOT NULL,
@@ -1054,7 +1139,7 @@ CREATE INDEX /*i*/exptime ON /*_*/objectcache (exptime);
 CREATE TABLE /*_*/transcache (
   tc_url varbinary(255) NOT NULL,
   tc_contents text,
-  tc_time int NOT NULL
+  tc_time binary(14) NOT NULL
 ) /*$wgDBTableOptions*/;
 
 CREATE UNIQUE INDEX /*i*/tc_url_idx ON /*_*/transcache (tc_url);
@@ -1067,8 +1152,8 @@ CREATE TABLE /*_*/logging (
   -- Symbolic keys for the general log type and the action type
   -- within the log. The output format will be controlled by the
   -- action field, but only the type controls categorization.
-  log_type varbinary(10) NOT NULL default '',
-  log_action varbinary(10) NOT NULL default '',
+  log_type varbinary(32) NOT NULL default '',
+  log_action varbinary(32) NOT NULL default '',
   
   -- Timestamp. Duh.
   log_timestamp binary(14) NOT NULL default '19700101000000',
@@ -1076,10 +1161,14 @@ CREATE TABLE /*_*/logging (
   -- The user who performed this action; key to user_id
   log_user int unsigned NOT NULL default 0,
   
+  -- Name of the user who performed this action
+  log_user_text varchar(255) binary NOT NULL default '',
+  
   -- Key to the page affected. Where a user is the target,
   -- this will point to the user page.
   log_namespace int NOT NULL default 0,
   log_title varchar(255) binary NOT NULL default '',
+  log_page int unsigned NULL,
   
   -- Freeform text. Interpreted as edit history comments.
   log_comment varchar(255) NOT NULL default '',
@@ -1095,6 +1184,20 @@ CREATE INDEX /*i*/type_time ON /*_*/logging (log_type, log_timestamp);
 CREATE INDEX /*i*/user_time ON /*_*/logging (log_user, log_timestamp);
 CREATE INDEX /*i*/page_time ON /*_*/logging (log_namespace, log_title, log_timestamp);
 CREATE INDEX /*i*/times ON /*_*/logging (log_timestamp);
+CREATE INDEX /*i*/log_user_type_time ON /*_*/logging (log_user, log_type, log_timestamp);
+CREATE INDEX /*i*/log_page_id_time ON /*_*/logging (log_page,log_timestamp);
+
+
+CREATE TABLE /*_*/log_search (
+  -- The type of ID (rev ID, log ID, rev timestamp, username)
+  ls_field varbinary(32) NOT NULL,
+  -- The value of the ID
+  ls_value varchar(255) NOT NULL,
+  -- Key to log_id
+  ls_log_id int unsigned NOT NULL default 0
+) /*$wgDBTableOptions*/;
+CREATE UNIQUE INDEX /*i*/ls_field_val ON /*_*/log_search (ls_field,ls_value,ls_log_id);
+CREATE INDEX /*i*/ls_log_id ON /*_*/log_search (ls_log_id);
 
 
 CREATE TABLE /*_*/trackbacks (
@@ -1126,7 +1229,7 @@ CREATE TABLE /*_*/job (
   job_params blob NOT NULL
 ) /*$wgDBTableOptions*/;
 
-CREATE INDEX /*i*/job_cmd ON /*_*/job (job_cmd, job_namespace, job_title);
+CREATE INDEX /*i*/job_cmd ON /*_*/job (job_cmd, job_namespace, job_title, job_params(128));
 
 
 -- Details of updates to cached special pages
@@ -1152,7 +1255,9 @@ CREATE TABLE /*_*/redirect (
   -- and deletions may refer to different page records as time
   -- goes by.
   rd_namespace int NOT NULL default 0,
-  rd_title varchar(255) binary NOT NULL default ''
+  rd_title varchar(255) binary NOT NULL default '',
+  rd_interwiki varchar(32) default NULL,
+  rd_fragment varchar(255) binary default NULL
 ) /*$wgDBTableOptions*/;
 
 CREATE INDEX /*i*/rd_ns_title ON /*_*/redirect (rd_namespace,rd_title,rd_from);
@@ -1199,9 +1304,9 @@ CREATE TABLE /*_*/page_restrictions (
 ) /*$wgDBTableOptions*/;
 
 CREATE UNIQUE INDEX /*i*/pr_pagetype ON /*_*/page_restrictions (pr_page,pr_type);
-CREATE UNIQUE INDEX /*i*/pr_typelevel ON /*_*/page_restrictions (pr_type,pr_level);
-CREATE UNIQUE INDEX /*i*/pr_level ON /*_*/page_restrictions (pr_level);
-CREATE UNIQUE INDEX /*i*/pr_cascade ON /*_*/page_restrictions (pr_cascade);
+CREATE INDEX /*i*/pr_typelevel ON /*_*/page_restrictions (pr_type,pr_level);
+CREATE INDEX /*i*/pr_level ON /*_*/page_restrictions (pr_level);
+CREATE INDEX /*i*/pr_cascade ON /*_*/page_restrictions (pr_cascade);
 
 
 -- Protected titles - nonexistent pages that have been protected
@@ -1231,39 +1336,97 @@ CREATE UNIQUE INDEX /*i*/pp_page_propname ON /*_*/page_props (pp_page,pp_propnam
 
 -- A table to log updates, one text key row per update.
 CREATE TABLE /*_*/updatelog (
-  ul_key varchar(255) NOT NULL PRIMARY KEY
+  ul_key varchar(255) NOT NULL PRIMARY KEY,
+  ul_value blob
 ) /*$wgDBTableOptions*/;
 
---- A table to track tags for revisions, logs and recent changes.
+
+-- A table to track tags for revisions, logs and recent changes.
 CREATE TABLE /*_*/change_tag (
-       ct_rc_id int NULL,
-       ct_log_id int NULL,
-       ct_rev_id int NULL,
-       ct_tag varchar(255) NOT NULL,
-       ct_params BLOB NULL,
-
-       UNIQUE KEY (ct_rc_id,ct_tag),
-       UNIQUE KEY (ct_log_id,ct_tag),
-       UNIQUE KEY (ct_rev_id,ct_tag),
-       KEY (ct_tag,ct_rc_id,ct_rev_id,ct_log_id) -- Covering index, so we can pull all the info only out of the index.
+  -- RCID for the change
+  ct_rc_id int NULL,
+  -- LOGID for the change
+  ct_log_id int NULL,
+  -- REVID for the change
+  ct_rev_id int NULL,
+  -- Tag applied
+  ct_tag varchar(255) NOT NULL,
+  -- Parameters for the tag, presently unused
+  ct_params blob NULL
 ) /*$wgDBTableOptions*/;
 
--- Rollup table to pull a LIST of tags simply without ugly GROUP_CONCAT that only works on MySQL 4.1+
+CREATE UNIQUE INDEX /*i*/change_tag_rc_tag ON /*_*/change_tag (ct_rc_id,ct_tag);
+CREATE UNIQUE INDEX /*i*/change_tag_log_tag ON /*_*/change_tag (ct_log_id,ct_tag);
+CREATE UNIQUE INDEX /*i*/change_tag_rev_tag ON /*_*/change_tag (ct_rev_id,ct_tag);
+-- Covering index, so we can pull all the info only out of the index.
+CREATE INDEX /*i*/change_tag_tag_id ON /*_*/change_tag (ct_tag,ct_rc_id,ct_rev_id,ct_log_id);
+
+
+-- Rollup table to pull a LIST of tags simply without ugly GROUP_CONCAT
+-- that only works on MySQL 4.1+
 CREATE TABLE /*_*/tag_summary (
-       ts_rc_id int NULL,
-       ts_log_id int NULL,
-       ts_rev_id int NULL,
-       ts_tags BLOB NOT NULL,
-
-       UNIQUE KEY (ts_rc_id),
-       UNIQUE KEY (ts_log_id),
-       UNIQUE KEY (ts_rev_id)
+  -- RCID for the change  
+  ts_rc_id int NULL,
+  -- LOGID for the change
+  ts_log_id int NULL,
+  -- REVID for the change
+  ts_rev_id int NULL,
+  -- Comma-separated list of tags
+  ts_tags blob NOT NULL
 ) /*$wgDBTableOptions*/;
 
+CREATE UNIQUE INDEX /*i*/tag_summary_rc_id ON /*_*/tag_summary (ts_rc_id);
+CREATE UNIQUE INDEX /*i*/tag_summary_log_id ON /*_*/tag_summary (ts_log_id);
+CREATE UNIQUE INDEX /*i*/tag_summary_rev_id ON /*_*/tag_summary (ts_rev_id);
+
+
 CREATE TABLE /*_*/valid_tag (
-       vt_tag varchar(255) NOT NULL,
-       PRIMARY KEY (vt_tag)
+  vt_tag varchar(255) NOT NULL PRIMARY KEY
 ) /*$wgDBTableOptions*/;
 
+-- Table for storing localisation data
+CREATE TABLE /*_*/l10n_cache (
+  -- Language code
+  lc_lang varbinary(32) NOT NULL,
+  -- Cache key
+  lc_key varchar(255) NOT NULL,
+  -- Value
+  lc_value mediumblob NOT NULL
+) /*$wgDBTableOptions*/;
+CREATE INDEX /*i*/lc_lang_key ON /*_*/l10n_cache (lc_lang, lc_key);
+
+-- Table for storing JSON message blobs for the resource loader
+CREATE TABLE /*_*/msg_resource (
+  -- Resource name
+  mr_resource varchar(255) NOT NULL,
+  -- Language code 
+  mr_lang varbinary(32) NOT NULL,
+  -- JSON blob
+  mr_blob mediumblob NOT NULL,
+  -- Timestamp of last update
+  mr_timestamp binary(14) NOT NULL
+) /*$wgDBTableOptions*/;
+CREATE UNIQUE INDEX /*i*/mr_resource_lang ON /*_*/msg_resource (mr_resource, mr_lang);
+
+-- Table for administering which message is contained in which resource
+CREATE TABLE /*_*/msg_resource_links (
+  mrl_resource varchar(255) NOT NULL,
+  -- Message key
+  mrl_message varchar(255) NOT NULL
+) /*$wgDBTableOptions*/;
+CREATE UNIQUE INDEX /*i*/mrl_message_resource ON /*_*/msg_resource_links (mrl_message, mrl_resource);
+
+-- Table for tracking which local files a module depends on that aren't
+-- registered directly.
+-- Currently only used for tracking images that CSS depends on
+CREATE TABLE /*_*/module_deps (
+  -- Module name
+  md_module varchar(255) NOT NULL,
+  -- Skin name
+  md_skin varchar(32) NOT NULL,
+  -- JSON blob with file dependencies
+  md_deps mediumblob NOT NULL
+) /*$wgDBTableOptions*/;
+CREATE UNIQUE INDEX /*i*/md_module_skin ON /*_*/module_deps (md_module, md_skin);
 
 -- vim: sw=2 sts=2 et