wiki.techinc.nl/maintenance/postgres/tables-generated.sql
Amir Sarabadani a9dcbe3585 Migrate sites table to abstract schema
For MySQL/Sqlite, using mwtinyint instead of bool, in reality it doesn't
matter since bool is an alias of tinyint(1) in MySQL.

In Postgres:
 - Changing type of site_domain from TEXT to VARCHAR to make it in sync
   with MySQL/Sqlite
 - Renaming all indexes from site_* to sites_* to be in sync with
   MySQL/Sqlite

Bug: T230428
Bug: T164898
Change-Id: Id73bb372807730446901d772fcdbd2f333b397ba
2020-10-22 19:35:39 +02:00

399 lines
9.5 KiB
SQL

-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: maintenance/tables.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE site_identifiers (
si_type TEXT NOT NULL,
si_key TEXT NOT NULL,
si_site INT NOT NULL,
PRIMARY KEY(si_type, si_key)
);
CREATE INDEX site_ids_site ON site_identifiers (si_site);
CREATE INDEX site_ids_key ON site_identifiers (si_key);
CREATE TABLE updatelog (
ul_key VARCHAR(255) NOT NULL,
ul_value TEXT DEFAULT NULL,
PRIMARY KEY(ul_key)
);
CREATE TABLE actor (
actor_id BIGSERIAL NOT NULL,
actor_user INT DEFAULT NULL,
actor_name TEXT NOT NULL,
PRIMARY KEY(actor_id)
);
CREATE UNIQUE INDEX actor_user ON actor (actor_user);
CREATE UNIQUE INDEX actor_name ON actor (actor_name);
CREATE TABLE user_former_groups (
ufg_user INT DEFAULT 0 NOT NULL,
ufg_group TEXT DEFAULT '' NOT NULL,
PRIMARY KEY(ufg_user, ufg_group)
);
CREATE TABLE bot_passwords (
bp_user INT NOT NULL,
bp_app_id TEXT NOT NULL,
bp_password TEXT NOT NULL,
bp_token TEXT DEFAULT '' NOT NULL,
bp_restrictions TEXT NOT NULL,
bp_grants TEXT NOT NULL,
PRIMARY KEY(bp_user, bp_app_id)
);
CREATE TABLE comment (
comment_id BIGSERIAL NOT NULL,
comment_hash INT NOT NULL,
comment_text TEXT NOT NULL,
comment_data TEXT DEFAULT NULL,
PRIMARY KEY(comment_id)
);
CREATE INDEX comment_hash ON comment (comment_hash);
CREATE TABLE slots (
slot_revision_id BIGINT NOT NULL,
slot_role_id SMALLINT NOT NULL,
slot_content_id BIGINT NOT NULL,
slot_origin BIGINT NOT NULL,
PRIMARY KEY(slot_revision_id, slot_role_id)
);
CREATE INDEX slot_revision_origin_role ON slots (
slot_revision_id, slot_origin, slot_role_id
);
CREATE TABLE site_stats (
ss_row_id INT NOT NULL,
ss_total_edits BIGINT DEFAULT NULL,
ss_good_articles BIGINT DEFAULT NULL,
ss_total_pages BIGINT DEFAULT NULL,
ss_users BIGINT DEFAULT NULL,
ss_active_users BIGINT DEFAULT NULL,
ss_images BIGINT DEFAULT NULL,
PRIMARY KEY(ss_row_id)
);
CREATE TABLE user_properties (
up_user INT NOT NULL,
up_property TEXT NOT NULL,
up_value TEXT DEFAULT NULL,
PRIMARY KEY(up_user, up_property)
);
CREATE INDEX user_properties_property ON user_properties (up_property);
CREATE TABLE log_search (
ls_field TEXT NOT NULL,
ls_value VARCHAR(255) NOT NULL,
ls_log_id INT DEFAULT 0 NOT NULL,
PRIMARY KEY(ls_field, ls_value, ls_log_id)
);
CREATE INDEX ls_log_id ON log_search (ls_log_id);
CREATE TABLE change_tag (
ct_id SERIAL NOT NULL,
ct_rc_id INT DEFAULT NULL,
ct_log_id INT DEFAULT NULL,
ct_rev_id INT DEFAULT NULL,
ct_params TEXT DEFAULT NULL,
ct_tag_id INT NOT NULL,
PRIMARY KEY(ct_id)
);
CREATE UNIQUE INDEX change_tag_rc_tag_id ON change_tag (ct_rc_id, ct_tag_id);
CREATE UNIQUE INDEX change_tag_log_tag_id ON change_tag (ct_log_id, ct_tag_id);
CREATE UNIQUE INDEX change_tag_rev_tag_id ON change_tag (ct_rev_id, ct_tag_id);
CREATE INDEX change_tag_tag_id_id ON change_tag (
ct_tag_id, ct_rc_id, ct_rev_id, ct_log_id
);
CREATE TABLE content (
content_id BIGSERIAL NOT NULL,
content_size INT NOT NULL,
content_sha1 TEXT NOT NULL,
content_model SMALLINT NOT NULL,
content_address TEXT NOT NULL,
PRIMARY KEY(content_id)
);
CREATE TABLE l10n_cache (
lc_lang TEXT NOT NULL,
lc_key VARCHAR(255) NOT NULL,
lc_value TEXT NOT NULL,
PRIMARY KEY(lc_lang, lc_key)
);
CREATE TABLE module_deps (
md_module TEXT NOT NULL,
md_skin TEXT NOT NULL,
md_deps TEXT NOT NULL,
PRIMARY KEY(md_module, md_skin)
);
CREATE TABLE redirect (
rd_from INT DEFAULT 0 NOT NULL,
rd_namespace INT DEFAULT 0 NOT NULL,
rd_title TEXT DEFAULT '' NOT NULL,
rd_interwiki VARCHAR(32) DEFAULT NULL,
rd_fragment TEXT DEFAULT NULL,
PRIMARY KEY(rd_from)
);
CREATE INDEX rd_ns_title ON redirect (rd_namespace, rd_title, rd_from);
CREATE TABLE pagelinks (
pl_from INT DEFAULT 0 NOT NULL,
pl_namespace INT DEFAULT 0 NOT NULL,
pl_title TEXT DEFAULT '' NOT NULL,
pl_from_namespace INT DEFAULT 0 NOT NULL,
PRIMARY KEY(pl_from, pl_namespace, pl_title)
);
CREATE INDEX pl_namespace ON pagelinks (pl_namespace, pl_title, pl_from);
CREATE INDEX pl_backlinks_namespace ON pagelinks (
pl_from_namespace, pl_namespace,
pl_title, pl_from
);
CREATE TABLE templatelinks (
tl_from INT DEFAULT 0 NOT NULL,
tl_namespace INT DEFAULT 0 NOT NULL,
tl_title TEXT DEFAULT '' NOT NULL,
tl_from_namespace INT DEFAULT 0 NOT NULL,
PRIMARY KEY(tl_from, tl_namespace, tl_title)
);
CREATE INDEX tl_namespace ON templatelinks (tl_namespace, tl_title, tl_from);
CREATE INDEX tl_backlinks_namespace ON templatelinks (
tl_from_namespace, tl_namespace,
tl_title, tl_from
);
CREATE TABLE imagelinks (
il_from INT DEFAULT 0 NOT NULL,
il_to TEXT DEFAULT '' NOT NULL,
il_from_namespace INT DEFAULT 0 NOT NULL,
PRIMARY KEY(il_from, il_to)
);
CREATE INDEX il_to ON imagelinks (il_to, il_from);
CREATE INDEX il_backlinks_namespace ON imagelinks (
il_from_namespace, il_to, il_from
);
CREATE TABLE langlinks (
ll_from INT DEFAULT 0 NOT NULL,
ll_lang TEXT DEFAULT '' NOT NULL,
ll_title TEXT DEFAULT '' NOT NULL,
PRIMARY KEY(ll_from, ll_lang)
);
CREATE INDEX ll_lang ON langlinks (ll_lang, ll_title);
CREATE TABLE iwlinks (
iwl_from INT DEFAULT 0 NOT NULL,
iwl_prefix TEXT DEFAULT '' NOT NULL,
iwl_title TEXT DEFAULT '' NOT NULL,
PRIMARY KEY(iwl_from, iwl_prefix, iwl_title)
);
CREATE INDEX iwl_prefix_title_from ON iwlinks (iwl_prefix, iwl_title, iwl_from);
CREATE INDEX iwl_prefix_from_title ON iwlinks (iwl_prefix, iwl_from, iwl_title);
CREATE TABLE category (
cat_id SERIAL NOT NULL,
cat_title TEXT NOT NULL,
cat_pages INT DEFAULT 0 NOT NULL,
cat_subcats INT DEFAULT 0 NOT NULL,
cat_files INT DEFAULT 0 NOT NULL,
PRIMARY KEY(cat_id)
);
CREATE UNIQUE INDEX cat_title ON category (cat_title);
CREATE INDEX cat_pages ON category (cat_pages);
CREATE TABLE watchlist_expiry (
we_item INT NOT NULL,
we_expiry TIMESTAMPTZ NOT NULL,
PRIMARY KEY(we_item)
);
CREATE INDEX we_expiry ON watchlist_expiry (we_expiry);
CREATE TABLE change_tag_def (
ctd_id SERIAL NOT NULL,
ctd_name TEXT NOT NULL,
ctd_user_defined SMALLINT NOT NULL,
ctd_count BIGINT DEFAULT 0 NOT NULL,
PRIMARY KEY(ctd_id)
);
CREATE UNIQUE INDEX ctd_name ON change_tag_def (ctd_name);
CREATE INDEX ctd_count ON change_tag_def (ctd_count);
CREATE INDEX ctd_user_defined ON change_tag_def (ctd_user_defined);
CREATE TABLE ipblocks_restrictions (
ir_ipb_id INT NOT NULL,
ir_type SMALLINT NOT NULL,
ir_value INT NOT NULL,
PRIMARY KEY(ir_ipb_id, ir_type, ir_value)
);
CREATE INDEX ir_type_value ON ipblocks_restrictions (ir_type, ir_value);
CREATE TABLE querycache (
qc_type TEXT NOT NULL, qc_value INT DEFAULT 0 NOT NULL,
qc_namespace INT DEFAULT 0 NOT NULL,
qc_title TEXT DEFAULT '' NOT NULL
);
CREATE INDEX qc_type ON querycache (qc_type, qc_value);
CREATE TABLE querycachetwo (
qcc_type TEXT NOT NULL, qcc_value INT DEFAULT 0 NOT NULL,
qcc_namespace INT DEFAULT 0 NOT NULL,
qcc_title TEXT DEFAULT '' NOT NULL,
qcc_namespacetwo INT DEFAULT 0 NOT NULL,
qcc_titletwo TEXT DEFAULT '' NOT NULL
);
CREATE INDEX qcc_type ON querycachetwo (qcc_type, qcc_value);
CREATE INDEX qcc_title ON querycachetwo (
qcc_type, qcc_namespace, qcc_title
);
CREATE INDEX qcc_titletwo ON querycachetwo (
qcc_type, qcc_namespacetwo, qcc_titletwo
);
CREATE TABLE page_restrictions (
pr_id SERIAL NOT NULL,
pr_page INT NOT NULL,
pr_type TEXT NOT NULL,
pr_level TEXT NOT NULL,
pr_cascade SMALLINT NOT NULL,
pr_user INT DEFAULT NULL,
pr_expiry TIMESTAMPTZ DEFAULT NULL,
PRIMARY KEY(pr_id)
);
CREATE UNIQUE INDEX pr_pagetype ON page_restrictions (pr_page, pr_type);
CREATE INDEX pr_typelevel ON page_restrictions (pr_type, pr_level);
CREATE INDEX pr_level ON page_restrictions (pr_level);
CREATE INDEX pr_cascade ON page_restrictions (pr_cascade);
CREATE TABLE user_groups (
ug_user INT DEFAULT 0 NOT NULL,
ug_group TEXT DEFAULT '' NOT NULL,
ug_expiry TIMESTAMPTZ DEFAULT NULL,
PRIMARY KEY(ug_user, ug_group)
);
CREATE INDEX ug_group ON user_groups (ug_group);
CREATE INDEX ug_expiry ON user_groups (ug_expiry);
CREATE TABLE querycache_info (
qci_type TEXT DEFAULT '' NOT NULL,
qci_timestamp TIMESTAMPTZ DEFAULT '1970-01-01 00:00:00+00' NOT NULL,
PRIMARY KEY(qci_type)
);
CREATE TABLE watchlist (
wl_id SERIAL NOT NULL,
wl_user INT NOT NULL,
wl_namespace INT DEFAULT 0 NOT NULL,
wl_title TEXT DEFAULT '' NOT NULL,
wl_notificationtimestamp TIMESTAMPTZ DEFAULT NULL,
PRIMARY KEY(wl_id)
);
CREATE UNIQUE INDEX wl_user ON watchlist (wl_user, wl_namespace, wl_title);
CREATE INDEX namespace_title ON watchlist (wl_namespace, wl_title);
CREATE INDEX wl_user_notificationtimestamp ON watchlist (
wl_user, wl_notificationtimestamp
);
CREATE TABLE sites (
site_id SERIAL NOT NULL,
site_global_key TEXT NOT NULL,
site_type TEXT NOT NULL,
site_group TEXT NOT NULL,
site_source TEXT NOT NULL,
site_language TEXT NOT NULL,
site_protocol TEXT NOT NULL,
site_domain VARCHAR(255) NOT NULL,
site_data TEXT NOT NULL,
site_forward SMALLINT NOT NULL,
site_config TEXT NOT NULL,
PRIMARY KEY(site_id)
);
CREATE UNIQUE INDEX sites_global_key ON sites (site_global_key);
CREATE INDEX sites_type ON sites (site_type);
CREATE INDEX sites_group ON sites (site_group);
CREATE INDEX sites_source ON sites (site_source);
CREATE INDEX sites_language ON sites (site_language);
CREATE INDEX sites_protocol ON sites (site_protocol);
CREATE INDEX sites_domain ON sites (site_domain);
CREATE INDEX sites_forward ON sites (site_forward);