tables.sql 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. -- Experimental table definitions for Microsoft SQL Server with
  2. -- content-holding fields switched to explicit BINARY charset.
  3. -- ------------------------------------------------------------
  4. -- SQL to create the initial tables for the MediaWiki database.
  5. -- This is read and executed by the install script; you should
  6. -- not have to run it by itself unless doing a manual install.
  7. --
  8. -- General notes:
  9. --
  10. -- The comments in this and other files are
  11. -- replaced with the defined table prefix by the installer
  12. -- and updater scripts. If you are installing or running
  13. -- updates manually, you will need to manually insert the
  14. -- table prefix if any when running these scripts.
  15. --
  16. --
  17. -- The user table contains basic account information,
  18. -- authentication keys, etc.
  19. --
  20. -- Some multi-wiki sites may share a single central user table
  21. -- between separate wikis using the $wgSharedDB setting.
  22. --
  23. -- Note that when a external authentication plugin is used,
  24. -- user table entries still need to be created to store
  25. -- preferences and to key tracking information in the other
  26. -- tables.
  27. -- LINE:53
  28. CREATE TABLE /*_*/mwuser (
  29. user_id INT NOT NULL PRIMARY KEY IDENTITY(0,1),
  30. user_name NVARCHAR(255) NOT NULL UNIQUE DEFAULT '',
  31. user_real_name NVARCHAR(255) NOT NULL DEFAULT '',
  32. user_password NVARCHAR(255) NOT NULL DEFAULT '',
  33. user_newpassword NVARCHAR(255) NOT NULL DEFAULT '',
  34. user_newpass_time varchar(14) NULL DEFAULT NULL,
  35. user_email NVARCHAR(255) NOT NULL DEFAULT '',
  36. user_touched varchar(14) NOT NULL DEFAULT '',
  37. user_token NCHAR(32) NOT NULL DEFAULT '',
  38. user_email_authenticated varchar(14) DEFAULT NULL,
  39. user_email_token NCHAR(32) DEFAULT '',
  40. user_email_token_expires varchar(14) DEFAULT NULL,
  41. user_registration varchar(14) DEFAULT NULL,
  42. user_editcount INT NULL DEFAULT NULL,
  43. user_password_expires varchar(14) DEFAULT NULL
  44. );
  45. CREATE UNIQUE INDEX /*i*/user_name ON /*_*/mwuser (user_name);
  46. CREATE INDEX /*i*/user_email_token ON /*_*/mwuser (user_email_token);
  47. CREATE INDEX /*i*/user_email ON /*_*/mwuser (user_email);
  48. -- Insert a dummy user to represent anons
  49. INSERT INTO /*_*/mwuser (user_name) VALUES ('##Anonymous##');
  50. --
  51. -- User permissions have been broken out to a separate table;
  52. -- this allows sites with a shared user table to have different
  53. -- permissions assigned to a user in each project.
  54. --
  55. -- This table replaces the old user_rights field which used a
  56. -- comma-separated nvarchar(max).
  57. CREATE TABLE /*_*/user_groups (
  58. ug_user INT NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
  59. ug_group NVARCHAR(255) NOT NULL DEFAULT '',
  60. );
  61. CREATE UNIQUE clustered INDEX /*i*/ug_user_group ON /*_*/user_groups (ug_user, ug_group);
  62. CREATE INDEX /*i*/ug_group ON /*_*/user_groups(ug_group);
  63. -- Stores the groups the user has once belonged to.
  64. -- The user may still belong to these groups (check user_groups).
  65. -- Users are not autopromoted to groups from which they were removed.
  66. CREATE TABLE /*_*/user_former_groups (
  67. ufg_user INT NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
  68. ufg_group nvarchar(255) NOT NULL default ''
  69. );
  70. CREATE UNIQUE INDEX /*i*/ufg_user_group ON /*_*/user_former_groups (ufg_user,ufg_group);
  71. -- Stores notifications of user talk page changes, for the display
  72. -- of the "you have new messages" box
  73. -- Changed user_id column to user_id to avoid clashing with user_id function
  74. CREATE TABLE /*_*/user_newtalk (
  75. user_id INT NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
  76. user_ip NVARCHAR(40) NOT NULL DEFAULT '',
  77. user_last_timestamp varchar(14) DEFAULT NULL,
  78. );
  79. CREATE INDEX /*i*/un_user_id ON /*_*/user_newtalk (user_id);
  80. CREATE INDEX /*i*/un_user_ip ON /*_*/user_newtalk (user_ip);
  81. --
  82. -- User preferences and other fun stuff
  83. -- replaces old user.user_options nvarchar(max)
  84. --
  85. CREATE TABLE /*_*/user_properties (
  86. up_user INT NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
  87. up_property NVARCHAR(255) NOT NULL,
  88. up_value NVARCHAR(MAX),
  89. );
  90. CREATE UNIQUE CLUSTERED INDEX /*i*/user_properties_user_property ON /*_*/user_properties (up_user,up_property);
  91. CREATE INDEX /*i*/user_properties_property ON /*_*/user_properties (up_property);
  92. --
  93. -- This table contains a user's bot passwords: passwords that allow access to
  94. -- the account via the API with limited rights.
  95. --
  96. CREATE TABLE /*_*/bot_passwords (
  97. bp_user int NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
  98. bp_app_id nvarchar(32) NOT NULL,
  99. bp_password nvarchar(255) NOT NULL,
  100. bp_token nvarchar(255) NOT NULL,
  101. bp_restrictions nvarchar(max) NOT NULL,
  102. bp_grants nvarchar(max) NOT NULL,
  103. PRIMARY KEY (bp_user, bp_app_id)
  104. );
  105. --
  106. -- Core of the wiki: each page has an entry here which identifies
  107. -- it by title and contains some essential metadata.
  108. --
  109. CREATE TABLE /*_*/page (
  110. page_id INT NOT NULL PRIMARY KEY IDENTITY(0,1),
  111. page_namespace INT NOT NULL,
  112. page_title NVARCHAR(255) NOT NULL,
  113. page_restrictions NVARCHAR(255) NOT NULL,
  114. page_is_redirect BIT NOT NULL DEFAULT 0,
  115. page_is_new BIT NOT NULL DEFAULT 0,
  116. page_random real NOT NULL DEFAULT RAND(),
  117. page_touched varchar(14) NOT NULL default '',
  118. page_links_updated varchar(14) DEFAULT NULL,
  119. page_latest INT, -- FK inserted later
  120. page_len INT NOT NULL,
  121. page_content_model nvarchar(32) default null,
  122. page_lang VARBINARY(35) DEFAULT NULL
  123. );
  124. CREATE UNIQUE INDEX /*i*/name_title ON /*_*/page (page_namespace,page_title);
  125. CREATE INDEX /*i*/page_random ON /*_*/page (page_random);
  126. CREATE INDEX /*i*/page_len ON /*_*/page (page_len);
  127. CREATE INDEX /*i*/page_redirect_namespace_len ON /*_*/page (page_is_redirect, page_namespace, page_len);
  128. -- insert a dummy page
  129. INSERT INTO /*_*/page (page_namespace, page_title, page_restrictions, page_latest, page_len) VALUES (-1,'','',0,0);
  130. --
  131. -- Every edit of a page creates also a revision row.
  132. -- This stores metadata about the revision, and a reference
  133. -- to the TEXT storage backend.
  134. --
  135. CREATE TABLE /*_*/revision (
  136. rev_id INT NOT NULL UNIQUE IDENTITY(0,1),
  137. rev_page INT NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  138. rev_text_id INT NOT NULL, -- FK added later
  139. rev_comment NVARCHAR(255) NOT NULL,
  140. rev_user INT REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
  141. rev_user_text NVARCHAR(255) NOT NULL DEFAULT '',
  142. rev_timestamp varchar(14) NOT NULL default '',
  143. rev_minor_edit BIT NOT NULL DEFAULT 0,
  144. rev_deleted TINYINT NOT NULL DEFAULT 0,
  145. rev_len INT,
  146. rev_parent_id INT DEFAULT NULL REFERENCES /*_*/revision(rev_id),
  147. rev_sha1 nvarchar(32) not null default '',
  148. rev_content_model nvarchar(32) default null,
  149. rev_content_format nvarchar(64) default null
  150. );
  151. CREATE UNIQUE CLUSTERED INDEX /*i*/rev_page_id ON /*_*/revision (rev_page, rev_id);
  152. CREATE INDEX /*i*/rev_timestamp ON /*_*/revision (rev_timestamp);
  153. CREATE INDEX /*i*/page_timestamp ON /*_*/revision (rev_page,rev_timestamp);
  154. CREATE INDEX /*i*/user_timestamp ON /*_*/revision (rev_user,rev_timestamp);
  155. CREATE INDEX /*i*/usertext_timestamp ON /*_*/revision (rev_user_text,rev_timestamp);
  156. CREATE INDEX /*i*/page_user_timestamp ON /*_*/revision (rev_page,rev_user,rev_timestamp);
  157. -- insert a dummy revision
  158. INSERT INTO /*_*/revision (rev_page,rev_text_id,rev_comment,rev_user,rev_len) VALUES (0,0,'',0,0);
  159. ALTER TABLE /*_*/page ADD CONSTRAINT FK_page_latest_page_id FOREIGN KEY (page_latest) REFERENCES /*_*/revision(rev_id);
  160. --
  161. -- Holds TEXT of individual page revisions.
  162. --
  163. -- Field names are a holdover from the 'old' revisions table in
  164. -- MediaWiki 1.4 and earlier: an upgrade will transform that
  165. -- table INTo the 'text' table to minimize unnecessary churning
  166. -- and downtime. If upgrading, the other fields will be left unused.
  167. CREATE TABLE /*_*/text (
  168. old_id INT NOT NULL PRIMARY KEY IDENTITY(0,1),
  169. old_text nvarchar(max) NOT NULL,
  170. old_flags NVARCHAR(255) NOT NULL,
  171. );
  172. -- insert a dummy text
  173. INSERT INTO /*_*/text (old_text,old_flags) VALUES ('','');
  174. ALTER TABLE /*_*/revision ADD CONSTRAINT FK_rev_text_id_old_id FOREIGN KEY (rev_text_id) REFERENCES /*_*/text(old_id) ON DELETE CASCADE;
  175. --
  176. -- Holding area for deleted articles, which may be viewed
  177. -- or restored by admins through the Special:Undelete interface.
  178. -- The fields generally correspond to the page, revision, and text
  179. -- fields, with several caveats.
  180. -- Cannot reasonably create views on this table, due to the presence of TEXT
  181. -- columns.
  182. CREATE TABLE /*_*/archive (
  183. ar_id int NOT NULL PRIMARY KEY IDENTITY,
  184. ar_namespace SMALLINT NOT NULL DEFAULT 0,
  185. ar_title NVARCHAR(255) NOT NULL DEFAULT '',
  186. ar_text NVARCHAR(MAX) NOT NULL,
  187. ar_comment NVARCHAR(255) NOT NULL,
  188. ar_user INT CONSTRAINT ar_user__user_id__fk FOREIGN KEY REFERENCES /*_*/mwuser(user_id),
  189. ar_user_text NVARCHAR(255) NOT NULL,
  190. ar_timestamp varchar(14) NOT NULL default '',
  191. ar_minor_edit BIT NOT NULL DEFAULT 0,
  192. ar_flags NVARCHAR(255) NOT NULL,
  193. ar_rev_id INT NULL, -- NOT a FK, the row gets deleted from revision and moved here
  194. ar_text_id INT CONSTRAINT ar_text_id__old_id__fk FOREIGN KEY REFERENCES /*_*/text(old_id) ON DELETE CASCADE,
  195. ar_deleted TINYINT NOT NULL DEFAULT 0,
  196. ar_len INT,
  197. ar_page_id INT NULL, -- NOT a FK, the row gets deleted from page and moved here
  198. ar_parent_id INT NULL, -- NOT FK
  199. ar_sha1 nvarchar(32) default null,
  200. ar_content_model nvarchar(32) DEFAULT NULL,
  201. ar_content_format nvarchar(64) DEFAULT NULL
  202. );
  203. CREATE INDEX /*i*/name_title_timestamp ON /*_*/archive (ar_namespace,ar_title,ar_timestamp);
  204. CREATE INDEX /*i*/ar_usertext_timestamp ON /*_*/archive (ar_user_text,ar_timestamp);
  205. CREATE INDEX /*i*/ar_revid ON /*_*/archive (ar_rev_id);
  206. --
  207. -- Track page-to-page hyperlinks within the wiki.
  208. --
  209. CREATE TABLE /*_*/pagelinks (
  210. pl_from INT NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  211. pl_from_namespace int NOT NULL DEFAULT 0,
  212. pl_namespace INT NOT NULL DEFAULT 0,
  213. pl_title NVARCHAR(255) NOT NULL DEFAULT '',
  214. );
  215. CREATE UNIQUE INDEX /*i*/pl_from ON /*_*/pagelinks (pl_from,pl_namespace,pl_title);
  216. CREATE UNIQUE INDEX /*i*/pl_namespace ON /*_*/pagelinks (pl_namespace,pl_title,pl_from);
  217. CREATE INDEX /*i*/pl_backlinks_namespace ON /*_*/pagelinks (pl_from_namespace,pl_namespace,pl_title,pl_from);
  218. --
  219. -- Track template inclusions.
  220. --
  221. CREATE TABLE /*_*/templatelinks (
  222. tl_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  223. tl_from_namespace int NOT NULL default 0,
  224. tl_namespace int NOT NULL default 0,
  225. tl_title nvarchar(255) NOT NULL default ''
  226. );
  227. CREATE UNIQUE INDEX /*i*/tl_from ON /*_*/templatelinks (tl_from,tl_namespace,tl_title);
  228. CREATE UNIQUE INDEX /*i*/tl_namespace ON /*_*/templatelinks (tl_namespace,tl_title,tl_from);
  229. CREATE INDEX /*i*/tl_backlinks_namespace ON /*_*/templatelinks (tl_from_namespace,tl_namespace,tl_title,tl_from);
  230. --
  231. -- Track links to images *used inline*
  232. -- We don't distinguish live from broken links here, so
  233. -- they do not need to be changed on upload/removal.
  234. --
  235. CREATE TABLE /*_*/imagelinks (
  236. -- Key to page_id of the page containing the image / media link.
  237. il_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  238. il_from_namespace int NOT NULL default 0,
  239. -- Filename of target image.
  240. -- This is also the page_title of the file's description page;
  241. -- all such pages are in namespace 6 (NS_FILE).
  242. il_to nvarchar(255) NOT NULL default ''
  243. );
  244. CREATE UNIQUE INDEX /*i*/il_from ON /*_*/imagelinks (il_from,il_to);
  245. CREATE UNIQUE INDEX /*i*/il_to ON /*_*/imagelinks (il_to,il_from);
  246. CREATE INDEX /*i*/il_backlinks_namespace ON /*_*/imagelinks (il_from_namespace,il_to,il_from);
  247. --
  248. -- Track category inclusions *used inline*
  249. -- This tracks a single level of category membership
  250. --
  251. CREATE TABLE /*_*/categorylinks (
  252. -- Key to page_id of the page defined as a category member.
  253. cl_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  254. -- Name of the category.
  255. -- This is also the page_title of the category's description page;
  256. -- all such pages are in namespace 14 (NS_CATEGORY).
  257. cl_to nvarchar(255) NOT NULL default '',
  258. -- A binary string obtained by applying a sortkey generation algorithm
  259. -- (Collation::getSortKey()) to page_title, or cl_sortkey_prefix . "\n"
  260. -- . page_title if cl_sortkey_prefix is nonempty.
  261. cl_sortkey varbinary(230) NOT NULL default 0x,
  262. -- A prefix for the raw sortkey manually specified by the user, either via
  263. -- [[Category:Foo|prefix]] or {{defaultsort:prefix}}. If nonempty, it's
  264. -- concatenated with a line break followed by the page title before the sortkey
  265. -- conversion algorithm is run. We store this so that we can update
  266. -- collations without reparsing all pages.
  267. -- Note: If you change the length of this field, you also need to change
  268. -- code in LinksUpdate.php. See bug 25254.
  269. cl_sortkey_prefix varbinary(255) NOT NULL default 0x,
  270. -- This isn't really used at present. Provided for an optional
  271. -- sorting method by approximate addition time.
  272. cl_timestamp varchar(14) NOT NULL,
  273. -- Stores $wgCategoryCollation at the time cl_sortkey was generated. This
  274. -- can be used to install new collation versions, tracking which rows are not
  275. -- yet updated. '' means no collation, this is a legacy row that needs to be
  276. -- updated by updateCollation.php. In the future, it might be possible to
  277. -- specify different collations per category.
  278. cl_collation nvarchar(32) NOT NULL default '',
  279. -- Stores whether cl_from is a category, file, or other page, so we can
  280. -- paginate the three categories separately. This never has to be updated
  281. -- after the page is created, since none of these page types can be moved to
  282. -- any other.
  283. cl_type varchar(10) NOT NULL default 'page',
  284. -- SQL server doesn't have enums, so we approximate with this
  285. CONSTRAINT cl_type_ckc CHECK (cl_type IN('page', 'subcat', 'file'))
  286. );
  287. CREATE UNIQUE INDEX /*i*/cl_from ON /*_*/categorylinks (cl_from,cl_to);
  288. -- We always sort within a given category, and within a given type. FIXME:
  289. -- Formerly this index didn't cover cl_type (since that didn't exist), so old
  290. -- callers won't be using an index: fix this?
  291. CREATE INDEX /*i*/cl_sortkey ON /*_*/categorylinks (cl_to,cl_type,cl_sortkey,cl_from);
  292. -- Used by the API (and some extensions)
  293. CREATE INDEX /*i*/cl_timestamp ON /*_*/categorylinks (cl_to,cl_timestamp);
  294. -- Used when updating collation (e.g. updateCollation.php)
  295. CREATE INDEX /*i*/cl_collation_ext ON /*_*/categorylinks (cl_collation, cl_to, cl_type, cl_from);
  296. --
  297. -- Track all existing categories. Something is a category if 1) it has an en-
  298. -- try somewhere in categorylinks, or 2) it once did. Categories might not
  299. -- have corresponding pages, so they need to be tracked separately.
  300. --
  301. CREATE TABLE /*_*/category (
  302. -- Primary key
  303. cat_id int NOT NULL PRIMARY KEY IDENTITY,
  304. -- Name of the category, in the same form as page_title (with underscores).
  305. -- If there is a category page corresponding to this category, by definition,
  306. -- it has this name (in the Category namespace).
  307. cat_title nvarchar(255) NOT NULL,
  308. -- The numbers of member pages (including categories and media), subcatego-
  309. -- ries, and Image: namespace members, respectively. These are signed to
  310. -- make underflow more obvious. We make the first number include the second
  311. -- two for better sorting: subtracting for display is easy, adding for order-
  312. -- ing is not.
  313. cat_pages int NOT NULL default 0,
  314. cat_subcats int NOT NULL default 0,
  315. cat_files int NOT NULL default 0
  316. );
  317. CREATE UNIQUE INDEX /*i*/cat_title ON /*_*/category (cat_title);
  318. -- For Special:Mostlinkedcategories
  319. CREATE INDEX /*i*/cat_pages ON /*_*/category (cat_pages);
  320. --
  321. -- Track links to external URLs
  322. --
  323. CREATE TABLE /*_*/externallinks (
  324. -- Primary key
  325. el_id int NOT NULL PRIMARY KEY IDENTITY,
  326. -- page_id of the referring page
  327. el_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  328. -- The URL
  329. el_to nvarchar(max) NOT NULL,
  330. -- In the case of HTTP URLs, this is the URL with any username or password
  331. -- removed, and with the labels in the hostname reversed and converted to
  332. -- lower case. An extra dot is added to allow for matching of either
  333. -- example.com or *.example.com in a single scan.
  334. -- Example:
  335. -- http://user:password@sub.example.com/page.html
  336. -- becomes
  337. -- http://com.example.sub./page.html
  338. -- which allows for fast searching for all pages under example.com with the
  339. -- clause:
  340. -- WHERE el_index LIKE 'http://com.example.%'
  341. el_index nvarchar(450) NOT NULL
  342. );
  343. CREATE INDEX /*i*/el_from ON /*_*/externallinks (el_from);
  344. CREATE INDEX /*i*/el_index ON /*_*/externallinks (el_index);
  345. -- el_to index intentionally not added; we cannot index nvarchar(max) columns,
  346. -- but we also cannot restrict el_to to a smaller column size as the external
  347. -- link may be larger.
  348. --
  349. -- Track interlanguage links
  350. --
  351. CREATE TABLE /*_*/langlinks (
  352. -- page_id of the referring page
  353. ll_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  354. -- Language code of the target
  355. ll_lang nvarchar(20) NOT NULL default '',
  356. -- Title of the target, including namespace
  357. ll_title nvarchar(255) NOT NULL default ''
  358. );
  359. CREATE UNIQUE INDEX /*i*/ll_from ON /*_*/langlinks (ll_from, ll_lang);
  360. CREATE INDEX /*i*/ll_lang ON /*_*/langlinks (ll_lang, ll_title);
  361. --
  362. -- Track inline interwiki links
  363. --
  364. CREATE TABLE /*_*/iwlinks (
  365. -- page_id of the referring page
  366. iwl_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  367. -- Interwiki prefix code of the target
  368. iwl_prefix nvarchar(20) NOT NULL default '',
  369. -- Title of the target, including namespace
  370. iwl_title nvarchar(255) NOT NULL default ''
  371. );
  372. CREATE UNIQUE INDEX /*i*/iwl_from ON /*_*/iwlinks (iwl_from, iwl_prefix, iwl_title);
  373. CREATE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
  374. CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
  375. --
  376. -- Contains a single row with some aggregate info
  377. -- on the state of the site.
  378. --
  379. CREATE TABLE /*_*/site_stats (
  380. -- The single row should contain 1 here.
  381. ss_row_id int NOT NULL,
  382. -- Total number of edits performed.
  383. ss_total_edits bigint default 0,
  384. -- An approximate count of pages matching the following criteria:
  385. -- * in namespace 0
  386. -- * not a redirect
  387. -- * contains the text '[['
  388. -- See Article::isCountable() in includes/Article.php
  389. ss_good_articles bigint default 0,
  390. -- Total pages, theoretically equal to SELECT COUNT(*) FROM page; except faster
  391. ss_total_pages bigint default '-1',
  392. -- Number of users, theoretically equal to SELECT COUNT(*) FROM user;
  393. ss_users bigint default '-1',
  394. -- Number of users that still edit
  395. ss_active_users bigint default '-1',
  396. -- Number of images, equivalent to SELECT COUNT(*) FROM image
  397. ss_images int default 0
  398. );
  399. -- Pointless index to assuage developer superstitions
  400. CREATE UNIQUE INDEX /*i*/ss_row_id ON /*_*/site_stats (ss_row_id);
  401. --
  402. -- The internet is full of jerks, alas. Sometimes it's handy
  403. -- to block a vandal or troll account.
  404. --
  405. CREATE TABLE /*_*/ipblocks (
  406. -- Primary key, introduced for privacy.
  407. ipb_id int NOT NULL PRIMARY KEY IDENTITY,
  408. -- Blocked IP address in dotted-quad form or user name.
  409. ipb_address nvarchar(255) NOT NULL,
  410. -- Blocked user ID or 0 for IP blocks.
  411. ipb_user int REFERENCES /*_*/mwuser(user_id),
  412. -- User ID who made the block.
  413. ipb_by int REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
  414. -- User name of blocker
  415. ipb_by_text nvarchar(255) NOT NULL default '',
  416. -- Text comment made by blocker.
  417. ipb_reason nvarchar(255) NOT NULL,
  418. -- Creation (or refresh) date in standard YMDHMS form.
  419. -- IP blocks expire automatically.
  420. ipb_timestamp varchar(14) NOT NULL default '',
  421. -- Indicates that the IP address was banned because a banned
  422. -- user accessed a page through it. If this is 1, ipb_address
  423. -- will be hidden, and the block identified by block ID number.
  424. ipb_auto bit NOT NULL default 0,
  425. -- If set to 1, block applies only to logged-out users
  426. ipb_anon_only bit NOT NULL default 0,
  427. -- Block prevents account creation from matching IP addresses
  428. ipb_create_account bit NOT NULL default 1,
  429. -- Block triggers autoblocks
  430. ipb_enable_autoblock bit NOT NULL default 1,
  431. -- Time at which the block will expire.
  432. -- May be "infinity"
  433. ipb_expiry varchar(14) NOT NULL,
  434. -- Start and end of an address range, in hexadecimal
  435. -- Size chosen to allow IPv6
  436. -- FIXME: these fields were originally blank for single-IP blocks,
  437. -- but now they are populated. No migration was ever done. They
  438. -- should be fixed to be blank again for such blocks (bug 49504).
  439. ipb_range_start varchar(255) NOT NULL,
  440. ipb_range_end varchar(255) NOT NULL,
  441. -- Flag for entries hidden from users and Sysops
  442. ipb_deleted bit NOT NULL default 0,
  443. -- Block prevents user from accessing Special:Emailuser
  444. ipb_block_email bit NOT NULL default 0,
  445. -- Block allows user to edit their own talk page
  446. ipb_allow_usertalk bit NOT NULL default 0,
  447. -- ID of the block that caused this block to exist
  448. -- Autoblocks set this to the original block
  449. -- so that the original block being deleted also
  450. -- deletes the autoblocks
  451. ipb_parent_block_id int default NULL REFERENCES /*_*/ipblocks(ipb_id)
  452. );
  453. -- Unique index to support "user already blocked" messages
  454. -- Any new options which prevent collisions should be included
  455. CREATE UNIQUE INDEX /*i*/ipb_address ON /*_*/ipblocks (ipb_address, ipb_user, ipb_auto, ipb_anon_only);
  456. CREATE INDEX /*i*/ipb_user ON /*_*/ipblocks (ipb_user);
  457. CREATE INDEX /*i*/ipb_range ON /*_*/ipblocks (ipb_range_start, ipb_range_end);
  458. CREATE INDEX /*i*/ipb_timestamp ON /*_*/ipblocks (ipb_timestamp);
  459. CREATE INDEX /*i*/ipb_expiry ON /*_*/ipblocks (ipb_expiry);
  460. CREATE INDEX /*i*/ipb_parent_block_id ON /*_*/ipblocks (ipb_parent_block_id);
  461. --
  462. -- Uploaded images and other files.
  463. --
  464. CREATE TABLE /*_*/image (
  465. -- Filename.
  466. -- This is also the title of the associated description page,
  467. -- which will be in namespace 6 (NS_FILE).
  468. img_name nvarchar(255) NOT NULL default '' PRIMARY KEY,
  469. -- File size in bytes.
  470. img_size int NOT NULL default 0,
  471. -- For images, size in pixels.
  472. img_width int NOT NULL default 0,
  473. img_height int NOT NULL default 0,
  474. -- Extracted Exif metadata stored as a serialized PHP array.
  475. img_metadata varbinary(max) NOT NULL,
  476. -- For images, bits per pixel if known.
  477. img_bits int NOT NULL default 0,
  478. -- Media type as defined by the MEDIATYPE_xxx constants
  479. img_media_type varchar(16) default null,
  480. -- major part of a MIME media type as defined by IANA
  481. -- see http://www.iana.org/assignments/media-types/
  482. img_major_mime varchar(16) not null default 'unknown',
  483. -- minor part of a MIME media type as defined by IANA
  484. -- the minor parts are not required to adher to any standard
  485. -- but should be consistent throughout the database
  486. -- see http://www.iana.org/assignments/media-types/
  487. img_minor_mime nvarchar(100) NOT NULL default 'unknown',
  488. -- Description field as entered by the uploader.
  489. -- This is displayed in image upload history and logs.
  490. img_description nvarchar(255) NOT NULL,
  491. -- user_id and user_name of uploader.
  492. img_user int REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
  493. img_user_text nvarchar(255) NOT NULL,
  494. -- Time of the upload.
  495. img_timestamp nvarchar(14) NOT NULL default '',
  496. -- SHA-1 content hash in base-36
  497. img_sha1 nvarchar(32) NOT NULL default '',
  498. CONSTRAINT img_major_mime_ckc check (img_major_mime IN('unknown', 'application', 'audio', 'image', 'text', 'video', 'message', 'model', 'multipart', 'chemical')),
  499. CONSTRAINT img_media_type_ckc check (img_media_type in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA', 'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))
  500. );
  501. CREATE INDEX /*i*/img_usertext_timestamp ON /*_*/image (img_user_text,img_timestamp);
  502. -- Used by Special:ListFiles for sort-by-size
  503. CREATE INDEX /*i*/img_size ON /*_*/image (img_size);
  504. -- Used by Special:Newimages and Special:ListFiles
  505. CREATE INDEX /*i*/img_timestamp ON /*_*/image (img_timestamp);
  506. -- Used in API and duplicate search
  507. CREATE INDEX /*i*/img_sha1 ON /*_*/image (img_sha1);
  508. -- Used to get media of one type
  509. CREATE INDEX /*i*/img_media_mime ON /*_*/image (img_media_type,img_major_mime,img_minor_mime);
  510. --
  511. -- Previous revisions of uploaded files.
  512. -- Awkwardly, image rows have to be moved into
  513. -- this table at re-upload time.
  514. --
  515. CREATE TABLE /*_*/oldimage (
  516. -- Base filename: key to image.img_name
  517. -- Not a FK because deleting images removes them from image
  518. oi_name nvarchar(255) NOT NULL default '',
  519. -- Filename of the archived file.
  520. -- This is generally a timestamp and '!' prepended to the base name.
  521. oi_archive_name nvarchar(255) NOT NULL default '',
  522. -- Other fields as in image...
  523. oi_size int NOT NULL default 0,
  524. oi_width int NOT NULL default 0,
  525. oi_height int NOT NULL default 0,
  526. oi_bits int NOT NULL default 0,
  527. oi_description nvarchar(255) NOT NULL,
  528. oi_user int REFERENCES /*_*/mwuser(user_id),
  529. oi_user_text nvarchar(255) NOT NULL,
  530. oi_timestamp varchar(14) NOT NULL default '',
  531. oi_metadata varbinary(max) NOT NULL,
  532. oi_media_type varchar(16) default null,
  533. oi_major_mime varchar(16) not null default 'unknown',
  534. oi_minor_mime nvarchar(100) NOT NULL default 'unknown',
  535. oi_deleted tinyint NOT NULL default 0,
  536. oi_sha1 nvarchar(32) NOT NULL default '',
  537. CONSTRAINT oi_major_mime_ckc check (oi_major_mime IN('unknown', 'application', 'audio', 'image', 'text', 'video', 'message', 'model', 'multipart', 'chemical')),
  538. CONSTRAINT oi_media_type_ckc check (oi_media_type IN('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA', 'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))
  539. );
  540. CREATE INDEX /*i*/oi_usertext_timestamp ON /*_*/oldimage (oi_user_text,oi_timestamp);
  541. CREATE INDEX /*i*/oi_name_timestamp ON /*_*/oldimage (oi_name,oi_timestamp);
  542. CREATE INDEX /*i*/oi_sha1 ON /*_*/oldimage (oi_sha1);
  543. --
  544. -- Record of deleted file data
  545. --
  546. CREATE TABLE /*_*/filearchive (
  547. -- Unique row id
  548. fa_id int NOT NULL PRIMARY KEY IDENTITY,
  549. -- Original base filename; key to image.img_name, page.page_title, etc
  550. fa_name nvarchar(255) NOT NULL default '',
  551. -- Filename of archived file, if an old revision
  552. fa_archive_name nvarchar(255) default '',
  553. -- Which storage bin (directory tree or object store) the file data
  554. -- is stored in. Should be 'deleted' for files that have been deleted;
  555. -- any other bin is not yet in use.
  556. fa_storage_group nvarchar(16),
  557. -- SHA-1 of the file contents plus extension, used as a key for storage.
  558. -- eg 8f8a562add37052a1848ff7771a2c515db94baa9.jpg
  559. --
  560. -- If NULL, the file was missing at deletion time or has been purged
  561. -- from the archival storage.
  562. fa_storage_key nvarchar(64) default '',
  563. -- Deletion information, if this file is deleted.
  564. fa_deleted_user int,
  565. fa_deleted_timestamp varchar(14) default '',
  566. fa_deleted_reason nvarchar(max),
  567. -- Duped fields from image
  568. fa_size int default 0,
  569. fa_width int default 0,
  570. fa_height int default 0,
  571. fa_metadata varbinary(max),
  572. fa_bits int default 0,
  573. fa_media_type varchar(16) default null,
  574. fa_major_mime varchar(16) not null default 'unknown',
  575. fa_minor_mime nvarchar(100) default 'unknown',
  576. fa_description nvarchar(255),
  577. fa_user int default 0 REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
  578. fa_user_text nvarchar(255),
  579. fa_timestamp varchar(14) default '',
  580. -- Visibility of deleted revisions, bitfield
  581. fa_deleted tinyint NOT NULL default 0,
  582. -- sha1 hash of file content
  583. fa_sha1 nvarchar(32) NOT NULL default '',
  584. CONSTRAINT fa_major_mime_ckc check (fa_major_mime in('unknown', 'application', 'audio', 'image', 'text', 'video', 'message', 'model', 'multipart', 'chemical')),
  585. CONSTRAINT fa_media_type_ckc check (fa_media_type in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA', 'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))
  586. );
  587. -- pick out by image name
  588. CREATE INDEX /*i*/fa_name ON /*_*/filearchive (fa_name, fa_timestamp);
  589. -- pick out dupe files
  590. CREATE INDEX /*i*/fa_storage_group ON /*_*/filearchive (fa_storage_group, fa_storage_key);
  591. -- sort by deletion time
  592. CREATE INDEX /*i*/fa_deleted_timestamp ON /*_*/filearchive (fa_deleted_timestamp);
  593. -- sort by uploader
  594. CREATE INDEX /*i*/fa_user_timestamp ON /*_*/filearchive (fa_user_text,fa_timestamp);
  595. -- find file by sha1, 10 bytes will be enough for hashes to be indexed
  596. CREATE INDEX /*i*/fa_sha1 ON /*_*/filearchive (fa_sha1);
  597. --
  598. -- Store information about newly uploaded files before they're
  599. -- moved into the actual filestore
  600. --
  601. CREATE TABLE /*_*/uploadstash (
  602. us_id int NOT NULL PRIMARY KEY IDENTITY,
  603. -- the user who uploaded the file.
  604. us_user int REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
  605. -- file key. this is how applications actually search for the file.
  606. -- this might go away, or become the primary key.
  607. us_key nvarchar(255) NOT NULL,
  608. -- the original path
  609. us_orig_path nvarchar(255) NOT NULL,
  610. -- the temporary path at which the file is actually stored
  611. us_path nvarchar(255) NOT NULL,
  612. -- which type of upload the file came from (sometimes)
  613. us_source_type nvarchar(50),
  614. -- the date/time on which the file was added
  615. us_timestamp varchar(14) NOT NULL,
  616. us_status nvarchar(50) NOT NULL,
  617. -- chunk counter starts at 0, current offset is stored in us_size
  618. us_chunk_inx int NULL,
  619. -- Serialized file properties from FSFile::getProps()
  620. us_props nvarchar(max),
  621. -- file size in bytes
  622. us_size int NOT NULL,
  623. -- this hash comes from FSFile::getSha1Base36(), and is 31 characters
  624. us_sha1 nvarchar(31) NOT NULL,
  625. us_mime nvarchar(255),
  626. -- Media type as defined by the MEDIATYPE_xxx constants, should duplicate definition in the image table
  627. us_media_type varchar(16) default null,
  628. -- image-specific properties
  629. us_image_width int,
  630. us_image_height int,
  631. us_image_bits smallint,
  632. CONSTRAINT us_media_type_ckc check (us_media_type in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA', 'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))
  633. );
  634. -- sometimes there's a delete for all of a user's stuff.
  635. CREATE INDEX /*i*/us_user ON /*_*/uploadstash (us_user);
  636. -- pick out files by key, enforce key uniqueness
  637. CREATE UNIQUE INDEX /*i*/us_key ON /*_*/uploadstash (us_key);
  638. -- the abandoned upload cleanup script needs this
  639. CREATE INDEX /*i*/us_timestamp ON /*_*/uploadstash (us_timestamp);
  640. --
  641. -- Primarily a summary table for Special:Recentchanges,
  642. -- this table contains some additional info on edits from
  643. -- the last few days, see Article::editUpdates()
  644. --
  645. CREATE TABLE /*_*/recentchanges (
  646. rc_id int NOT NULL CONSTRAINT recentchanges__pk PRIMARY KEY IDENTITY,
  647. rc_timestamp varchar(14) not null default '',
  648. -- As in revision
  649. rc_user int NOT NULL default 0 CONSTRAINT rc_user__user_id__fk FOREIGN KEY REFERENCES /*_*/mwuser(user_id),
  650. rc_user_text nvarchar(255) NOT NULL,
  651. -- When pages are renamed, their RC entries do _not_ change.
  652. rc_namespace int NOT NULL default 0,
  653. rc_title nvarchar(255) NOT NULL default '',
  654. -- as in revision...
  655. rc_comment nvarchar(255) NOT NULL default '',
  656. rc_minor bit NOT NULL default 0,
  657. -- Edits by user accounts with the 'bot' rights key are
  658. -- marked with a 1 here, and will be hidden from the
  659. -- default view.
  660. rc_bot bit NOT NULL default 0,
  661. -- Set if this change corresponds to a page creation
  662. rc_new bit NOT NULL default 0,
  663. -- Key to page_id (was cur_id prior to 1.5).
  664. -- This will keep links working after moves while
  665. -- retaining the at-the-time name in the changes list.
  666. rc_cur_id int, -- NOT FK
  667. -- rev_id of the given revision
  668. rc_this_oldid int, -- NOT FK
  669. -- rev_id of the prior revision, for generating diff links.
  670. rc_last_oldid int, -- NOT FK
  671. -- The type of change entry (RC_EDIT,RC_NEW,RC_LOG,RC_EXTERNAL)
  672. rc_type tinyint NOT NULL default 0,
  673. -- The source of the change entry (replaces rc_type)
  674. -- default of '' is temporary, needed for initial migration
  675. rc_source nvarchar(16) not null default '',
  676. -- If the Recent Changes Patrol option is enabled,
  677. -- users may mark edits as having been reviewed to
  678. -- remove a warning flag on the RC list.
  679. -- A value of 1 indicates the page has been reviewed.
  680. rc_patrolled bit NOT NULL default 0,
  681. -- Recorded IP address the edit was made from, if the
  682. -- $wgPutIPinRC option is enabled.
  683. rc_ip nvarchar(40) NOT NULL default '',
  684. -- Text length in characters before
  685. -- and after the edit
  686. rc_old_len int,
  687. rc_new_len int,
  688. -- Visibility of recent changes items, bitfield
  689. rc_deleted tinyint NOT NULL default 0,
  690. -- Value corresponding to log_id, specific log entries
  691. rc_logid int, -- FK added later
  692. -- Store log type info here, or null
  693. rc_log_type nvarchar(255) NULL default NULL,
  694. -- Store log action or null
  695. rc_log_action nvarchar(255) NULL default NULL,
  696. -- Log params
  697. rc_params nvarchar(max) NULL
  698. );
  699. CREATE INDEX /*i*/rc_timestamp ON /*_*/recentchanges (rc_timestamp);
  700. CREATE INDEX /*i*/rc_namespace_title ON /*_*/recentchanges (rc_namespace, rc_title);
  701. CREATE INDEX /*i*/rc_cur_id ON /*_*/recentchanges (rc_cur_id);
  702. CREATE INDEX /*i*/new_name_timestamp ON /*_*/recentchanges (rc_new,rc_namespace,rc_timestamp);
  703. CREATE INDEX /*i*/rc_ip ON /*_*/recentchanges (rc_ip);
  704. CREATE INDEX /*i*/rc_ns_usertext ON /*_*/recentchanges (rc_namespace, rc_user_text);
  705. CREATE INDEX /*i*/rc_user_text ON /*_*/recentchanges (rc_user_text, rc_timestamp);
  706. CREATE TABLE /*_*/watchlist (
  707. wl_id int NOT NULL PRIMARY KEY IDENTITY,
  708. -- Key to user.user_id
  709. wl_user int NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
  710. -- Key to page_namespace/page_title
  711. -- Note that users may watch pages which do not exist yet,
  712. -- or existed in the past but have been deleted.
  713. wl_namespace int NOT NULL default 0,
  714. wl_title nvarchar(255) NOT NULL default '',
  715. -- Timestamp used to send notification e-mails and show "updated since last visit" markers on
  716. -- history and recent changes / watchlist. Set to NULL when the user visits the latest revision
  717. -- of the page, which means that they should be sent an e-mail on the next change.
  718. wl_notificationtimestamp varchar(14)
  719. );
  720. CREATE UNIQUE INDEX /*i*/wl_user ON /*_*/watchlist (wl_user, wl_namespace, wl_title);
  721. CREATE INDEX /*i*/namespace_title ON /*_*/watchlist (wl_namespace, wl_title);
  722. --
  723. -- Our search index for the builtin MediaWiki search
  724. --
  725. CREATE TABLE /*_*/searchindex (
  726. -- Key to page_id
  727. si_page int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  728. -- Munged version of title
  729. si_title nvarchar(255) NOT NULL default '',
  730. -- Munged version of body text
  731. si_text nvarchar(max) NOT NULL
  732. );
  733. CREATE UNIQUE INDEX /*i*/si_page ON /*_*/searchindex (si_page);
  734. -- Fulltext index is defined in MssqlInstaller.php
  735. --
  736. -- Recognized interwiki link prefixes
  737. --
  738. CREATE TABLE /*_*/interwiki (
  739. -- The interwiki prefix, (e.g. "Meatball", or the language prefix "de")
  740. iw_prefix nvarchar(32) NOT NULL,
  741. -- The URL of the wiki, with "$1" as a placeholder for an article name.
  742. -- Any spaces in the name will be transformed to underscores before
  743. -- insertion.
  744. iw_url nvarchar(max) NOT NULL,
  745. -- The URL of the file api.php
  746. iw_api nvarchar(max) NOT NULL,
  747. -- The name of the database (for a connection to be established with wfGetLB( 'wikiid' ))
  748. iw_wikiid nvarchar(64) NOT NULL,
  749. -- A boolean value indicating whether the wiki is in this project
  750. -- (used, for example, to detect redirect loops)
  751. iw_local bit NOT NULL,
  752. -- Boolean value indicating whether interwiki transclusions are allowed.
  753. iw_trans bit NOT NULL default 0
  754. );
  755. CREATE UNIQUE INDEX /*i*/iw_prefix ON /*_*/interwiki (iw_prefix);
  756. --
  757. -- Used for caching expensive grouped queries
  758. --
  759. CREATE TABLE /*_*/querycache (
  760. -- A key name, generally the base name of of the special page.
  761. qc_type nvarchar(32) NOT NULL,
  762. -- Some sort of stored value. Sizes, counts...
  763. qc_value int NOT NULL default 0,
  764. -- Target namespace+title
  765. qc_namespace int NOT NULL default 0,
  766. qc_title nvarchar(255) NOT NULL default ''
  767. );
  768. CREATE INDEX /*i*/qc_type ON /*_*/querycache (qc_type,qc_value);
  769. --
  770. -- For a few generic cache operations if not using Memcached
  771. --
  772. CREATE TABLE /*_*/objectcache (
  773. keyname nvarchar(255) NOT NULL default '' PRIMARY KEY,
  774. value varbinary(max),
  775. exptime varchar(14)
  776. );
  777. CREATE INDEX /*i*/exptime ON /*_*/objectcache (exptime);
  778. --
  779. -- Cache of interwiki transclusion
  780. --
  781. CREATE TABLE /*_*/transcache (
  782. tc_url nvarchar(255) NOT NULL,
  783. tc_contents nvarchar(max),
  784. tc_time varchar(14) NOT NULL
  785. );
  786. CREATE UNIQUE INDEX /*i*/tc_url_idx ON /*_*/transcache (tc_url);
  787. CREATE TABLE /*_*/logging (
  788. -- Log ID, for referring to this specific log entry, probably for deletion and such.
  789. log_id int NOT NULL PRIMARY KEY IDENTITY(0,1),
  790. -- Symbolic keys for the general log type and the action type
  791. -- within the log. The output format will be controlled by the
  792. -- action field, but only the type controls categorization.
  793. log_type nvarchar(32) NOT NULL default '',
  794. log_action nvarchar(32) NOT NULL default '',
  795. -- Timestamp. Duh.
  796. log_timestamp varchar(14) NOT NULL default '',
  797. -- The user who performed this action; key to user_id
  798. log_user int, -- NOT an FK, if a user is deleted we still want to maintain a record of who did a thing
  799. -- Name of the user who performed this action
  800. log_user_text nvarchar(255) NOT NULL default '',
  801. -- Key to the page affected. Where a user is the target,
  802. -- this will point to the user page.
  803. log_namespace int NOT NULL default 0,
  804. log_title nvarchar(255) NOT NULL default '',
  805. log_page int NULL, -- NOT an FK, logging entries are inserted for deleted pages which still reference the deleted page ids
  806. -- Freeform text. Interpreted as edit history comments.
  807. log_comment nvarchar(255) NOT NULL default '',
  808. -- miscellaneous parameters:
  809. -- LF separated list (old system) or serialized PHP array (new system)
  810. log_params nvarchar(max) NOT NULL,
  811. -- rev_deleted for logs
  812. log_deleted tinyint NOT NULL default 0
  813. );
  814. CREATE INDEX /*i*/type_time ON /*_*/logging (log_type, log_timestamp);
  815. CREATE INDEX /*i*/user_time ON /*_*/logging (log_user, log_timestamp);
  816. CREATE INDEX /*i*/page_time ON /*_*/logging (log_namespace, log_title, log_timestamp);
  817. CREATE INDEX /*i*/times ON /*_*/logging (log_timestamp);
  818. CREATE INDEX /*i*/log_user_type_time ON /*_*/logging (log_user, log_type, log_timestamp);
  819. CREATE INDEX /*i*/log_page_id_time ON /*_*/logging (log_page,log_timestamp);
  820. CREATE INDEX /*i*/type_action ON /*_*/logging (log_type, log_action, log_timestamp);
  821. CREATE INDEX /*i*/log_user_text_type_time ON /*_*/logging (log_user_text, log_type, log_timestamp);
  822. CREATE INDEX /*i*/log_user_text_time ON /*_*/logging (log_user_text, log_timestamp);
  823. INSERT INTO /*_*/logging (log_user,log_page,log_params) VALUES(0,0,'');
  824. ALTER TABLE /*_*/recentchanges ADD CONSTRAINT rc_logid__log_id__fk FOREIGN KEY (rc_logid) REFERENCES /*_*/logging(log_id) ON DELETE CASCADE;
  825. CREATE TABLE /*_*/log_search (
  826. -- The type of ID (rev ID, log ID, rev timestamp, username)
  827. ls_field nvarchar(32) NOT NULL,
  828. -- The value of the ID
  829. ls_value nvarchar(255) NOT NULL,
  830. -- Key to log_id
  831. ls_log_id int REFERENCES /*_*/logging(log_id) ON DELETE CASCADE
  832. );
  833. CREATE UNIQUE INDEX /*i*/ls_field_val ON /*_*/log_search (ls_field,ls_value,ls_log_id);
  834. CREATE INDEX /*i*/ls_log_id ON /*_*/log_search (ls_log_id);
  835. -- Jobs performed by parallel apache threads or a command-line daemon
  836. CREATE TABLE /*_*/job (
  837. job_id int NOT NULL PRIMARY KEY IDENTITY,
  838. -- Command name
  839. -- Limited to 60 to prevent key length overflow
  840. job_cmd nvarchar(60) NOT NULL default '',
  841. -- Namespace and title to act on
  842. -- Should be 0 and '' if the command does not operate on a title
  843. job_namespace int NOT NULL,
  844. job_title nvarchar(255) NOT NULL,
  845. -- Timestamp of when the job was inserted
  846. -- NULL for jobs added before addition of the timestamp
  847. job_timestamp nvarchar(14) NULL default NULL,
  848. -- Any other parameters to the command
  849. -- Stored as a PHP serialized array, or an empty string if there are no parameters
  850. job_params nvarchar(max) NOT NULL,
  851. -- Random, non-unique, number used for job acquisition (for lock concurrency)
  852. job_random int NOT NULL default 0,
  853. -- The number of times this job has been locked
  854. job_attempts int NOT NULL default 0,
  855. -- Field that conveys process locks on rows via process UUIDs
  856. job_token nvarchar(32) NOT NULL default '',
  857. -- Timestamp when the job was locked
  858. job_token_timestamp varchar(14) NULL default NULL,
  859. -- Base 36 SHA1 of the job parameters relevant to detecting duplicates
  860. job_sha1 nvarchar(32) NOT NULL default ''
  861. );
  862. CREATE INDEX /*i*/job_sha1 ON /*_*/job (job_sha1);
  863. CREATE INDEX /*i*/job_cmd_token ON /*_*/job (job_cmd,job_token,job_random);
  864. CREATE INDEX /*i*/job_cmd_token_id ON /*_*/job (job_cmd,job_token,job_id);
  865. CREATE INDEX /*i*/job_cmd ON /*_*/job (job_cmd, job_namespace, job_title);
  866. CREATE INDEX /*i*/job_timestamp ON /*_*/job (job_timestamp);
  867. -- Details of updates to cached special pages
  868. CREATE TABLE /*_*/querycache_info (
  869. -- Special page name
  870. -- Corresponds to a qc_type value
  871. qci_type nvarchar(32) NOT NULL default '',
  872. -- Timestamp of last update
  873. qci_timestamp varchar(14) NOT NULL default ''
  874. );
  875. CREATE UNIQUE INDEX /*i*/qci_type ON /*_*/querycache_info (qci_type);
  876. -- For each redirect, this table contains exactly one row defining its target
  877. CREATE TABLE /*_*/redirect (
  878. -- Key to the page_id of the redirect page
  879. rd_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  880. -- Key to page_namespace/page_title of the target page.
  881. -- The target page may or may not exist, and due to renames
  882. -- and deletions may refer to different page records as time
  883. -- goes by.
  884. rd_namespace int NOT NULL default 0,
  885. rd_title nvarchar(255) NOT NULL default '',
  886. rd_interwiki nvarchar(32) default NULL,
  887. rd_fragment nvarchar(255) default NULL
  888. );
  889. CREATE INDEX /*i*/rd_ns_title ON /*_*/redirect (rd_namespace,rd_title,rd_from);
  890. -- Used for caching expensive grouped queries that need two links (for example double-redirects)
  891. CREATE TABLE /*_*/querycachetwo (
  892. -- A key name, generally the base name of of the special page.
  893. qcc_type nvarchar(32) NOT NULL,
  894. -- Some sort of stored value. Sizes, counts...
  895. qcc_value int NOT NULL default 0,
  896. -- Target namespace+title
  897. qcc_namespace int NOT NULL default 0,
  898. qcc_title nvarchar(255) NOT NULL default '',
  899. -- Target namespace+title2
  900. qcc_namespacetwo int NOT NULL default 0,
  901. qcc_titletwo nvarchar(255) NOT NULL default ''
  902. );
  903. CREATE INDEX /*i*/qcc_type ON /*_*/querycachetwo (qcc_type,qcc_value);
  904. CREATE INDEX /*i*/qcc_title ON /*_*/querycachetwo (qcc_type,qcc_namespace,qcc_title);
  905. CREATE INDEX /*i*/qcc_titletwo ON /*_*/querycachetwo (qcc_type,qcc_namespacetwo,qcc_titletwo);
  906. -- Used for storing page restrictions (i.e. protection levels)
  907. CREATE TABLE /*_*/page_restrictions (
  908. -- Field for an ID for this restrictions row (sort-key for Special:ProtectedPages)
  909. pr_id int NOT NULL PRIMARY KEY IDENTITY,
  910. -- Page to apply restrictions to (Foreign Key to page).
  911. pr_page int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  912. -- The protection type (edit, move, etc)
  913. pr_type nvarchar(60) NOT NULL,
  914. -- The protection level (Sysop, autoconfirmed, etc)
  915. pr_level nvarchar(60) NOT NULL,
  916. -- Whether or not to cascade the protection down to pages transcluded.
  917. pr_cascade bit NOT NULL,
  918. -- Field for future support of per-user restriction.
  919. pr_user int NULL,
  920. -- Field for time-limited protection.
  921. pr_expiry varchar(14) NULL
  922. );
  923. CREATE UNIQUE INDEX /*i*/pr_pagetype ON /*_*/page_restrictions (pr_page,pr_type);
  924. CREATE INDEX /*i*/pr_typelevel ON /*_*/page_restrictions (pr_type,pr_level);
  925. CREATE INDEX /*i*/pr_level ON /*_*/page_restrictions (pr_level);
  926. CREATE INDEX /*i*/pr_cascade ON /*_*/page_restrictions (pr_cascade);
  927. -- Protected titles - nonexistent pages that have been protected
  928. CREATE TABLE /*_*/protected_titles (
  929. pt_namespace int NOT NULL,
  930. pt_title nvarchar(255) NOT NULL,
  931. pt_user int REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
  932. pt_reason nvarchar(255),
  933. pt_timestamp varchar(14) NOT NULL,
  934. pt_expiry varchar(14) NOT NULL,
  935. pt_create_perm nvarchar(60) NOT NULL
  936. );
  937. CREATE UNIQUE INDEX /*i*/pt_namespace_title ON /*_*/protected_titles (pt_namespace,pt_title);
  938. CREATE INDEX /*i*/pt_timestamp ON /*_*/protected_titles (pt_timestamp);
  939. -- Name/value pairs indexed by page_id
  940. CREATE TABLE /*_*/page_props (
  941. pp_page int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
  942. pp_propname nvarchar(60) NOT NULL,
  943. pp_value nvarchar(max) NOT NULL,
  944. pp_sortkey float DEFAULT NULL
  945. );
  946. CREATE UNIQUE INDEX /*i*/pp_page_propname ON /*_*/page_props (pp_page,pp_propname);
  947. CREATE UNIQUE INDEX /*i*/pp_propname_page ON /*_*/page_props (pp_propname,pp_page);
  948. CREATE UNIQUE INDEX /*i*/pp_propname_sortkey_page ON /*_*/page_props (pp_propname,pp_sortkey,pp_page);
  949. -- A table to log updates, one text key row per update.
  950. CREATE TABLE /*_*/updatelog (
  951. ul_key nvarchar(255) NOT NULL PRIMARY KEY,
  952. ul_value nvarchar(max)
  953. );
  954. -- A table to track tags for revisions, logs and recent changes.
  955. CREATE TABLE /*_*/change_tag (
  956. -- RCID for the change
  957. ct_rc_id int NULL REFERENCES /*_*/recentchanges(rc_id),
  958. -- LOGID for the change
  959. ct_log_id int NULL REFERENCES /*_*/logging(log_id),
  960. -- REVID for the change
  961. ct_rev_id int NULL REFERENCES /*_*/revision(rev_id),
  962. -- Tag applied
  963. ct_tag nvarchar(255) NOT NULL,
  964. -- Parameters for the tag, presently unused
  965. ct_params nvarchar(max) NULL
  966. );
  967. CREATE UNIQUE INDEX /*i*/change_tag_rc_tag ON /*_*/change_tag (ct_rc_id,ct_tag);
  968. CREATE UNIQUE INDEX /*i*/change_tag_log_tag ON /*_*/change_tag (ct_log_id,ct_tag);
  969. CREATE UNIQUE INDEX /*i*/change_tag_rev_tag ON /*_*/change_tag (ct_rev_id,ct_tag);
  970. -- Covering index, so we can pull all the info only out of the index.
  971. CREATE INDEX /*i*/change_tag_tag_id ON /*_*/change_tag (ct_tag,ct_rc_id,ct_rev_id,ct_log_id);
  972. -- Rollup table to pull a LIST of tags simply without ugly GROUP_CONCAT
  973. -- that only works on MySQL 4.1+
  974. CREATE TABLE /*_*/tag_summary (
  975. -- RCID for the change
  976. ts_rc_id int NULL REFERENCES /*_*/recentchanges(rc_id),
  977. -- LOGID for the change
  978. ts_log_id int NULL REFERENCES /*_*/logging(log_id),
  979. -- REVID for the change
  980. ts_rev_id int NULL REFERENCES /*_*/revision(rev_id),
  981. -- Comma-separated list of tags
  982. ts_tags nvarchar(max) NOT NULL
  983. );
  984. CREATE UNIQUE INDEX /*i*/tag_summary_rc_id ON /*_*/tag_summary (ts_rc_id);
  985. CREATE UNIQUE INDEX /*i*/tag_summary_log_id ON /*_*/tag_summary (ts_log_id);
  986. CREATE UNIQUE INDEX /*i*/tag_summary_rev_id ON /*_*/tag_summary (ts_rev_id);
  987. CREATE TABLE /*_*/valid_tag (
  988. vt_tag nvarchar(255) NOT NULL PRIMARY KEY
  989. );
  990. -- Table for storing localisation data
  991. CREATE TABLE /*_*/l10n_cache (
  992. -- Language code
  993. lc_lang nvarchar(32) NOT NULL,
  994. -- Cache key
  995. lc_key nvarchar(255) NOT NULL,
  996. -- Value
  997. lc_value varbinary(max) NOT NULL
  998. );
  999. CREATE INDEX /*i*/lc_lang_key ON /*_*/l10n_cache (lc_lang, lc_key);
  1000. -- Table caching which local files a module depends on that aren't
  1001. -- registered directly, used for fast retrieval of file dependency.
  1002. -- Currently only used for tracking images that CSS depends on
  1003. CREATE TABLE /*_*/module_deps (
  1004. -- Module name
  1005. md_module nvarchar(255) NOT NULL,
  1006. -- Skin name
  1007. md_skin nvarchar(32) NOT NULL,
  1008. -- JSON nvarchar(max) with file dependencies
  1009. md_deps nvarchar(max) NOT NULL
  1010. );
  1011. CREATE UNIQUE INDEX /*i*/md_module_skin ON /*_*/module_deps (md_module, md_skin);
  1012. -- Holds all the sites known to the wiki.
  1013. CREATE TABLE /*_*/sites (
  1014. -- Numeric id of the site
  1015. site_id int NOT NULL PRIMARY KEY IDENTITY,
  1016. -- Global identifier for the site, ie 'enwiktionary'
  1017. site_global_key nvarchar(32) NOT NULL,
  1018. -- Type of the site, ie 'mediawiki'
  1019. site_type nvarchar(32) NOT NULL,
  1020. -- Group of the site, ie 'wikipedia'
  1021. site_group nvarchar(32) NOT NULL,
  1022. -- Source of the site data, ie 'local', 'wikidata', 'my-magical-repo'
  1023. site_source nvarchar(32) NOT NULL,
  1024. -- Language code of the sites primary language.
  1025. site_language nvarchar(32) NOT NULL,
  1026. -- Protocol of the site, ie 'http://', 'irc://', '//'
  1027. -- This field is an index for lookups and is build from type specific data in site_data.
  1028. site_protocol nvarchar(32) NOT NULL,
  1029. -- Domain of the site in reverse order, ie 'org.mediawiki.www.'
  1030. -- This field is an index for lookups and is build from type specific data in site_data.
  1031. site_domain NVARCHAR(255) NOT NULL,
  1032. -- Type dependent site data.
  1033. site_data nvarchar(max) NOT NULL,
  1034. -- If site.tld/path/key:pageTitle should forward users to the page on
  1035. -- the actual site, where "key" is the local identifier.
  1036. site_forward bit NOT NULL,
  1037. -- Type dependent site config.
  1038. -- For instance if template transclusion should be allowed if it's a MediaWiki.
  1039. site_config nvarchar(max) NOT NULL
  1040. );
  1041. CREATE UNIQUE INDEX /*i*/sites_global_key ON /*_*/sites (site_global_key);
  1042. CREATE INDEX /*i*/sites_type ON /*_*/sites (site_type);
  1043. CREATE INDEX /*i*/sites_group ON /*_*/sites (site_group);
  1044. CREATE INDEX /*i*/sites_source ON /*_*/sites (site_source);
  1045. CREATE INDEX /*i*/sites_language ON /*_*/sites (site_language);
  1046. CREATE INDEX /*i*/sites_protocol ON /*_*/sites (site_protocol);
  1047. CREATE INDEX /*i*/sites_domain ON /*_*/sites (site_domain);
  1048. CREATE INDEX /*i*/sites_forward ON /*_*/sites (site_forward);
  1049. -- Links local site identifiers to their corresponding site.
  1050. CREATE TABLE /*_*/site_identifiers (
  1051. -- Key on site.site_id
  1052. si_site int NOT NULL REFERENCES /*_*/sites(site_id) ON DELETE CASCADE,
  1053. -- local key type, ie 'interwiki' or 'langlink'
  1054. si_type nvarchar(32) NOT NULL,
  1055. -- local key value, ie 'en' or 'wiktionary'
  1056. si_key nvarchar(32) NOT NULL
  1057. );
  1058. CREATE UNIQUE INDEX /*i*/site_ids_type ON /*_*/site_identifiers (si_type, si_key);
  1059. CREATE INDEX /*i*/site_ids_site ON /*_*/site_identifiers (si_site);
  1060. CREATE INDEX /*i*/site_ids_key ON /*_*/site_identifiers (si_key);