Merge "Add support for 'hu-formal'"
[lhc/web/wiklou.git] / maintenance / mssql / tables.sql
1 -- Experimental table definitions for Microsoft SQL Server with
2 -- content-holding fields switched to explicit BINARY charset.
3 -- ------------------------------------------------------------
4
5 -- SQL to create the initial tables for the MediaWiki database.
6 -- This is read and executed by the install script; you should
7 -- not have to run it by itself unless doing a manual install.
8
9 --
10 -- General notes:
11 --
12 -- The comments in this and other files are
13 -- replaced with the defined table prefix by the installer
14 -- and updater scripts. If you are installing or running
15 -- updates manually, you will need to manually insert the
16 -- table prefix if any when running these scripts.
17 --
18
19
20 --
21 -- The user table contains basic account information,
22 -- authentication keys, etc.
23 --
24 -- Some multi-wiki sites may share a single central user table
25 -- between separate wikis using the $wgSharedDB setting.
26 --
27 -- Note that when a external authentication plugin is used,
28 -- user table entries still need to be created to store
29 -- preferences and to key tracking information in the other
30 -- tables.
31
32 -- LINE:53
33 CREATE TABLE /*_*/mwuser (
34 user_id INT NOT NULL PRIMARY KEY IDENTITY(0,1),
35 user_name NVARCHAR(255) NOT NULL UNIQUE DEFAULT '',
36 user_real_name NVARCHAR(255) NOT NULL DEFAULT '',
37 user_password NVARCHAR(255) NOT NULL DEFAULT '',
38 user_newpassword NVARCHAR(255) NOT NULL DEFAULT '',
39 user_newpass_time varchar(14) NULL DEFAULT NULL,
40 user_email NVARCHAR(255) NOT NULL DEFAULT '',
41 user_touched varchar(14) NOT NULL DEFAULT '',
42 user_token NCHAR(32) NOT NULL DEFAULT '',
43 user_email_authenticated varchar(14) DEFAULT NULL,
44 user_email_token NCHAR(32) DEFAULT '',
45 user_email_token_expires varchar(14) DEFAULT NULL,
46 user_registration varchar(14) DEFAULT NULL,
47 user_editcount INT NULL DEFAULT NULL,
48 user_password_expires varchar(14) DEFAULT NULL
49 );
50 CREATE UNIQUE INDEX /*i*/user_name ON /*_*/mwuser (user_name);
51 CREATE INDEX /*i*/user_email_token ON /*_*/mwuser (user_email_token);
52 CREATE INDEX /*i*/user_email ON /*_*/mwuser (user_email);
53
54 -- Insert a dummy user to represent anons
55 INSERT INTO /*_*/mwuser (user_name) VALUES ('##Anonymous##');
56
57 --
58 -- The "actor" table associates user names or IP addresses with integers for
59 -- the benefit of other tables that need to refer to either logged-in or
60 -- logged-out users. If something can only ever be done by logged-in users, it
61 -- can refer to the user table directly.
62 --
63 CREATE TABLE /*_*/actor (
64 actor_id bigint unsigned NOT NULL CONSTRAINT PK_actor PRIMARY KEY IDENTITY(0,1),
65 actor_user int unsigned,
66 actor_name nvarchar(255) NOT NULL
67 );
68 CREATE UNIQUE INDEX /*i*/actor_user ON /*_*/actor (actor_user);
69 CREATE UNIQUE INDEX /*i*/actor_name ON /*_*/actor (actor_name);
70
71 -- Insert a dummy actor to represent no actor
72 INSERT INTO /*_*/actor (actor_name) VALUES ('##Anonymous##');
73
74 --
75 -- User permissions have been broken out to a separate table;
76 -- this allows sites with a shared user table to have different
77 -- permissions assigned to a user in each project.
78 --
79 -- This table replaces the old user_rights field which used a
80 -- comma-separated nvarchar(max).
81 CREATE TABLE /*_*/user_groups (
82 ug_user INT NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
83 ug_group NVARCHAR(255) NOT NULL DEFAULT '',
84 ug_expiry varchar(14) DEFAULT NULL,
85 PRIMARY KEY(ug_user, ug_group)
86 );
87 CREATE INDEX /*i*/ug_group ON /*_*/user_groups(ug_group);
88 CREATE INDEX /*i*/ug_expiry ON /*_*/user_groups(ug_expiry);
89
90 -- Stores the groups the user has once belonged to.
91 -- The user may still belong to these groups (check user_groups).
92 -- Users are not autopromoted to groups from which they were removed.
93 CREATE TABLE /*_*/user_former_groups (
94 ufg_user INT NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
95 ufg_group nvarchar(255) NOT NULL default ''
96 );
97 CREATE UNIQUE INDEX /*i*/ufg_user_group ON /*_*/user_former_groups (ufg_user,ufg_group);
98
99 -- Stores notifications of user talk page changes, for the display
100 -- of the "you have new messages" box
101 -- Changed user_id column to user_id to avoid clashing with user_id function
102 CREATE TABLE /*_*/user_newtalk (
103 user_id INT NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
104 user_ip NVARCHAR(40) NOT NULL DEFAULT '',
105 user_last_timestamp varchar(14) DEFAULT NULL,
106 );
107 CREATE INDEX /*i*/un_user_id ON /*_*/user_newtalk (user_id);
108 CREATE INDEX /*i*/un_user_ip ON /*_*/user_newtalk (user_ip);
109
110 --
111 -- User preferences and other fun stuff
112 -- replaces old user.user_options nvarchar(max)
113 --
114 CREATE TABLE /*_*/user_properties (
115 up_user INT NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
116 up_property NVARCHAR(255) NOT NULL,
117 up_value NVARCHAR(MAX),
118 );
119 CREATE UNIQUE CLUSTERED INDEX /*i*/user_properties_user_property ON /*_*/user_properties (up_user,up_property);
120 CREATE INDEX /*i*/user_properties_property ON /*_*/user_properties (up_property);
121
122 --
123 -- This table contains a user's bot passwords: passwords that allow access to
124 -- the account via the API with limited rights.
125 --
126 CREATE TABLE /*_*/bot_passwords (
127 bp_user int NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
128 bp_app_id nvarchar(32) NOT NULL,
129 bp_password nvarchar(255) NOT NULL,
130 bp_token nvarchar(255) NOT NULL,
131 bp_restrictions nvarchar(max) NOT NULL,
132 bp_grants nvarchar(max) NOT NULL,
133 PRIMARY KEY (bp_user, bp_app_id)
134 );
135
136
137 --
138 -- Edits, blocks, and other actions typically have a textual comment describing
139 -- the action. They are stored here to reduce the size of the main tables, and
140 -- to allow for deduplication.
141 --
142 -- Deduplication is currently best-effort to avoid locking on inserts that
143 -- would be required for strict deduplication. There MAY be multiple rows with
144 -- the same comment_text and comment_data.
145 --
146 CREATE TABLE /*_*/comment (
147 comment_id bigint unsigned NOT NULL PRIMARY KEY IDENTITY(0,1),
148 comment_hash INT NOT NULL,
149 comment_text nvarchar(max) NOT NULL,
150 comment_data nvarchar(max)
151 );
152 -- Index used for deduplication.
153 CREATE INDEX /*i*/comment_hash ON /*_*/comment (comment_hash);
154
155 -- dummy row for FKs. Hash is intentionally wrong so CommentStore won't match it.
156 INSERT INTO /*_*/comment (comment_hash, comment_text) VALUES (-1, '** dummy **');
157
158
159 --
160 -- Core of the wiki: each page has an entry here which identifies
161 -- it by title and contains some essential metadata.
162 --
163 CREATE TABLE /*_*/page (
164 page_id INT NOT NULL PRIMARY KEY IDENTITY(0,1),
165 page_namespace INT NOT NULL,
166 page_title NVARCHAR(255) NOT NULL,
167 page_restrictions NVARCHAR(255) NOT NULL,
168 page_is_redirect BIT NOT NULL DEFAULT 0,
169 page_is_new BIT NOT NULL DEFAULT 0,
170 page_random real NOT NULL DEFAULT RAND(),
171 page_touched varchar(14) NOT NULL default '',
172 page_links_updated varchar(14) DEFAULT NULL,
173 page_latest INT, -- FK inserted later
174 page_len INT NOT NULL,
175 page_content_model nvarchar(32) default null,
176 page_lang VARBINARY(35) DEFAULT NULL
177 );
178 CREATE UNIQUE INDEX /*i*/name_title ON /*_*/page (page_namespace,page_title);
179 CREATE INDEX /*i*/page_random ON /*_*/page (page_random);
180 CREATE INDEX /*i*/page_len ON /*_*/page (page_len);
181 CREATE INDEX /*i*/page_redirect_namespace_len ON /*_*/page (page_is_redirect, page_namespace, page_len);
182
183 -- insert a dummy page
184 INSERT INTO /*_*/page (page_namespace, page_title, page_restrictions, page_latest, page_len) VALUES (-1,'','',0,0);
185
186 --
187 -- Every edit of a page creates also a revision row.
188 -- This stores metadata about the revision, and a reference
189 -- to the TEXT storage backend.
190 --
191 CREATE TABLE /*_*/revision (
192 rev_id INT NOT NULL UNIQUE IDENTITY(0,1),
193 rev_page INT NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
194 rev_text_id INT NOT NULL, -- FK added later
195 rev_comment NVARCHAR(255) NOT NULL CONSTRAINT DF_rev_comment DEFAULT '',
196 rev_user INT REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
197 rev_user_text NVARCHAR(255) NOT NULL DEFAULT '',
198 rev_timestamp varchar(14) NOT NULL default '',
199 rev_minor_edit BIT NOT NULL DEFAULT 0,
200 rev_deleted TINYINT NOT NULL DEFAULT 0,
201 rev_len INT,
202 rev_parent_id INT DEFAULT NULL REFERENCES /*_*/revision(rev_id),
203 rev_sha1 nvarchar(32) not null default '',
204 rev_content_model nvarchar(32) default null,
205 rev_content_format nvarchar(64) default null
206 );
207 CREATE UNIQUE CLUSTERED INDEX /*i*/rev_page_id ON /*_*/revision (rev_page, rev_id);
208 CREATE INDEX /*i*/rev_timestamp ON /*_*/revision (rev_timestamp);
209 CREATE INDEX /*i*/page_timestamp ON /*_*/revision (rev_page,rev_timestamp);
210 CREATE INDEX /*i*/user_timestamp ON /*_*/revision (rev_user,rev_timestamp);
211 CREATE INDEX /*i*/usertext_timestamp ON /*_*/revision (rev_user_text,rev_timestamp);
212 CREATE INDEX /*i*/page_user_timestamp ON /*_*/revision (rev_page,rev_user,rev_timestamp);
213
214 -- insert a dummy revision
215 INSERT INTO /*_*/revision (rev_page,rev_text_id,rev_comment,rev_user,rev_len) VALUES (0,0,'',0,0);
216
217 ALTER TABLE /*_*/page ADD CONSTRAINT FK_page_latest_page_id FOREIGN KEY (page_latest) REFERENCES /*_*/revision(rev_id);
218
219 --
220 -- Temporary tables to avoid blocking on an alter of revision.
221 --
222 -- On large wikis like the English Wikipedia, altering the revision table is a
223 -- months-long process. This table is being created to avoid such an alter, and
224 -- will be merged back into revision in the future.
225 --
226 CREATE TABLE /*_*/revision_comment_temp (
227 revcomment_rev INT NOT NULL CONSTRAINT FK_revcomment_rev FOREIGN KEY REFERENCES /*_*/revision(rev_id) ON DELETE CASCADE,
228 revcomment_comment_id bigint unsigned NOT NULL CONSTRAINT FK_revcomment_comment_id FOREIGN KEY REFERENCES /*_*/comment(comment_id),
229 CONSTRAINT PK_revision_comment_temp PRIMARY KEY (revcomment_rev, revcomment_comment_id)
230 );
231 CREATE UNIQUE INDEX /*i*/revcomment_rev ON /*_*/revision_comment_temp (revcomment_rev);
232
233 CREATE TABLE /*_*/revision_actor_temp (
234 revactor_rev int unsigned NOT NULL CONSTRAINT FK_revactor_rev FOREIGN KEY REFERENCES /*_*/revision(rev_id) ON DELETE CASCADE,
235 revactor_actor bigint unsigned NOT NULL,
236 revactor_timestamp varchar(14) NOT NULL CONSTRAINT DF_revactor_timestamp DEFAULT '',
237 revactor_page int unsigned NOT NULL,
238 CONSTRAINT PK_revision_actor_temp PRIMARY KEY (revactor_rev, revactor_actor)
239 );
240 CREATE UNIQUE INDEX /*i*/revactor_rev ON /*_*/revision_actor_temp (revactor_rev);
241 CREATE INDEX /*i*/actor_timestamp ON /*_*/revision_actor_temp (revactor_actor,revactor_timestamp);
242 CREATE INDEX /*i*/page_actor_timestamp ON /*_*/revision_actor_temp (revactor_page,revactor_actor,revactor_timestamp);
243
244 --
245 -- Holds TEXT of individual page revisions.
246 --
247 -- Field names are a holdover from the 'old' revisions table in
248 -- MediaWiki 1.4 and earlier: an upgrade will transform that
249 -- table INTo the 'text' table to minimize unnecessary churning
250 -- and downtime. If upgrading, the other fields will be left unused.
251 CREATE TABLE /*_*/text (
252 old_id INT NOT NULL PRIMARY KEY IDENTITY(0,1),
253 old_text nvarchar(max) NOT NULL,
254 old_flags NVARCHAR(255) NOT NULL,
255 );
256
257 -- insert a dummy text
258 INSERT INTO /*_*/text (old_text,old_flags) VALUES ('','');
259
260 ALTER TABLE /*_*/revision ADD CONSTRAINT FK_rev_text_id_old_id FOREIGN KEY (rev_text_id) REFERENCES /*_*/text(old_id) ON DELETE CASCADE;
261
262 --
263 -- Holding area for deleted articles, which may be viewed
264 -- or restored by admins through the Special:Undelete interface.
265 -- The fields generally correspond to the page, revision, and text
266 -- fields, with several caveats.
267 -- Cannot reasonably create views on this table, due to the presence of TEXT
268 -- columns.
269 CREATE TABLE /*_*/archive (
270 ar_id int NOT NULL PRIMARY KEY IDENTITY,
271 ar_namespace SMALLINT NOT NULL DEFAULT 0,
272 ar_title NVARCHAR(255) NOT NULL DEFAULT '',
273 ar_text NVARCHAR(MAX) NOT NULL,
274 ar_comment NVARCHAR(255) NOT NULL CONSTRAINT DF_ar_comment DEFAULT '',
275 ar_comment_id bigint unsigned NOT NULL CONSTRAINT DF_ar_comment_id DEFAULT 0 CONSTRAINT FK_ar_comment_id FOREIGN KEY REFERENCES /*_*/comment(comment_id),
276 ar_user INT CONSTRAINT ar_user__user_id__fk FOREIGN KEY REFERENCES /*_*/mwuser(user_id),
277 ar_user_text NVARCHAR(255) NOT NULL CONSTRAINT DF_ar_user_text DEFAULT '',
278 ar_actor bigint unsigned NOT NULL CONSTRAINT DF_ar_actor DEFAULT 0,
279 ar_timestamp varchar(14) NOT NULL default '',
280 ar_minor_edit BIT NOT NULL DEFAULT 0,
281 ar_flags NVARCHAR(255) NOT NULL,
282 ar_rev_id INT NULL, -- NOT a FK, the row gets deleted from revision and moved here
283 ar_text_id INT CONSTRAINT ar_text_id__old_id__fk FOREIGN KEY REFERENCES /*_*/text(old_id) ON DELETE CASCADE,
284 ar_deleted TINYINT NOT NULL DEFAULT 0,
285 ar_len INT,
286 ar_page_id INT NULL, -- NOT a FK, the row gets deleted from page and moved here
287 ar_parent_id INT NULL, -- NOT FK
288 ar_sha1 nvarchar(32) default null,
289 ar_content_model nvarchar(32) DEFAULT NULL,
290 ar_content_format nvarchar(64) DEFAULT NULL
291 );
292 CREATE INDEX /*i*/name_title_timestamp ON /*_*/archive (ar_namespace,ar_title,ar_timestamp);
293 CREATE INDEX /*i*/ar_usertext_timestamp ON /*_*/archive (ar_user_text,ar_timestamp);
294 CREATE INDEX /*i*/ar_actor_timestamp ON /*_*/archive (ar_actor,ar_timestamp);
295 CREATE INDEX /*i*/ar_revid ON /*_*/archive (ar_rev_id);
296
297
298 --
299 -- Slots represent an n:m relation between revisions and content objects.
300 -- A content object can have a specific "role" in one or more revisions.
301 -- Each revision can have multiple content objects, each having a different role.
302 --
303 CREATE TABLE /*_*/slots (
304
305 -- reference to rev_id
306 slot_revision_id bigint unsigned NOT NULL,
307
308 -- reference to role_id
309 slot_role_id smallint unsigned NOT NULL CONSTRAINT FK_slots_slot_role FOREIGN KEY REFERENCES slot_roles(role_id),
310
311 -- reference to content_id
312 slot_content_id bigint unsigned NOT NULL CONSTRAINT FK_slots_content_id FOREIGN KEY REFERENCES content(content_id),
313
314 -- whether the content is inherited (1) or new in this revision (0)
315 slot_inherited tinyint unsigned NOT NULL CONSTRAINT DF_slot_inherited DEFAULT 0,
316
317 CONSTRAINT PK_slots PRIMARY KEY (slot_revision_id, slot_role_id)
318 );
319
320 -- Index for finding revisions that modified a specific slot
321 CREATE INDEX /*i*/slot_role_inherited ON /*_*/slots (slot_revision_id, slot_role_id, slot_inherited);
322
323 --
324 -- The content table represents content objects. It's primary purpose is to provide the necessary
325 -- meta-data for loading and interpreting a serialized data blob to create a content object.
326 --
327 CREATE TABLE /*_*/content (
328
329 -- ID of the content object
330 content_id bigint unsigned NOT NULL CONSTRAINT PK_content PRIMARY KEY IDENTITY,
331
332 -- Nominal size of the content object (not necessarily of the serialized blob)
333 content_size int unsigned NOT NULL,
334
335 -- Nominal hash of the content object (not necessarily of the serialized blob)
336 content_sha1 varchar(32) NOT NULL,
337
338 -- reference to model_id
339 content_model smallint unsigned NOT NULL CONSTRAINT FK_content_content_models FOREIGN KEY REFERENCES /*_*/content_models(model_id),
340
341 -- URL-like address of the content blob
342 content_address nvarchar(255) NOT NULL
343 );
344
345 --
346 -- Normalization table for role names
347 --
348 CREATE TABLE /*_*/slot_roles (
349 role_id smallint NOT NULL CONSTRAINT PK_slot_roles PRIMARY KEY IDENTITY,
350 role_name nvarchar(64) NOT NULL
351 );
352
353 -- Index for looking of the internal ID of for a name
354 CREATE UNIQUE INDEX /*i*/role_name ON /*_*/slot_roles (role_name);
355
356 --
357 -- Normalization table for content model names
358 --
359 CREATE TABLE /*_*/content_models (
360 model_id smallint NOT NULL CONSTRAINT PK_content_models PRIMARY KEY IDENTITY,
361 model_name nvarchar(64) NOT NULL
362 );
363
364 -- Index for looking of the internal ID of for a name
365 CREATE UNIQUE INDEX /*i*/model_name ON /*_*/content_models (model_name);
366
367
368 --
369 -- Track page-to-page hyperlinks within the wiki.
370 --
371 CREATE TABLE /*_*/pagelinks (
372 pl_from INT NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
373 pl_from_namespace int NOT NULL DEFAULT 0,
374 pl_namespace INT NOT NULL DEFAULT 0,
375 pl_title NVARCHAR(255) NOT NULL DEFAULT '',
376 );
377 CREATE UNIQUE INDEX /*i*/pl_from ON /*_*/pagelinks (pl_from,pl_namespace,pl_title);
378 CREATE UNIQUE INDEX /*i*/pl_namespace ON /*_*/pagelinks (pl_namespace,pl_title,pl_from);
379 CREATE INDEX /*i*/pl_backlinks_namespace ON /*_*/pagelinks (pl_from_namespace,pl_namespace,pl_title,pl_from);
380
381
382 --
383 -- Track template inclusions.
384 --
385 CREATE TABLE /*_*/templatelinks (
386 tl_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
387 tl_from_namespace int NOT NULL default 0,
388 tl_namespace int NOT NULL default 0,
389 tl_title nvarchar(255) NOT NULL default ''
390 );
391
392 CREATE UNIQUE INDEX /*i*/tl_from ON /*_*/templatelinks (tl_from,tl_namespace,tl_title);
393 CREATE UNIQUE INDEX /*i*/tl_namespace ON /*_*/templatelinks (tl_namespace,tl_title,tl_from);
394 CREATE INDEX /*i*/tl_backlinks_namespace ON /*_*/templatelinks (tl_from_namespace,tl_namespace,tl_title,tl_from);
395
396
397 --
398 -- Track links to images *used inline*
399 -- We don't distinguish live from broken links here, so
400 -- they do not need to be changed on upload/removal.
401 --
402 CREATE TABLE /*_*/imagelinks (
403 -- Key to page_id of the page containing the image / media link.
404 il_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
405 il_from_namespace int NOT NULL default 0,
406
407 -- Filename of target image.
408 -- This is also the page_title of the file's description page;
409 -- all such pages are in namespace 6 (NS_FILE).
410 il_to nvarchar(255) NOT NULL default ''
411 );
412
413 CREATE UNIQUE INDEX /*i*/il_from ON /*_*/imagelinks (il_from,il_to);
414 CREATE UNIQUE INDEX /*i*/il_to ON /*_*/imagelinks (il_to,il_from);
415 CREATE INDEX /*i*/il_backlinks_namespace ON /*_*/imagelinks (il_from_namespace,il_to,il_from);
416
417 --
418 -- Track category inclusions *used inline*
419 -- This tracks a single level of category membership
420 --
421 CREATE TABLE /*_*/categorylinks (
422 -- Key to page_id of the page defined as a category member.
423 cl_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
424
425 -- Name of the category.
426 -- This is also the page_title of the category's description page;
427 -- all such pages are in namespace 14 (NS_CATEGORY).
428 cl_to nvarchar(255) NOT NULL default '',
429
430 -- A binary string obtained by applying a sortkey generation algorithm
431 -- (Collation::getSortKey()) to page_title, or cl_sortkey_prefix . "\n"
432 -- . page_title if cl_sortkey_prefix is nonempty.
433 cl_sortkey varbinary(230) NOT NULL default 0x,
434
435 -- A prefix for the raw sortkey manually specified by the user, either via
436 -- [[Category:Foo|prefix]] or {{defaultsort:prefix}}. If nonempty, it's
437 -- concatenated with a line break followed by the page title before the sortkey
438 -- conversion algorithm is run. We store this so that we can update
439 -- collations without reparsing all pages.
440 -- Note: If you change the length of this field, you also need to change
441 -- code in LinksUpdate.php. See T27254.
442 cl_sortkey_prefix varbinary(255) NOT NULL default 0x,
443
444 -- This isn't really used at present. Provided for an optional
445 -- sorting method by approximate addition time.
446 cl_timestamp varchar(14) NOT NULL,
447
448 -- Stores $wgCategoryCollation at the time cl_sortkey was generated. This
449 -- can be used to install new collation versions, tracking which rows are not
450 -- yet updated. '' means no collation, this is a legacy row that needs to be
451 -- updated by updateCollation.php. In the future, it might be possible to
452 -- specify different collations per category.
453 cl_collation nvarchar(32) NOT NULL default '',
454
455 -- Stores whether cl_from is a category, file, or other page, so we can
456 -- paginate the three categories separately. This never has to be updated
457 -- after the page is created, since none of these page types can be moved to
458 -- any other.
459 cl_type varchar(10) NOT NULL default 'page',
460 -- SQL server doesn't have enums, so we approximate with this
461 CONSTRAINT cl_type_ckc CHECK (cl_type IN('page', 'subcat', 'file'))
462 );
463
464 CREATE UNIQUE INDEX /*i*/cl_from ON /*_*/categorylinks (cl_from,cl_to);
465
466 -- We always sort within a given category, and within a given type. FIXME:
467 -- Formerly this index didn't cover cl_type (since that didn't exist), so old
468 -- callers won't be using an index: fix this?
469 CREATE INDEX /*i*/cl_sortkey ON /*_*/categorylinks (cl_to,cl_type,cl_sortkey,cl_from);
470
471 -- Used by the API (and some extensions)
472 CREATE INDEX /*i*/cl_timestamp ON /*_*/categorylinks (cl_to,cl_timestamp);
473
474 -- Used when updating collation (e.g. updateCollation.php)
475 CREATE INDEX /*i*/cl_collation_ext ON /*_*/categorylinks (cl_collation, cl_to, cl_type, cl_from);
476
477 --
478 -- Track all existing categories. Something is a category if 1) it has an entry
479 -- somewhere in categorylinks, or 2) it has a description page. Categories
480 -- might not have corresponding pages, so they need to be tracked separately.
481 --
482 CREATE TABLE /*_*/category (
483 -- Primary key
484 cat_id int NOT NULL PRIMARY KEY IDENTITY,
485
486 -- Name of the category, in the same form as page_title (with underscores).
487 -- If there is a category page corresponding to this category, by definition,
488 -- it has this name (in the Category namespace).
489 cat_title nvarchar(255) NOT NULL,
490
491 -- The numbers of member pages (including categories and media), subcatego-
492 -- ries, and Image: namespace members, respectively. These are signed to
493 -- make underflow more obvious. We make the first number include the second
494 -- two for better sorting: subtracting for display is easy, adding for order-
495 -- ing is not.
496 cat_pages int NOT NULL default 0,
497 cat_subcats int NOT NULL default 0,
498 cat_files int NOT NULL default 0
499 );
500
501 CREATE UNIQUE INDEX /*i*/cat_title ON /*_*/category (cat_title);
502
503 -- For Special:Mostlinkedcategories
504 CREATE INDEX /*i*/cat_pages ON /*_*/category (cat_pages);
505
506
507 --
508 -- Track links to external URLs
509 --
510 CREATE TABLE /*_*/externallinks (
511 -- Primary key
512 el_id int NOT NULL PRIMARY KEY IDENTITY,
513
514 -- page_id of the referring page
515 el_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
516
517 -- The URL
518 el_to nvarchar(max) NOT NULL,
519
520 -- In the case of HTTP URLs, this is the URL with any username or password
521 -- removed, and with the labels in the hostname reversed and converted to
522 -- lower case. An extra dot is added to allow for matching of either
523 -- example.com or *.example.com in a single scan.
524 -- Example:
525 -- http://user:password@sub.example.com/page.html
526 -- becomes
527 -- http://com.example.sub./page.html
528 -- which allows for fast searching for all pages under example.com with the
529 -- clause:
530 -- WHERE el_index LIKE 'http://com.example.%'
531 el_index nvarchar(450) NOT NULL,
532
533 -- This is el_index truncated to 60 bytes to allow for sortable queries that
534 -- aren't supported by a partial index.
535 -- @todo Drop the default once this is deployed everywhere and code is populating it.
536 el_index_60 varbinary(60) NOT NULL default ''
537 );
538
539 CREATE INDEX /*i*/el_from ON /*_*/externallinks (el_from);
540 CREATE INDEX /*i*/el_index ON /*_*/externallinks (el_index);
541 CREATE INDEX /*i*/el_index_60 ON /*_*/externallinks (el_index_60, el_id);
542 CREATE INDEX /*i*/el_from_index_60 ON /*_*/externallinks (el_from, el_index_60, el_id);
543 -- el_to index intentionally not added; we cannot index nvarchar(max) columns,
544 -- but we also cannot restrict el_to to a smaller column size as the external
545 -- link may be larger.
546
547 --
548 -- Track interlanguage links
549 --
550 CREATE TABLE /*_*/langlinks (
551 -- page_id of the referring page
552 ll_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
553
554 -- Language code of the target
555 ll_lang nvarchar(20) NOT NULL default '',
556
557 -- Title of the target, including namespace
558 ll_title nvarchar(255) NOT NULL default ''
559 );
560
561 CREATE UNIQUE INDEX /*i*/ll_from ON /*_*/langlinks (ll_from, ll_lang);
562 CREATE INDEX /*i*/ll_lang ON /*_*/langlinks (ll_lang, ll_title);
563
564
565 --
566 -- Track inline interwiki links
567 --
568 CREATE TABLE /*_*/iwlinks (
569 -- page_id of the referring page
570 iwl_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
571
572 -- Interwiki prefix code of the target
573 iwl_prefix nvarchar(20) NOT NULL default '',
574
575 -- Title of the target, including namespace
576 iwl_title nvarchar(255) NOT NULL default ''
577 );
578
579 CREATE UNIQUE INDEX /*i*/iwl_from ON /*_*/iwlinks (iwl_from, iwl_prefix, iwl_title);
580 CREATE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
581 CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);
582
583
584 --
585 -- Contains a single row with some aggregate info
586 -- on the state of the site.
587 --
588 CREATE TABLE /*_*/site_stats (
589 -- The single row should contain 1 here.
590 ss_row_id int NOT NULL CONSTRAINT /*i*/ss_row_id PRIMARY KEY,
591
592 -- Total number of edits performed.
593 ss_total_edits bigint default 0,
594
595 -- An approximate count of pages matching the following criteria:
596 -- * in namespace 0
597 -- * not a redirect
598 -- * contains the text '[['
599 -- See Article::isCountable() in includes/Article.php
600 ss_good_articles bigint default 0,
601
602 -- Total pages, theoretically equal to SELECT COUNT(*) FROM page; except faster
603 ss_total_pages bigint default '-1',
604
605 -- Number of users, theoretically equal to SELECT COUNT(*) FROM user;
606 ss_users bigint default '-1',
607
608 -- Number of users that still edit
609 ss_active_users bigint default '-1',
610
611 -- Number of images, equivalent to SELECT COUNT(*) FROM image
612 ss_images int default 0
613 );
614
615
616 --
617 -- The internet is full of jerks, alas. Sometimes it's handy
618 -- to block a vandal or troll account.
619 --
620 CREATE TABLE /*_*/ipblocks (
621 -- Primary key, introduced for privacy.
622 ipb_id int NOT NULL PRIMARY KEY IDENTITY,
623
624 -- Blocked IP address in dotted-quad form or user name.
625 ipb_address nvarchar(255) NOT NULL,
626
627 -- Blocked user ID or 0 for IP blocks.
628 ipb_user int REFERENCES /*_*/mwuser(user_id),
629
630 -- User ID who made the block.
631 ipb_by int REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
632
633 -- Actor ID who made the block.
634 ipb_by_actor bigint unsigned NOT NULL CONSTRAINT DF_ipb_by_actor DEFAULT 0,
635
636 -- User name of blocker
637 ipb_by_text nvarchar(255) NOT NULL default '',
638
639 -- Text comment made by blocker.
640 ipb_reason nvarchar(255) NOT NULL CONSTRAINT DF_ipb_reason DEFAULT '',
641
642 -- Key to comment_id. Text comment made by blocker.
643 -- ("DEFAULT 0" is temporary, signaling that ipb_reason should be used)
644 ipb_reason_id bigint unsigned NOT NULL CONSTRAINT DF_ipb_reason_id DEFAULT 0 CONSTRAINT FK_ipb_reason_id FOREIGN KEY REFERENCES /*_*/comment(comment_id),
645
646 -- Creation (or refresh) date in standard YMDHMS form.
647 -- IP blocks expire automatically.
648 ipb_timestamp varchar(14) NOT NULL default '',
649
650 -- Indicates that the IP address was banned because a banned
651 -- user accessed a page through it. If this is 1, ipb_address
652 -- will be hidden, and the block identified by block ID number.
653 ipb_auto bit NOT NULL default 0,
654
655 -- If set to 1, block applies only to logged-out users
656 ipb_anon_only bit NOT NULL default 0,
657
658 -- Block prevents account creation from matching IP addresses
659 ipb_create_account bit NOT NULL default 1,
660
661 -- Block triggers autoblocks
662 ipb_enable_autoblock bit NOT NULL default 1,
663
664 -- Time at which the block will expire.
665 -- May be "infinity"
666 ipb_expiry varchar(14) NOT NULL,
667
668 -- Start and end of an address range, in hexadecimal
669 -- Size chosen to allow IPv6
670 -- FIXME: these fields were originally blank for single-IP blocks,
671 -- but now they are populated. No migration was ever done. They
672 -- should be fixed to be blank again for such blocks (T51504).
673 ipb_range_start varchar(255) NOT NULL,
674 ipb_range_end varchar(255) NOT NULL,
675
676 -- Flag for entries hidden from users and Sysops
677 ipb_deleted bit NOT NULL default 0,
678
679 -- Block prevents user from accessing Special:Emailuser
680 ipb_block_email bit NOT NULL default 0,
681
682 -- Block allows user to edit their own talk page
683 ipb_allow_usertalk bit NOT NULL default 0,
684
685 -- ID of the block that caused this block to exist
686 -- Autoblocks set this to the original block
687 -- so that the original block being deleted also
688 -- deletes the autoblocks
689 ipb_parent_block_id int default NULL REFERENCES /*_*/ipblocks(ipb_id)
690
691 );
692
693 -- Unique index to support "user already blocked" messages
694 -- Any new options which prevent collisions should be included
695 CREATE UNIQUE INDEX /*i*/ipb_address ON /*_*/ipblocks (ipb_address, ipb_user, ipb_auto, ipb_anon_only);
696
697 CREATE INDEX /*i*/ipb_user ON /*_*/ipblocks (ipb_user);
698 CREATE INDEX /*i*/ipb_range ON /*_*/ipblocks (ipb_range_start, ipb_range_end);
699 CREATE INDEX /*i*/ipb_timestamp ON /*_*/ipblocks (ipb_timestamp);
700 CREATE INDEX /*i*/ipb_expiry ON /*_*/ipblocks (ipb_expiry);
701 CREATE INDEX /*i*/ipb_parent_block_id ON /*_*/ipblocks (ipb_parent_block_id);
702
703
704 --
705 -- Uploaded images and other files.
706 --
707 CREATE TABLE /*_*/image (
708 -- Filename.
709 -- This is also the title of the associated description page,
710 -- which will be in namespace 6 (NS_FILE).
711 img_name nvarchar(255) NOT NULL default '' PRIMARY KEY,
712
713 -- File size in bytes.
714 img_size int NOT NULL default 0,
715
716 -- For images, size in pixels.
717 img_width int NOT NULL default 0,
718 img_height int NOT NULL default 0,
719
720 -- Extracted Exif metadata stored as a serialized PHP array.
721 img_metadata varbinary(max) NOT NULL,
722
723 -- For images, bits per pixel if known.
724 img_bits int NOT NULL default 0,
725
726 -- Media type as defined by the MEDIATYPE_xxx constants
727 img_media_type varchar(16) default null,
728
729 -- major part of a MIME media type as defined by IANA
730 -- see https://www.iana.org/assignments/media-types/
731 img_major_mime varchar(16) not null default 'unknown',
732
733 -- minor part of a MIME media type as defined by IANA
734 -- the minor parts are not required to adher to any standard
735 -- but should be consistent throughout the database
736 -- see https://www.iana.org/assignments/media-types/
737 img_minor_mime nvarchar(100) NOT NULL default 'unknown',
738
739 -- Description field as entered by the uploader.
740 -- This is displayed in image upload history and logs.
741 img_description nvarchar(255) NOT NULL CONSTRAINT DF_img_description DEFAULT '',
742
743 -- user_id and user_name of uploader.
744 img_user int REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
745 img_user_text nvarchar(255) NOT NULL CONSTRAINT DF_img_user_text DEFAULT '',
746 img_actor bigint unsigned NOT NULL CONSTRAINT DF_img_actor DEFAULT 0,
747
748 -- Time of the upload.
749 img_timestamp nvarchar(14) NOT NULL default '',
750
751 -- SHA-1 content hash in base-36
752 img_sha1 nvarchar(32) NOT NULL default '',
753
754 CONSTRAINT img_major_mime_ckc check (img_major_mime IN('unknown', 'application', 'audio', 'image', 'text', 'video', 'message', 'model', 'multipart', 'chemical')),
755 CONSTRAINT img_media_type_ckc check (img_media_type in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA', 'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE','3D'))
756 );
757
758 CREATE INDEX /*i*/img_usertext_timestamp ON /*_*/image (img_user_text,img_timestamp);
759 CREATE INDEX /*i*/img_actor_timestamp ON /*_*/image (img_actor, img_timestamp);
760 -- Used by Special:ListFiles for sort-by-size
761 CREATE INDEX /*i*/img_size ON /*_*/image (img_size);
762 -- Used by Special:Newimages and Special:ListFiles
763 CREATE INDEX /*i*/img_timestamp ON /*_*/image (img_timestamp);
764 -- Used in API and duplicate search
765 CREATE INDEX /*i*/img_sha1 ON /*_*/image (img_sha1);
766 -- Used to get media of one type
767 CREATE INDEX /*i*/img_media_mime ON /*_*/image (img_media_type,img_major_mime,img_minor_mime);
768
769 --
770 -- Temporary table to avoid blocking on an alter of image.
771 --
772 -- On large wikis like Wikimedia Commons, altering the image table is a
773 -- months-long process. This table is being created to avoid such an alter, and
774 -- will be merged back into image in the future.
775 --
776 CREATE TABLE /*_*/image_comment_temp (
777 imgcomment_name nvarchar(255) NOT NULL CONSTRAINT FK_imgcomment_name FOREIGN KEY REFERENCES /*_*/image(imgcomment_name) ON DELETE CASCADE,
778 imgcomment_description_id bigint unsigned NOT NULL CONSTRAINT FK_imgcomment_description_id FOREIGN KEY REFERENCES /*_*/comment(comment_id),
779 CONSTRAINT PK_image_comment_temp PRIMARY KEY (imgcomment_name, imgcomment_description_id)
780 );
781 CREATE UNIQUE INDEX /*i*/imgcomment_name ON /*_*/image_comment_temp (imgcomment_name);
782
783
784 --
785 -- Previous revisions of uploaded files.
786 -- Awkwardly, image rows have to be moved into
787 -- this table at re-upload time.
788 --
789 CREATE TABLE /*_*/oldimage (
790 -- Base filename: key to image.img_name
791 -- Not a FK because deleting images removes them from image
792 oi_name nvarchar(255) NOT NULL default '',
793
794 -- Filename of the archived file.
795 -- This is generally a timestamp and '!' prepended to the base name.
796 oi_archive_name nvarchar(255) NOT NULL default '',
797
798 -- Other fields as in image...
799 oi_size int NOT NULL default 0,
800 oi_width int NOT NULL default 0,
801 oi_height int NOT NULL default 0,
802 oi_bits int NOT NULL default 0,
803 oi_description nvarchar(255) NOT NULL CONSTRAINT DF_oi_description DEFAULT '',
804 oi_description_id bigint unsigned NOT NULL CONSTRAINT DF_oi_description_id DEFAULT 0 CONSTRAINT FK_oi_description_id FOREIGN KEY REFERENCES /*_*/comment(comment_id),
805 oi_user int REFERENCES /*_*/mwuser(user_id),
806 oi_user_text nvarchar(255) NOT NULL CONSTRAINT DF_oi_user_text DEFAULT '',
807 oi_actor bigint unsigned NOT NULL CONSTRAINT DF_oi_actor DEFAULT 0,
808 oi_timestamp varchar(14) NOT NULL default '',
809
810 oi_metadata varbinary(max) NOT NULL,
811 oi_media_type varchar(16) default null,
812 oi_major_mime varchar(16) not null default 'unknown',
813 oi_minor_mime nvarchar(100) NOT NULL default 'unknown',
814 oi_deleted tinyint NOT NULL default 0,
815 oi_sha1 nvarchar(32) NOT NULL default '',
816
817 CONSTRAINT oi_major_mime_ckc check (oi_major_mime IN('unknown', 'application', 'audio', 'image', 'text', 'video', 'message', 'model', 'multipart', 'chemical')),
818 CONSTRAINT oi_media_type_ckc check (oi_media_type IN('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA', 'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE','3D'))
819 );
820
821 CREATE INDEX /*i*/oi_usertext_timestamp ON /*_*/oldimage (oi_user_text,oi_timestamp);
822 CREATE INDEX /*i*/oi_actor_timestamp ON /*_*/oldimage (oi_actor,oi_timestamp);
823 CREATE INDEX /*i*/oi_name_timestamp ON /*_*/oldimage (oi_name,oi_timestamp);
824 CREATE INDEX /*i*/oi_sha1 ON /*_*/oldimage (oi_sha1);
825
826
827 --
828 -- Record of deleted file data
829 --
830 CREATE TABLE /*_*/filearchive (
831 -- Unique row id
832 fa_id int NOT NULL PRIMARY KEY IDENTITY,
833
834 -- Original base filename; key to image.img_name, page.page_title, etc
835 fa_name nvarchar(255) NOT NULL default '',
836
837 -- Filename of archived file, if an old revision
838 fa_archive_name nvarchar(255) default '',
839
840 -- Which storage bin (directory tree or object store) the file data
841 -- is stored in. Should be 'deleted' for files that have been deleted;
842 -- any other bin is not yet in use.
843 fa_storage_group nvarchar(16),
844
845 -- SHA-1 of the file contents plus extension, used as a key for storage.
846 -- eg 8f8a562add37052a1848ff7771a2c515db94baa9.jpg
847 --
848 -- If NULL, the file was missing at deletion time or has been purged
849 -- from the archival storage.
850 fa_storage_key nvarchar(64) default '',
851
852 -- Deletion information, if this file is deleted.
853 fa_deleted_user int,
854 fa_deleted_timestamp varchar(14) default '',
855 fa_deleted_reason nvarchar(max) CONSTRAINT DF_fa_deleted_reason DEFAULT '',
856 fa_deleted_reason_id bigint unsigned NOT NULL CONSTRAINT DF_fa_deleted_reason_id DEFAULT 0 CONSTRAINT FK_fa_deleted_reason_id FOREIGN KEY REFERENCES /*_*/comment(comment_id),
857
858 -- Duped fields from image
859 fa_size int default 0,
860 fa_width int default 0,
861 fa_height int default 0,
862 fa_metadata varbinary(max),
863 fa_bits int default 0,
864 fa_media_type varchar(16) default null,
865 fa_major_mime varchar(16) not null default 'unknown',
866 fa_minor_mime nvarchar(100) default 'unknown',
867 fa_description nvarchar(255) CONSTRAINT DF_fa_description DEFAULT '',
868 fa_description_id bigint unsigned NOT NULL CONSTRAINT DF_fa_description DEFAULT 0 CONSTRAINT FK_fa_description FOREIGN KEY REFERENCES /*_*/comment(comment_id),
869 fa_user int default 0 REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
870 fa_user_text nvarchar(255) CONSTRAINT DF_fa_user_text DEFAULT '',
871 fa_actor bigint unsigned NOT NULL CONSTRAINT DF_fa_actor DEFAULT 0,
872 fa_timestamp varchar(14) default '',
873
874 -- Visibility of deleted revisions, bitfield
875 fa_deleted tinyint NOT NULL default 0,
876
877 -- sha1 hash of file content
878 fa_sha1 nvarchar(32) NOT NULL default '',
879
880 CONSTRAINT fa_major_mime_ckc check (fa_major_mime in('unknown', 'application', 'audio', 'image', 'text', 'video', 'message', 'model', 'multipart', 'chemical')),
881 CONSTRAINT fa_media_type_ckc check (fa_media_type in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA', 'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE','3D'))
882 );
883
884 -- pick out by image name
885 CREATE INDEX /*i*/fa_name ON /*_*/filearchive (fa_name, fa_timestamp);
886 -- pick out dupe files
887 CREATE INDEX /*i*/fa_storage_group ON /*_*/filearchive (fa_storage_group, fa_storage_key);
888 -- sort by deletion time
889 CREATE INDEX /*i*/fa_deleted_timestamp ON /*_*/filearchive (fa_deleted_timestamp);
890 -- sort by uploader
891 CREATE INDEX /*i*/fa_user_timestamp ON /*_*/filearchive (fa_user_text,fa_timestamp);
892 CREATE INDEX /*i*/fa_actor_timestamp ON /*_*/filearchive (fa_actor,fa_timestamp);
893 -- find file by sha1, 10 bytes will be enough for hashes to be indexed
894 CREATE INDEX /*i*/fa_sha1 ON /*_*/filearchive (fa_sha1);
895
896
897 --
898 -- Store information about newly uploaded files before they're
899 -- moved into the actual filestore
900 --
901 CREATE TABLE /*_*/uploadstash (
902 us_id int NOT NULL PRIMARY KEY IDENTITY,
903
904 -- the user who uploaded the file.
905 us_user int REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
906
907 -- file key. this is how applications actually search for the file.
908 -- this might go away, or become the primary key.
909 us_key nvarchar(255) NOT NULL,
910
911 -- the original path
912 us_orig_path nvarchar(255) NOT NULL,
913
914 -- the temporary path at which the file is actually stored
915 us_path nvarchar(255) NOT NULL,
916
917 -- which type of upload the file came from (sometimes)
918 us_source_type nvarchar(50),
919
920 -- the date/time on which the file was added
921 us_timestamp varchar(14) NOT NULL,
922
923 us_status nvarchar(50) NOT NULL,
924
925 -- chunk counter starts at 0, current offset is stored in us_size
926 us_chunk_inx int NULL,
927
928 -- Serialized file properties from FSFile::getProps()
929 us_props nvarchar(max),
930
931 -- file size in bytes
932 us_size int NOT NULL,
933 -- this hash comes from FSFile::getSha1Base36(), and is 31 characters
934 us_sha1 nvarchar(31) NOT NULL,
935 us_mime nvarchar(255),
936 -- Media type as defined by the MEDIATYPE_xxx constants, should duplicate definition in the image table
937 us_media_type varchar(16) default null,
938 -- image-specific properties
939 us_image_width int,
940 us_image_height int,
941 us_image_bits smallint,
942
943 CONSTRAINT us_media_type_ckc check (us_media_type in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA', 'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE', '3D'))
944 );
945
946 -- sometimes there's a delete for all of a user's stuff.
947 CREATE INDEX /*i*/us_user ON /*_*/uploadstash (us_user);
948 -- pick out files by key, enforce key uniqueness
949 CREATE UNIQUE INDEX /*i*/us_key ON /*_*/uploadstash (us_key);
950 -- the abandoned upload cleanup script needs this
951 CREATE INDEX /*i*/us_timestamp ON /*_*/uploadstash (us_timestamp);
952
953
954 --
955 -- Primarily a summary table for Special:Recentchanges,
956 -- this table contains some additional info on edits from
957 -- the last few days, see Article::editUpdates()
958 --
959 CREATE TABLE /*_*/recentchanges (
960 rc_id int NOT NULL CONSTRAINT recentchanges__pk PRIMARY KEY IDENTITY,
961 rc_timestamp varchar(14) not null default '',
962
963 -- As in revision
964 rc_user int NOT NULL default 0 CONSTRAINT rc_user__user_id__fk FOREIGN KEY REFERENCES /*_*/mwuser(user_id),
965 rc_user_text nvarchar(255) NOT NULL CONSTRAINT DF_rc_user_text DEFAULT '',
966 rc_actor bigint unsigned NOT NULL CONSTRAINT DF_rc_actor DEFAULT 0,
967
968 -- When pages are renamed, their RC entries do _not_ change.
969 rc_namespace int NOT NULL default 0,
970 rc_title nvarchar(255) NOT NULL default '',
971
972 -- as in revision...
973 rc_comment nvarchar(255) NOT NULL default '',
974 rc_comment_id bigint unsigned NOT NULL CONSTRAINT DF_rc_comment_id DEFAULT 0 CONSTRAINT FK_rc_comment_id FOREIGN KEY REFERENCES /*_*/comment(comment_id),
975 rc_minor bit NOT NULL default 0,
976
977 -- Edits by user accounts with the 'bot' rights key are
978 -- marked with a 1 here, and will be hidden from the
979 -- default view.
980 rc_bot bit NOT NULL default 0,
981
982 -- Set if this change corresponds to a page creation
983 rc_new bit NOT NULL default 0,
984
985 -- Key to page_id (was cur_id prior to 1.5).
986 -- This will keep links working after moves while
987 -- retaining the at-the-time name in the changes list.
988 rc_cur_id int, -- NOT FK
989
990 -- rev_id of the given revision
991 rc_this_oldid int, -- NOT FK
992
993 -- rev_id of the prior revision, for generating diff links.
994 rc_last_oldid int, -- NOT FK
995
996 -- The type of change entry (RC_EDIT,RC_NEW,RC_LOG,RC_EXTERNAL)
997 rc_type tinyint NOT NULL default 0,
998
999 -- The source of the change entry (replaces rc_type)
1000 -- default of '' is temporary, needed for initial migration
1001 rc_source nvarchar(16) not null default '',
1002
1003 -- If the Recent Changes Patrol option is enabled,
1004 -- users may mark edits as having been reviewed to
1005 -- remove a warning flag on the RC list.
1006 -- A value of 1 indicates the page has been reviewed.
1007 rc_patrolled bit NOT NULL default 0,
1008
1009 -- Recorded IP address the edit was made from, if the
1010 -- $wgPutIPinRC option is enabled.
1011 rc_ip nvarchar(40) NOT NULL default '',
1012
1013 -- Text length in characters before
1014 -- and after the edit
1015 rc_old_len int,
1016 rc_new_len int,
1017
1018 -- Visibility of recent changes items, bitfield
1019 rc_deleted tinyint NOT NULL default 0,
1020
1021 -- Value corresponding to log_id, specific log entries
1022 rc_logid int, -- FK added later
1023 -- Store log type info here, or null
1024 rc_log_type nvarchar(255) NULL default NULL,
1025 -- Store log action or null
1026 rc_log_action nvarchar(255) NULL default NULL,
1027 -- Log params
1028 rc_params nvarchar(max) NULL
1029 );
1030
1031 CREATE INDEX /*i*/rc_timestamp ON /*_*/recentchanges (rc_timestamp);
1032 CREATE INDEX /*i*/rc_namespace_title ON /*_*/recentchanges (rc_namespace, rc_title);
1033 CREATE INDEX /*i*/rc_cur_id ON /*_*/recentchanges (rc_cur_id);
1034 CREATE INDEX /*i*/new_name_timestamp ON /*_*/recentchanges (rc_new,rc_namespace,rc_timestamp);
1035 CREATE INDEX /*i*/rc_ip ON /*_*/recentchanges (rc_ip);
1036 CREATE INDEX /*i*/rc_ns_usertext ON /*_*/recentchanges (rc_namespace, rc_user_text);
1037 CREATE INDEX /*i*/rc_user_text ON /*_*/recentchanges (rc_user_text, rc_timestamp);
1038 CREATE INDEX /*i*/rc_ns_actor ON /*_*/recentchanges (rc_namespace, rc_actor);
1039 CREATE INDEX /*i*/rc_actor ON /*_*/recentchanges (rc_actor, rc_timestamp);
1040 CREATE INDEX /*i*/rc_name_type_patrolled_timestamp ON /*_*/recentchanges (rc_namespace, rc_type, rc_patrolled, rc_timestamp);
1041
1042
1043 CREATE TABLE /*_*/watchlist (
1044 wl_id int NOT NULL PRIMARY KEY IDENTITY,
1045 -- Key to user.user_id
1046 wl_user int NOT NULL REFERENCES /*_*/mwuser(user_id) ON DELETE CASCADE,
1047
1048 -- Key to page_namespace/page_title
1049 -- Note that users may watch pages which do not exist yet,
1050 -- or existed in the past but have been deleted.
1051 wl_namespace int NOT NULL default 0,
1052 wl_title nvarchar(255) NOT NULL default '',
1053
1054 -- Timestamp used to send notification e-mails and show "updated since last visit" markers on
1055 -- history and recent changes / watchlist. Set to NULL when the user visits the latest revision
1056 -- of the page, which means that they should be sent an e-mail on the next change.
1057 wl_notificationtimestamp varchar(14)
1058
1059 );
1060
1061 CREATE UNIQUE INDEX /*i*/wl_user ON /*_*/watchlist (wl_user, wl_namespace, wl_title);
1062 CREATE INDEX /*i*/namespace_title ON /*_*/watchlist (wl_namespace, wl_title);
1063
1064
1065 --
1066 -- Our search index for the builtin MediaWiki search
1067 --
1068 CREATE TABLE /*_*/searchindex (
1069 -- Key to page_id
1070 si_page int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
1071
1072 -- Munged version of title
1073 si_title nvarchar(255) NOT NULL default '',
1074
1075 -- Munged version of body text
1076 si_text nvarchar(max) NOT NULL
1077 );
1078
1079 CREATE UNIQUE INDEX /*i*/si_page ON /*_*/searchindex (si_page);
1080 -- Fulltext index is defined in MssqlInstaller.php
1081
1082 --
1083 -- Recognized interwiki link prefixes
1084 --
1085 CREATE TABLE /*_*/interwiki (
1086 -- The interwiki prefix, (e.g. "Meatball", or the language prefix "de")
1087 iw_prefix nvarchar(32) NOT NULL,
1088
1089 -- The URL of the wiki, with "$1" as a placeholder for an article name.
1090 -- Any spaces in the name will be transformed to underscores before
1091 -- insertion.
1092 iw_url nvarchar(max) NOT NULL,
1093
1094 -- The URL of the file api.php
1095 iw_api nvarchar(max) NOT NULL,
1096
1097 -- The name of the database (for a connection to be established with wfGetLB( 'wikiid' ))
1098 iw_wikiid nvarchar(64) NOT NULL,
1099
1100 -- A boolean value indicating whether the wiki is in this project
1101 -- (used, for example, to detect redirect loops)
1102 iw_local bit NOT NULL,
1103
1104 -- Boolean value indicating whether interwiki transclusions are allowed.
1105 iw_trans bit NOT NULL default 0
1106 );
1107
1108 CREATE UNIQUE INDEX /*i*/iw_prefix ON /*_*/interwiki (iw_prefix);
1109
1110
1111 --
1112 -- Used for caching expensive grouped queries
1113 --
1114 CREATE TABLE /*_*/querycache (
1115 -- A key name, generally the base name of of the special page.
1116 qc_type nvarchar(32) NOT NULL,
1117
1118 -- Some sort of stored value. Sizes, counts...
1119 qc_value int NOT NULL default 0,
1120
1121 -- Target namespace+title
1122 qc_namespace int NOT NULL default 0,
1123 qc_title nvarchar(255) NOT NULL default ''
1124 );
1125
1126 CREATE INDEX /*i*/qc_type ON /*_*/querycache (qc_type,qc_value);
1127
1128
1129 --
1130 -- For a few generic cache operations if not using Memcached
1131 --
1132 CREATE TABLE /*_*/objectcache (
1133 keyname nvarchar(255) NOT NULL default '' PRIMARY KEY,
1134 value varbinary(max),
1135 exptime varchar(14)
1136 );
1137 CREATE INDEX /*i*/exptime ON /*_*/objectcache (exptime);
1138
1139
1140 --
1141 -- Cache of interwiki transclusion
1142 --
1143 CREATE TABLE /*_*/transcache (
1144 tc_url nvarchar(255) NOT NULL,
1145 tc_contents nvarchar(max),
1146 tc_time varchar(14) NOT NULL
1147 );
1148
1149 CREATE UNIQUE INDEX /*i*/tc_url_idx ON /*_*/transcache (tc_url);
1150
1151
1152 CREATE TABLE /*_*/logging (
1153 -- Log ID, for referring to this specific log entry, probably for deletion and such.
1154 log_id int NOT NULL PRIMARY KEY IDENTITY(0,1),
1155
1156 -- Symbolic keys for the general log type and the action type
1157 -- within the log. The output format will be controlled by the
1158 -- action field, but only the type controls categorization.
1159 log_type nvarchar(32) NOT NULL default '',
1160 log_action nvarchar(32) NOT NULL default '',
1161
1162 -- Timestamp. Duh.
1163 log_timestamp varchar(14) NOT NULL default '',
1164
1165 -- The user who performed this action; key to user_id
1166 log_user int, -- NOT an FK, if a user is deleted we still want to maintain a record of who did a thing
1167
1168 -- Name of the user who performed this action
1169 log_user_text nvarchar(255) NOT NULL default '',
1170
1171 -- The actor who performed this action
1172 log_actor bigint unsigned NOT NULL CONSTRAINT DF_log_actor DEFAULT 0,
1173
1174 -- Key to the page affected. Where a user is the target,
1175 -- this will point to the user page.
1176 log_namespace int NOT NULL default 0,
1177 log_title nvarchar(255) NOT NULL default '',
1178 log_page int NULL, -- NOT an FK, logging entries are inserted for deleted pages which still reference the deleted page ids
1179
1180 -- Freeform text. Interpreted as edit history comments.
1181 log_comment nvarchar(255) NOT NULL default '',
1182
1183 -- Key to comment_id. Comment summarizing the change.
1184 -- ("DEFAULT 0" is temporary, signaling that log_comment should be used)
1185 log_comment_id bigint unsigned NOT NULL CONSTRAINT DF_log_comment_id DEFAULT 0 CONSTRAINT FK_log_comment_id FOREIGN KEY REFERENCES /*_*/comment(comment_id),
1186
1187 -- miscellaneous parameters:
1188 -- LF separated list (old system) or serialized PHP array (new system)
1189 log_params nvarchar(max) NOT NULL,
1190
1191 -- rev_deleted for logs
1192 log_deleted tinyint NOT NULL default 0
1193 );
1194
1195 CREATE INDEX /*i*/type_time ON /*_*/logging (log_type, log_timestamp);
1196 CREATE INDEX /*i*/user_time ON /*_*/logging (log_user, log_timestamp);
1197 CREATE INDEX /*i*/page_time ON /*_*/logging (log_namespace, log_title, log_timestamp);
1198 CREATE INDEX /*i*/times ON /*_*/logging (log_timestamp);
1199 CREATE INDEX /*i*/log_user_type_time ON /*_*/logging (log_user, log_type, log_timestamp);
1200 CREATE INDEX /*i*/log_page_id_time ON /*_*/logging (log_page,log_timestamp);
1201 CREATE INDEX /*i*/type_action ON /*_*/logging (log_type, log_action, log_timestamp);
1202 CREATE INDEX /*i*/log_user_text_type_time ON /*_*/logging (log_user_text, log_type, log_timestamp);
1203 CREATE INDEX /*i*/log_user_text_time ON /*_*/logging (log_user_text, log_timestamp);
1204 CREATE INDEX /*i*/actor_time ON /*_*/logging (log_actor, log_timestamp);
1205 CREATE INDEX /*i*/log_actor_type_time ON /*_*/logging (log_actor, log_type, log_timestamp);
1206
1207 INSERT INTO /*_*/logging (log_user,log_page,log_params) VALUES(0,0,'');
1208
1209 ALTER TABLE /*_*/recentchanges ADD CONSTRAINT rc_logid__log_id__fk FOREIGN KEY (rc_logid) REFERENCES /*_*/logging(log_id) ON DELETE CASCADE;
1210
1211 CREATE TABLE /*_*/log_search (
1212 -- The type of ID (rev ID, log ID, rev timestamp, username)
1213 ls_field nvarchar(32) NOT NULL,
1214 -- The value of the ID
1215 ls_value nvarchar(255) NOT NULL,
1216 -- Key to log_id
1217 ls_log_id int REFERENCES /*_*/logging(log_id) ON DELETE CASCADE
1218 );
1219 CREATE UNIQUE INDEX /*i*/ls_field_val ON /*_*/log_search (ls_field,ls_value,ls_log_id);
1220 CREATE INDEX /*i*/ls_log_id ON /*_*/log_search (ls_log_id);
1221
1222
1223 -- Jobs performed by parallel apache threads or a command-line daemon
1224 CREATE TABLE /*_*/job (
1225 job_id int NOT NULL PRIMARY KEY IDENTITY,
1226
1227 -- Command name
1228 -- Limited to 60 to prevent key length overflow
1229 job_cmd nvarchar(60) NOT NULL default '',
1230
1231 -- Namespace and title to act on
1232 -- Should be 0 and '' if the command does not operate on a title
1233 job_namespace int NOT NULL,
1234 job_title nvarchar(255) NOT NULL,
1235
1236 -- Timestamp of when the job was inserted
1237 -- NULL for jobs added before addition of the timestamp
1238 job_timestamp nvarchar(14) NULL default NULL,
1239
1240 -- Any other parameters to the command
1241 -- Stored as a PHP serialized array, or an empty string if there are no parameters
1242 job_params nvarchar(max) NOT NULL,
1243
1244 -- Random, non-unique, number used for job acquisition (for lock concurrency)
1245 job_random int NOT NULL default 0,
1246
1247 -- The number of times this job has been locked
1248 job_attempts int NOT NULL default 0,
1249
1250 -- Field that conveys process locks on rows via process UUIDs
1251 job_token nvarchar(32) NOT NULL default '',
1252
1253 -- Timestamp when the job was locked
1254 job_token_timestamp varchar(14) NULL default NULL,
1255
1256 -- Base 36 SHA1 of the job parameters relevant to detecting duplicates
1257 job_sha1 nvarchar(32) NOT NULL default ''
1258 );
1259
1260 CREATE INDEX /*i*/job_sha1 ON /*_*/job (job_sha1);
1261 CREATE INDEX /*i*/job_cmd_token ON /*_*/job (job_cmd,job_token,job_random);
1262 CREATE INDEX /*i*/job_cmd_token_id ON /*_*/job (job_cmd,job_token,job_id);
1263 CREATE INDEX /*i*/job_cmd ON /*_*/job (job_cmd, job_namespace, job_title);
1264 CREATE INDEX /*i*/job_timestamp ON /*_*/job (job_timestamp);
1265
1266
1267 -- Details of updates to cached special pages
1268 CREATE TABLE /*_*/querycache_info (
1269 -- Special page name
1270 -- Corresponds to a qc_type value
1271 qci_type nvarchar(32) NOT NULL default '',
1272
1273 -- Timestamp of last update
1274 qci_timestamp varchar(14) NOT NULL default ''
1275 );
1276
1277 CREATE UNIQUE INDEX /*i*/qci_type ON /*_*/querycache_info (qci_type);
1278
1279
1280 -- For each redirect, this table contains exactly one row defining its target
1281 CREATE TABLE /*_*/redirect (
1282 -- Key to the page_id of the redirect page
1283 rd_from int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
1284
1285 -- Key to page_namespace/page_title of the target page.
1286 -- The target page may or may not exist, and due to renames
1287 -- and deletions may refer to different page records as time
1288 -- goes by.
1289 rd_namespace int NOT NULL default 0,
1290 rd_title nvarchar(255) NOT NULL default '',
1291 rd_interwiki nvarchar(32) default NULL,
1292 rd_fragment nvarchar(255) default NULL
1293 );
1294
1295 CREATE INDEX /*i*/rd_ns_title ON /*_*/redirect (rd_namespace,rd_title,rd_from);
1296
1297
1298 -- Used for caching expensive grouped queries that need two links (for example double-redirects)
1299 CREATE TABLE /*_*/querycachetwo (
1300 -- A key name, generally the base name of of the special page.
1301 qcc_type nvarchar(32) NOT NULL,
1302
1303 -- Some sort of stored value. Sizes, counts...
1304 qcc_value int NOT NULL default 0,
1305
1306 -- Target namespace+title
1307 qcc_namespace int NOT NULL default 0,
1308 qcc_title nvarchar(255) NOT NULL default '',
1309
1310 -- Target namespace+title2
1311 qcc_namespacetwo int NOT NULL default 0,
1312 qcc_titletwo nvarchar(255) NOT NULL default ''
1313 );
1314
1315 CREATE INDEX /*i*/qcc_type ON /*_*/querycachetwo (qcc_type,qcc_value);
1316 CREATE INDEX /*i*/qcc_title ON /*_*/querycachetwo (qcc_type,qcc_namespace,qcc_title);
1317 CREATE INDEX /*i*/qcc_titletwo ON /*_*/querycachetwo (qcc_type,qcc_namespacetwo,qcc_titletwo);
1318
1319
1320 -- Used for storing page restrictions (i.e. protection levels)
1321 CREATE TABLE /*_*/page_restrictions (
1322 -- Field for an ID for this restrictions row (sort-key for Special:ProtectedPages)
1323 pr_id int NOT NULL PRIMARY KEY IDENTITY,
1324 -- Page to apply restrictions to (Foreign Key to page).
1325 pr_page int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
1326 -- The protection type (edit, move, etc)
1327 pr_type nvarchar(60) NOT NULL,
1328 -- The protection level (Sysop, autoconfirmed, etc)
1329 pr_level nvarchar(60) NOT NULL,
1330 -- Whether or not to cascade the protection down to pages transcluded.
1331 pr_cascade bit NOT NULL,
1332 -- Field for future support of per-user restriction.
1333 pr_user int NULL,
1334 -- Field for time-limited protection.
1335 pr_expiry varchar(14) NULL
1336 );
1337
1338 CREATE UNIQUE INDEX /*i*/pr_pagetype ON /*_*/page_restrictions (pr_page,pr_type);
1339 CREATE INDEX /*i*/pr_typelevel ON /*_*/page_restrictions (pr_type,pr_level);
1340 CREATE INDEX /*i*/pr_level ON /*_*/page_restrictions (pr_level);
1341 CREATE INDEX /*i*/pr_cascade ON /*_*/page_restrictions (pr_cascade);
1342
1343
1344 -- Protected titles - nonexistent pages that have been protected
1345 CREATE TABLE /*_*/protected_titles (
1346 pt_namespace int NOT NULL,
1347 pt_title nvarchar(255) NOT NULL,
1348 pt_user int REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
1349 pt_reason nvarchar(255) CONSTRAINT DF_pt_reason DEFAULT '',
1350 pt_reason_id bigint unsigned NOT NULL CONSTRAINT DF_pt_reason_id DEFAULT 0 CONSTRAINT FK_pt_reason_id FOREIGN KEY REFERENCES /*_*/comment(comment_id),
1351 pt_timestamp varchar(14) NOT NULL,
1352 pt_expiry varchar(14) NOT NULL,
1353 pt_create_perm nvarchar(60) NOT NULL
1354 );
1355
1356 CREATE UNIQUE INDEX /*i*/pt_namespace_title ON /*_*/protected_titles (pt_namespace,pt_title);
1357 CREATE INDEX /*i*/pt_timestamp ON /*_*/protected_titles (pt_timestamp);
1358
1359
1360 -- Name/value pairs indexed by page_id
1361 CREATE TABLE /*_*/page_props (
1362 pp_page int NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
1363 pp_propname nvarchar(60) NOT NULL,
1364 pp_value nvarchar(max) NOT NULL,
1365 pp_sortkey float DEFAULT NULL
1366 );
1367
1368 CREATE UNIQUE INDEX /*i*/pp_page_propname ON /*_*/page_props (pp_page,pp_propname);
1369 CREATE UNIQUE INDEX /*i*/pp_propname_page ON /*_*/page_props (pp_propname,pp_page);
1370 CREATE UNIQUE INDEX /*i*/pp_propname_sortkey_page ON /*_*/page_props (pp_propname,pp_sortkey,pp_page);
1371
1372
1373 -- A table to log updates, one text key row per update.
1374 CREATE TABLE /*_*/updatelog (
1375 ul_key nvarchar(255) NOT NULL PRIMARY KEY,
1376 ul_value nvarchar(max)
1377 );
1378
1379
1380 -- A table to track tags for revisions, logs and recent changes.
1381 CREATE TABLE /*_*/change_tag (
1382 ct_id int NOT NULL PRIMARY KEY IDENTITY,
1383 -- RCID for the change
1384 ct_rc_id int NULL REFERENCES /*_*/recentchanges(rc_id),
1385 -- LOGID for the change
1386 ct_log_id int NULL REFERENCES /*_*/logging(log_id),
1387 -- REVID for the change
1388 ct_rev_id int NULL REFERENCES /*_*/revision(rev_id),
1389 -- Tag applied
1390 ct_tag nvarchar(255) NOT NULL,
1391 -- Parameters for the tag, presently unused
1392 ct_params nvarchar(max) NULL
1393 );
1394
1395 CREATE UNIQUE INDEX /*i*/change_tag_rc_tag ON /*_*/change_tag (ct_rc_id,ct_tag);
1396 CREATE UNIQUE INDEX /*i*/change_tag_log_tag ON /*_*/change_tag (ct_log_id,ct_tag);
1397 CREATE UNIQUE INDEX /*i*/change_tag_rev_tag ON /*_*/change_tag (ct_rev_id,ct_tag);
1398 -- Covering index, so we can pull all the info only out of the index.
1399 CREATE INDEX /*i*/change_tag_tag_id ON /*_*/change_tag (ct_tag,ct_rc_id,ct_rev_id,ct_log_id);
1400
1401
1402 -- Rollup table to pull a LIST of tags simply without ugly GROUP_CONCAT
1403 -- that only works on MySQL 4.1+
1404 CREATE TABLE /*_*/tag_summary (
1405 ts_id int NOT NULL PRIMARY KEY IDENTITY,
1406 -- RCID for the change
1407 ts_rc_id int NULL REFERENCES /*_*/recentchanges(rc_id),
1408 -- LOGID for the change
1409 ts_log_id int NULL REFERENCES /*_*/logging(log_id),
1410 -- REVID for the change
1411 ts_rev_id int NULL REFERENCES /*_*/revision(rev_id),
1412 -- Comma-separated list of tags
1413 ts_tags nvarchar(max) NOT NULL
1414 );
1415
1416 CREATE UNIQUE INDEX /*i*/tag_summary_rc_id ON /*_*/tag_summary (ts_rc_id);
1417 CREATE UNIQUE INDEX /*i*/tag_summary_log_id ON /*_*/tag_summary (ts_log_id);
1418 CREATE UNIQUE INDEX /*i*/tag_summary_rev_id ON /*_*/tag_summary (ts_rev_id);
1419
1420
1421 CREATE TABLE /*_*/valid_tag (
1422 vt_tag nvarchar(255) NOT NULL PRIMARY KEY
1423 );
1424
1425 -- Table for storing localisation data
1426 CREATE TABLE /*_*/l10n_cache (
1427 -- Language code
1428 lc_lang nvarchar(32) NOT NULL,
1429 -- Cache key
1430 lc_key nvarchar(255) NOT NULL,
1431 -- Value
1432 lc_value varbinary(max) NOT NULL
1433 );
1434 CREATE INDEX /*i*/lc_lang_key ON /*_*/l10n_cache (lc_lang, lc_key);
1435
1436 -- Table caching which local files a module depends on that aren't
1437 -- registered directly, used for fast retrieval of file dependency.
1438 -- Currently only used for tracking images that CSS depends on
1439 CREATE TABLE /*_*/module_deps (
1440 -- Module name
1441 md_module nvarchar(255) NOT NULL,
1442 -- Skin name
1443 md_skin nvarchar(32) NOT NULL,
1444 -- JSON nvarchar(max) with file dependencies
1445 md_deps nvarchar(max) NOT NULL
1446 );
1447 CREATE UNIQUE INDEX /*i*/md_module_skin ON /*_*/module_deps (md_module, md_skin);
1448
1449 -- Holds all the sites known to the wiki.
1450 CREATE TABLE /*_*/sites (
1451 -- Numeric id of the site
1452 site_id int NOT NULL PRIMARY KEY IDENTITY,
1453
1454 -- Global identifier for the site, ie 'enwiktionary'
1455 site_global_key nvarchar(32) NOT NULL,
1456
1457 -- Type of the site, ie 'mediawiki'
1458 site_type nvarchar(32) NOT NULL,
1459
1460 -- Group of the site, ie 'wikipedia'
1461 site_group nvarchar(32) NOT NULL,
1462
1463 -- Source of the site data, ie 'local', 'wikidata', 'my-magical-repo'
1464 site_source nvarchar(32) NOT NULL,
1465
1466 -- Language code of the sites primary language.
1467 site_language nvarchar(32) NOT NULL,
1468
1469 -- Protocol of the site, ie 'http://', 'irc://', '//'
1470 -- This field is an index for lookups and is build from type specific data in site_data.
1471 site_protocol nvarchar(32) NOT NULL,
1472
1473 -- Domain of the site in reverse order, ie 'org.mediawiki.www.'
1474 -- This field is an index for lookups and is build from type specific data in site_data.
1475 site_domain NVARCHAR(255) NOT NULL,
1476
1477 -- Type dependent site data.
1478 site_data nvarchar(max) NOT NULL,
1479
1480 -- If site.tld/path/key:pageTitle should forward users to the page on
1481 -- the actual site, where "key" is the local identifier.
1482 site_forward bit NOT NULL,
1483
1484 -- Type dependent site config.
1485 -- For instance if template transclusion should be allowed if it's a MediaWiki.
1486 site_config nvarchar(max) NOT NULL
1487 );
1488
1489 CREATE UNIQUE INDEX /*i*/sites_global_key ON /*_*/sites (site_global_key);
1490 CREATE INDEX /*i*/sites_type ON /*_*/sites (site_type);
1491 CREATE INDEX /*i*/sites_group ON /*_*/sites (site_group);
1492 CREATE INDEX /*i*/sites_source ON /*_*/sites (site_source);
1493 CREATE INDEX /*i*/sites_language ON /*_*/sites (site_language);
1494 CREATE INDEX /*i*/sites_protocol ON /*_*/sites (site_protocol);
1495 CREATE INDEX /*i*/sites_domain ON /*_*/sites (site_domain);
1496 CREATE INDEX /*i*/sites_forward ON /*_*/sites (site_forward);
1497
1498 -- Links local site identifiers to their corresponding site.
1499 CREATE TABLE /*_*/site_identifiers (
1500 -- Key on site.site_id
1501 si_site int NOT NULL REFERENCES /*_*/sites(site_id) ON DELETE CASCADE,
1502
1503 -- local key type, ie 'interwiki' or 'langlink'
1504 si_type nvarchar(32) NOT NULL,
1505
1506 -- local key value, ie 'en' or 'wiktionary'
1507 si_key nvarchar(32) NOT NULL
1508 );
1509
1510 CREATE UNIQUE INDEX /*i*/site_ids_type ON /*_*/site_identifiers (si_type, si_key);
1511 CREATE INDEX /*i*/site_ids_site ON /*_*/site_identifiers (si_site);
1512 CREATE INDEX /*i*/site_ids_key ON /*_*/site_identifiers (si_key);