CREATE TABLE /*_*/site_identifiers (
  si_type BLOB NOT NULL,
  si_key BLOB NOT NULL,
  si_site INTEGER  NOT NULL,
  PRIMARY KEY(si_type, si_key)
);
CREATE INDEX si_site ON /*_*/site_identifiers (si_site);
CREATE INDEX si_key ON /*_*/site_identifiers (si_key);

CREATE TABLE /*_*/updatelog (
  ul_key TEXT NOT NULL,
  ul_value BLOB DEFAULT NULL,
  PRIMARY KEY(ul_key)
);

CREATE TABLE /*_*/actor (
  actor_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  actor_user INTEGER  DEFAULT NULL,
  actor_name BLOB NOT NULL
);
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 INTEGER  DEFAULT 0 NOT NULL,
  ufg_group BLOB DEFAULT '' NOT NULL,
  PRIMARY KEY(ufg_user, ufg_group)
);

CREATE TABLE /*_*/bot_passwords (
  bp_user INTEGER  NOT NULL,
  bp_app_id BLOB NOT NULL,
  bp_password BLOB NOT NULL,
  bp_token BLOB DEFAULT '' NOT NULL,
  bp_restrictions BLOB NOT NULL,
  bp_grants BLOB NOT NULL,
  PRIMARY KEY(bp_user, bp_app_id)
);

CREATE TABLE /*_*/comment (
  comment_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  comment_hash INTEGER NOT NULL, comment_text BLOB NOT NULL,
  comment_data BLOB DEFAULT NULL
);
CREATE INDEX comment_hash ON /*_*/comment (comment_hash);

CREATE TABLE /*_*/slots (
  slot_revision_id INTEGER  NOT NULL,
  slot_role_id INTEGER  NOT NULL,
  slot_content_id INTEGER  NOT NULL,
  slot_origin INTEGER  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 INTEGER UNSIGNED NOT NULL,
  ss_total_edits INTEGER  DEFAULT NULL,
  ss_good_articles INTEGER  DEFAULT NULL,
  ss_total_pages INTEGER  DEFAULT NULL,
  ss_users INTEGER  DEFAULT NULL,
  ss_active_users INTEGER  DEFAULT NULL,
  ss_images INTEGER  DEFAULT NULL,
  PRIMARY KEY(ss_row_id)
);

CREATE TABLE /*_*/user_properties (
  up_user INTEGER  NOT NULL,
  up_property BLOB NOT NULL,
  up_value BLOB DEFAULT NULL,
  PRIMARY KEY(up_user, up_property)
);
CREATE INDEX up_property ON /*_*/user_properties (up_property);

CREATE TABLE /*_*/log_search (
  ls_field BLOB NOT NULL,
  ls_value TEXT NOT NULL,
  ls_log_id INTEGER  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 INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  ct_rc_id INTEGER  DEFAULT NULL,
  ct_log_id INTEGER  DEFAULT NULL,
  ct_rev_id INTEGER  DEFAULT NULL,
  ct_params BLOB DEFAULT NULL, ct_tag_id INTEGER  NOT NULL
);
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 INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  content_size INTEGER  NOT NULL,
  content_sha1 BLOB NOT NULL, content_model INTEGER  NOT NULL,
  content_address BLOB NOT NULL
);

CREATE TABLE /*_*/l10n_cache (
  lc_lang BLOB NOT NULL,
  lc_key TEXT NOT NULL,
  lc_value BLOB NOT NULL,
  PRIMARY KEY(lc_lang, lc_key)
);

CREATE TABLE /*_*/module_deps (
  md_module BLOB NOT NULL,
  md_skin BLOB NOT NULL,
  md_deps BLOB NOT NULL,
  PRIMARY KEY(md_module, md_skin)
);

CREATE TABLE /*_*/redirect (
  rd_from INTEGER  DEFAULT 0 NOT NULL,
  rd_namespace INTEGER DEFAULT 0 NOT NULL,
  rd_title BLOB DEFAULT '' NOT NULL,
  rd_interwiki TEXT DEFAULT NULL,
  rd_fragment BLOB DEFAULT NULL,
  PRIMARY KEY(rd_from)
);
CREATE INDEX rd_ns_title ON /*_*/redirect (rd_namespace, rd_title, rd_from);

CREATE TABLE /*_*/pagelinks (
  pl_from INTEGER  DEFAULT 0 NOT NULL,
  pl_namespace INTEGER DEFAULT 0 NOT NULL,
  pl_title BLOB DEFAULT '' NOT NULL,
  pl_from_namespace INTEGER 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 INTEGER  DEFAULT 0 NOT NULL,
  tl_namespace INTEGER DEFAULT 0 NOT NULL,
  tl_title BLOB DEFAULT '' NOT NULL,
  tl_from_namespace INTEGER 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 INTEGER  DEFAULT 0 NOT NULL,
  il_to BLOB DEFAULT '' NOT NULL,
  il_from_namespace INTEGER 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 INTEGER  DEFAULT 0 NOT NULL,
  ll_lang BLOB DEFAULT '' NOT NULL,
  ll_title BLOB DEFAULT '' NOT NULL,
  PRIMARY KEY(ll_from, ll_lang)
);
CREATE INDEX ll_lang ON /*_*/langlinks (ll_lang, ll_title);

CREATE TABLE /*_*/iwlinks (
  iwl_from INTEGER  DEFAULT 0 NOT NULL,
  iwl_prefix BLOB DEFAULT '' NOT NULL,
  iwl_title BLOB 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 INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  cat_title BLOB NOT NULL, cat_pages INTEGER DEFAULT 0 NOT NULL,
  cat_subcats INTEGER DEFAULT 0 NOT NULL,
  cat_files INTEGER DEFAULT 0 NOT NULL
);
CREATE UNIQUE INDEX cat_title ON /*_*/category (cat_title);
CREATE INDEX cat_pages ON /*_*/category (cat_pages);

CREATE TABLE /*_*/watchlist_expiry (
  we_item INTEGER UNSIGNED NOT NULL,
  we_expiry BLOB NOT NULL,
  PRIMARY KEY(we_item)
);
CREATE INDEX we_expiry ON /*_*/watchlist_expiry (we_expiry);

CREATE TABLE /*_*/change_tag_def (
  ctd_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  ctd_name BLOB NOT NULL, ctd_user_defined INTEGER NOT NULL,
  ctd_count INTEGER  DEFAULT 0 NOT NULL
);
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 INTEGER NOT NULL,
  ir_type INTEGER NOT NULL,
  ir_value INTEGER 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 BLOB NOT NULL, qc_value INTEGER  DEFAULT 0 NOT NULL,
  qc_namespace INTEGER DEFAULT 0 NOT NULL,
  qc_title BLOB DEFAULT '' NOT NULL
);
CREATE INDEX qc_type ON /*_*/querycache (qc_type, qc_value);

CREATE TABLE /*_*/querycachetwo (
  qcc_type BLOB NOT NULL, qcc_value INTEGER  DEFAULT 0 NOT NULL,
  qcc_namespace INTEGER DEFAULT 0 NOT NULL,
  qcc_title BLOB DEFAULT '' NOT NULL,
  qcc_namespacetwo INTEGER DEFAULT 0 NOT NULL,
  qcc_titletwo BLOB 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 INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  pr_page INTEGER NOT NULL, pr_type BLOB NOT NULL,
  pr_level BLOB NOT NULL, pr_cascade INTEGER NOT NULL,
  pr_user INTEGER  DEFAULT NULL,
  pr_expiry BLOB DEFAULT NULL
);
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 INTEGER  DEFAULT 0 NOT NULL,
  ug_group BLOB DEFAULT '' NOT NULL,
  ug_expiry BLOB 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 BLOB DEFAULT '' NOT NULL,
  qci_timestamp BLOB DEFAULT '19700101000000' NOT NULL,
  PRIMARY KEY(qci_type)
);

CREATE TABLE /*_*/watchlist (
  wl_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  wl_user INTEGER  NOT NULL,
  wl_namespace INTEGER DEFAULT 0 NOT NULL,
  wl_title BLOB DEFAULT '' NOT NULL, wl_notificationtimestamp BLOB DEFAULT NULL
);
CREATE UNIQUE INDEX wl_user ON /*_*/watchlist (wl_user, wl_namespace, wl_title);
CREATE INDEX wl_namespace_title ON /*_*/watchlist (wl_namespace, wl_title);
CREATE INDEX wl_user_notificationtimestamp ON /*_*/watchlist (
  wl_user, wl_notificationtimestamp
);

CREATE TABLE /*_*/sites (
  site_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  site_global_key BLOB NOT NULL,
  site_type BLOB NOT NULL,
  site_group BLOB NOT NULL,
  site_source BLOB NOT NULL,
  site_language BLOB NOT NULL,
  site_protocol BLOB NOT NULL,
  site_domain TEXT NOT NULL,
  site_data BLOB NOT NULL,
  site_forward INTEGER NOT NULL,
  site_config BLOB NOT NULL
);
CREATE UNIQUE INDEX site_global_key ON /*_*/sites (site_global_key);
CREATE INDEX site_type ON /*_*/sites (site_type);
CREATE INDEX site_group ON /*_*/sites (site_group);
CREATE INDEX site_source ON /*_*/sites (site_source);
CREATE INDEX site_language ON /*_*/sites (site_language);
CREATE INDEX site_protocol ON /*_*/sites (site_protocol);
CREATE INDEX site_domain ON /*_*/sites (site_domain);
CREATE INDEX site_forward ON /*_*/sites (site_forward);

CREATE TABLE /*_*/user_newtalk (
  user_id INTEGER  DEFAULT 0 NOT NULL,
  user_ip BLOB DEFAULT '' NOT NULL, user_last_timestamp BLOB DEFAULT NULL
);
CREATE INDEX un_user_id ON /*_*/user_newtalk (user_id);
CREATE INDEX un_user_ip ON /*_*/user_newtalk (user_ip);

CREATE TABLE /*_*/interwiki (
  iw_prefix TEXT NOT NULL,
  iw_url BLOB NOT NULL,
  iw_api BLOB NOT NULL,
  iw_wikiid TEXT NOT NULL,
  iw_local INTEGER NOT NULL,
  iw_trans INTEGER DEFAULT 0 NOT NULL,
  PRIMARY KEY(iw_prefix)
);

CREATE TABLE /*_*/protected_titles (
  pt_namespace INTEGER NOT NULL,
  pt_title BLOB NOT NULL,
  pt_user INTEGER  NOT NULL,
  pt_reason_id INTEGER  NOT NULL,
  pt_timestamp BLOB NOT NULL,
  pt_expiry BLOB NOT NULL,
  pt_create_perm BLOB NOT NULL,
  PRIMARY KEY(pt_namespace, pt_title)
);
CREATE INDEX pt_timestamp ON /*_*/protected_titles (pt_timestamp);

CREATE TABLE /*_*/externallinks (
  el_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  el_from INTEGER  DEFAULT 0 NOT NULL,
  el_to BLOB NOT NULL, el_index BLOB NOT NULL,
  el_index_60 BLOB NOT NULL
);
CREATE INDEX el_from ON /*_*/externallinks (el_from, el_to);
CREATE INDEX el_to ON /*_*/externallinks (el_to, el_from);
CREATE INDEX el_index ON /*_*/externallinks (el_index);
CREATE INDEX el_index_60 ON /*_*/externallinks (el_index_60, el_id);
CREATE INDEX el_from_index_60 ON /*_*/externallinks (el_from, el_index_60, el_id);

CREATE TABLE /*_*/ip_changes (
  ipc_rev_id INTEGER  DEFAULT 0 NOT NULL,
  ipc_rev_timestamp BLOB NOT NULL,
  ipc_hex BLOB DEFAULT '' NOT NULL,
  PRIMARY KEY(ipc_rev_id)
);
CREATE INDEX ipc_rev_timestamp ON /*_*/ip_changes (ipc_rev_timestamp);
CREATE INDEX ipc_hex_time ON /*_*/ip_changes (ipc_hex, ipc_rev_timestamp);

CREATE TABLE /*_*/revision_comment_temp (
  revcomment_rev INTEGER  NOT NULL,
  revcomment_comment_id INTEGER  NOT NULL,
  PRIMARY KEY(
  revcomment_rev, revcomment_comment_id
  )
);
CREATE UNIQUE INDEX revcomment_rev ON /*_*/revision_comment_temp (revcomment_rev);

CREATE TABLE /*_*/revision_actor_temp (
  revactor_rev INTEGER  NOT NULL,
  revactor_actor INTEGER  NOT NULL,
  revactor_timestamp BLOB NOT NULL,
  revactor_page INTEGER  NOT NULL,
  PRIMARY KEY(revactor_rev, revactor_actor)
);
CREATE UNIQUE INDEX revactor_rev ON /*_*/revision_actor_temp (revactor_rev);
CREATE INDEX actor_timestamp ON /*_*/revision_actor_temp (
  revactor_actor, revactor_timestamp
);
CREATE INDEX page_actor_timestamp ON /*_*/revision_actor_temp (
  revactor_page, revactor_actor, revactor_timestamp
);

CREATE TABLE /*_*/page_props (
  pp_page INTEGER NOT NULL,
  pp_propname BLOB NOT NULL,
  pp_value BLOB NOT NULL,
  pp_sortkey REAL DEFAULT NULL,
  PRIMARY KEY(pp_page, pp_propname)
);
CREATE UNIQUE INDEX pp_propname_page ON /*_*/page_props (pp_propname, pp_page);
CREATE UNIQUE INDEX pp_propname_sortkey_page ON /*_*/page_props (pp_propname, pp_sortkey, pp_page);

CREATE TABLE /*_*/job (
  job_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  job_cmd BLOB DEFAULT '' NOT NULL, job_namespace INTEGER NOT NULL,
  job_title BLOB NOT NULL, job_timestamp BLOB DEFAULT NULL,
  job_params BLOB NOT NULL, job_random INTEGER  DEFAULT 0 NOT NULL,
  job_attempts INTEGER  DEFAULT 0 NOT NULL,
  job_token BLOB DEFAULT '' NOT NULL,
  job_token_timestamp BLOB DEFAULT NULL,
  job_sha1 BLOB DEFAULT '' NOT NULL
);
CREATE INDEX job_sha1 ON /*_*/job (job_sha1);
CREATE INDEX job_cmd_token ON /*_*/job (job_cmd, job_token, job_random);
CREATE INDEX job_cmd_token_id ON /*_*/job (job_cmd, job_token, job_id);
CREATE INDEX job_cmd ON /*_*/job (
  job_cmd, job_namespace, job_title,
  job_params
);
CREATE INDEX job_timestamp ON /*_*/job (job_timestamp);

CREATE TABLE /*_*/slot_roles (
  role_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  role_name BLOB NOT NULL
);
CREATE UNIQUE INDEX role_name ON /*_*/slot_roles (role_name);

CREATE TABLE /*_*/content_models (
  model_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  model_name BLOB NOT NULL
);
CREATE UNIQUE INDEX model_name ON /*_*/content_models (model_name);

CREATE TABLE /*_*/categorylinks (
  cl_from INTEGER  DEFAULT 0 NOT NULL,
  cl_to BLOB DEFAULT '' NOT NULL,
  cl_sortkey BLOB DEFAULT '' NOT NULL,
  cl_sortkey_prefix BLOB DEFAULT '' NOT NULL,
  cl_timestamp TEXT NOT NULL,
  cl_collation BLOB DEFAULT '' NOT NULL,
  cl_type TEXT DEFAULT 'page' NOT NULL,
  PRIMARY KEY(cl_from, cl_to)
);
CREATE INDEX cl_sortkey ON /*_*/categorylinks (
  cl_to, cl_type, cl_sortkey, cl_from
);
CREATE INDEX cl_timestamp ON /*_*/categorylinks (cl_to, cl_timestamp);
CREATE INDEX cl_collation_ext ON /*_*/categorylinks (
  cl_collation, cl_to, cl_type, cl_from
);

CREATE TABLE /*_*/logging (
  log_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  log_type BLOB DEFAULT '' NOT NULL, log_action BLOB DEFAULT '' NOT NULL,
  log_timestamp BLOB DEFAULT '19700101000000' NOT NULL,
  log_actor INTEGER  NOT NULL,
  log_namespace INTEGER DEFAULT 0 NOT NULL,
  log_title BLOB DEFAULT '' NOT NULL,
  log_page INTEGER  DEFAULT NULL,
  log_comment_id INTEGER  NOT NULL,
  log_params BLOB NOT NULL, log_deleted INTEGER  DEFAULT 0 NOT NULL
);
CREATE INDEX log_type_time ON /*_*/logging (log_type, log_timestamp);
CREATE INDEX log_actor_time ON /*_*/logging (log_actor, log_timestamp);
CREATE INDEX log_page_time ON /*_*/logging (
  log_namespace, log_title, log_timestamp
);
CREATE INDEX log_times ON /*_*/logging (log_timestamp);
CREATE INDEX log_actor_type_time ON /*_*/logging (
  log_actor, log_type, log_timestamp
);
CREATE INDEX log_page_id_time ON /*_*/logging (log_page, log_timestamp);
CREATE INDEX log_type_action ON /*_*/logging (
  log_type, log_action, log_timestamp
);

CREATE TABLE /*_*/uploadstash (
  us_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  us_user INTEGER  NOT NULL,
  us_key TEXT NOT NULL,
  us_orig_path TEXT NOT NULL,
  us_path TEXT NOT NULL,
  us_source_type TEXT DEFAULT NULL,
  us_timestamp BLOB NOT NULL,
  us_status TEXT NOT NULL,
  us_chunk_inx INTEGER  DEFAULT NULL,
  us_props BLOB DEFAULT NULL,
  us_size INTEGER  NOT NULL,
  us_sha1 TEXT NOT NULL,
  us_mime TEXT DEFAULT NULL,
  us_media_type TEXT DEFAULT NULL,
  us_image_width INTEGER  DEFAULT NULL,
  us_image_height INTEGER  DEFAULT NULL,
  us_image_bits INTEGER  DEFAULT NULL
);
CREATE INDEX us_user ON /*_*/uploadstash (us_user);
CREATE UNIQUE INDEX us_key ON /*_*/uploadstash (us_key);
CREATE INDEX us_timestamp ON /*_*/uploadstash (us_timestamp);

CREATE TABLE /*_*/filearchive (
  fa_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  fa_name BLOB DEFAULT '' NOT NULL, fa_archive_name BLOB DEFAULT '',
  fa_storage_group BLOB DEFAULT NULL,
  fa_storage_key BLOB DEFAULT '', fa_deleted_user INTEGER DEFAULT NULL,
  fa_deleted_timestamp BLOB DEFAULT NULL,
  fa_deleted_reason_id INTEGER  NOT NULL,
  fa_size INTEGER  DEFAULT 0,
  fa_width INTEGER DEFAULT 0, fa_height INTEGER DEFAULT 0,
  fa_metadata BLOB DEFAULT NULL, fa_bits INTEGER DEFAULT 0,
  fa_media_type TEXT DEFAULT NULL, fa_major_mime TEXT DEFAULT 'unknown',
  fa_minor_mime BLOB DEFAULT 'unknown',
  fa_description_id INTEGER  NOT NULL,
  fa_actor INTEGER  NOT NULL,
  fa_timestamp BLOB DEFAULT NULL, fa_deleted INTEGER  DEFAULT 0 NOT NULL,
  fa_sha1 BLOB DEFAULT '' NOT NULL
);
CREATE INDEX fa_name ON /*_*/filearchive (fa_name, fa_timestamp);
CREATE INDEX fa_storage_group ON /*_*/filearchive (
  fa_storage_group, fa_storage_key
);
CREATE INDEX fa_deleted_timestamp ON /*_*/filearchive (fa_deleted_timestamp);
CREATE INDEX fa_actor_timestamp ON /*_*/filearchive (fa_actor, fa_timestamp);
CREATE INDEX fa_sha1 ON /*_*/filearchive (fa_sha1);

CREATE TABLE /*_*/text (
  old_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  old_text BLOB NOT NULL, old_flags BLOB NOT NULL
);

CREATE TABLE /*_*/oldimage (
  oi_name BLOB DEFAULT '' NOT NULL, oi_archive_name BLOB DEFAULT '' NOT NULL,
  oi_size INTEGER  DEFAULT 0 NOT NULL,
  oi_width INTEGER DEFAULT 0 NOT NULL,
  oi_height INTEGER DEFAULT 0 NOT NULL,
  oi_bits INTEGER DEFAULT 0 NOT NULL,
  oi_description_id INTEGER  NOT NULL,
  oi_actor INTEGER  NOT NULL,
  oi_timestamp BLOB NOT NULL, oi_metadata BLOB NOT NULL,
  oi_media_type TEXT DEFAULT NULL, oi_major_mime TEXT DEFAULT 'unknown' NOT NULL,
  oi_minor_mime BLOB DEFAULT 'unknown' NOT NULL,
  oi_deleted INTEGER  DEFAULT 0 NOT NULL,
  oi_sha1 BLOB DEFAULT '' NOT NULL
);
CREATE INDEX oi_actor_timestamp ON /*_*/oldimage (oi_actor, oi_timestamp);
CREATE INDEX oi_name_timestamp ON /*_*/oldimage (oi_name, oi_timestamp);
CREATE INDEX oi_name_archive_name ON /*_*/oldimage (oi_name, oi_archive_name);
CREATE INDEX oi_sha1 ON /*_*/oldimage (oi_sha1);

CREATE TABLE /*_*/objectcache (
  keyname BLOB DEFAULT '' NOT NULL,
  value BLOB DEFAULT NULL,
  exptime BLOB NOT NULL,
  PRIMARY KEY(keyname)
);
CREATE INDEX exptime ON /*_*/objectcache (exptime);

CREATE TABLE /*_*/ipblocks (
  ipb_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  ipb_address BLOB NOT NULL, ipb_user INTEGER  DEFAULT 0 NOT NULL,
  ipb_by_actor INTEGER  NOT NULL,
  ipb_reason_id INTEGER  NOT NULL,
  ipb_timestamp BLOB NOT NULL, ipb_auto INTEGER DEFAULT 0 NOT NULL,
  ipb_anon_only INTEGER DEFAULT 0 NOT NULL,
  ipb_create_account INTEGER DEFAULT 1 NOT NULL,
  ipb_enable_autoblock INTEGER DEFAULT 1 NOT NULL,
  ipb_expiry BLOB NOT NULL, ipb_range_start BLOB NOT NULL,
  ipb_range_end BLOB NOT NULL, ipb_deleted INTEGER DEFAULT 0 NOT NULL,
  ipb_block_email INTEGER DEFAULT 0 NOT NULL,
  ipb_allow_usertalk INTEGER DEFAULT 0 NOT NULL,
  ipb_parent_block_id INTEGER DEFAULT NULL,
  ipb_sitewide INTEGER DEFAULT 1 NOT NULL
);
CREATE UNIQUE INDEX ipb_address_unique ON /*_*/ipblocks (ipb_address, ipb_user, ipb_auto);
CREATE INDEX ipb_user ON /*_*/ipblocks (ipb_user);
CREATE INDEX ipb_range ON /*_*/ipblocks (ipb_range_start, ipb_range_end);
CREATE INDEX ipb_timestamp ON /*_*/ipblocks (ipb_timestamp);
CREATE INDEX ipb_expiry ON /*_*/ipblocks (ipb_expiry);
CREATE INDEX ipb_parent_block_id ON /*_*/ipblocks (ipb_parent_block_id);

CREATE TABLE /*_*/image (
  img_name BLOB DEFAULT '' NOT NULL,
  img_size INTEGER  DEFAULT 0 NOT NULL,
  img_width INTEGER DEFAULT 0 NOT NULL,
  img_height INTEGER DEFAULT 0 NOT NULL,
  img_metadata BLOB NOT NULL,
  img_bits INTEGER DEFAULT 0 NOT NULL,
  img_media_type TEXT DEFAULT NULL,
  img_major_mime TEXT DEFAULT 'unknown' NOT NULL,
  img_minor_mime BLOB DEFAULT 'unknown' NOT NULL,
  img_description_id INTEGER  NOT NULL,
  img_actor INTEGER  NOT NULL,
  img_timestamp BLOB NOT NULL,
  img_sha1 BLOB DEFAULT '' NOT NULL,
  PRIMARY KEY(img_name)
);
CREATE INDEX img_actor_timestamp ON /*_*/image (img_actor, img_timestamp);
CREATE INDEX img_size ON /*_*/image (img_size);
CREATE INDEX img_timestamp ON /*_*/image (img_timestamp);
CREATE INDEX img_sha1 ON /*_*/image (img_sha1);
CREATE INDEX img_media_mime ON /*_*/image (
  img_media_type, img_major_mime, img_minor_mime
);

CREATE TABLE /*_*/recentchanges (
  rc_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  rc_timestamp BLOB NOT NULL, rc_actor INTEGER  NOT NULL,
  rc_namespace INTEGER DEFAULT 0 NOT NULL,
  rc_title BLOB DEFAULT '' NOT NULL, rc_comment_id INTEGER  NOT NULL,
  rc_minor INTEGER  DEFAULT 0 NOT NULL,
  rc_bot INTEGER  DEFAULT 0 NOT NULL,
  rc_new INTEGER  DEFAULT 0 NOT NULL,
  rc_cur_id INTEGER  DEFAULT 0 NOT NULL,
  rc_this_oldid INTEGER  DEFAULT 0 NOT NULL,
  rc_last_oldid INTEGER  DEFAULT 0 NOT NULL,
  rc_type INTEGER  DEFAULT 0 NOT NULL,
  rc_source BLOB DEFAULT '' NOT NULL,
  rc_patrolled INTEGER  DEFAULT 0 NOT NULL,
  rc_ip BLOB DEFAULT '' NOT NULL, rc_old_len INTEGER DEFAULT NULL,
  rc_new_len INTEGER DEFAULT NULL, rc_deleted INTEGER  DEFAULT 0 NOT NULL,
  rc_logid INTEGER  DEFAULT 0 NOT NULL,
  rc_log_type BLOB DEFAULT NULL, rc_log_action BLOB DEFAULT NULL,
  rc_params BLOB DEFAULT NULL
);
CREATE INDEX rc_timestamp ON /*_*/recentchanges (rc_timestamp);
CREATE INDEX rc_namespace_title_timestamp ON /*_*/recentchanges (
  rc_namespace, rc_title, rc_timestamp
);
CREATE INDEX rc_cur_id ON /*_*/recentchanges (rc_cur_id);
CREATE INDEX rc_new_name_timestamp ON /*_*/recentchanges (
  rc_new, rc_namespace, rc_timestamp
);
CREATE INDEX rc_ip ON /*_*/recentchanges (rc_ip);
CREATE INDEX rc_ns_actor ON /*_*/recentchanges (rc_namespace, rc_actor);
CREATE INDEX rc_actor ON /*_*/recentchanges (rc_actor, rc_timestamp);
CREATE INDEX rc_name_type_patrolled_timestamp ON /*_*/recentchanges (
  rc_namespace, rc_type, rc_patrolled,
  rc_timestamp
);
CREATE INDEX rc_this_oldid ON /*_*/recentchanges (rc_this_oldid);

CREATE TABLE /*_*/archive (
  ar_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  ar_namespace INTEGER DEFAULT 0 NOT NULL,
  ar_title BLOB DEFAULT '' NOT NULL, ar_comment_id INTEGER  NOT NULL,
  ar_actor INTEGER  NOT NULL,
  ar_timestamp BLOB NOT NULL, ar_minor_edit INTEGER DEFAULT 0 NOT NULL,
  ar_rev_id INTEGER  NOT NULL,
  ar_deleted INTEGER  DEFAULT 0 NOT NULL,
  ar_len INTEGER  DEFAULT NULL,
  ar_page_id INTEGER  DEFAULT NULL,
  ar_parent_id INTEGER  DEFAULT NULL,
  ar_sha1 BLOB DEFAULT '' NOT NULL
);
CREATE INDEX ar_name_title_timestamp ON /*_*/archive (
  ar_namespace, ar_title, ar_timestamp
);
CREATE INDEX ar_actor_timestamp ON /*_*/archive (ar_actor, ar_timestamp);
CREATE UNIQUE INDEX ar_revid_uniq ON /*_*/archive (ar_rev_id);

CREATE TABLE /*_*/page (
  page_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  page_namespace INTEGER NOT NULL, page_title BLOB NOT NULL,
  page_restrictions BLOB DEFAULT NULL,
  page_is_redirect INTEGER  DEFAULT 0 NOT NULL,
  page_is_new INTEGER  DEFAULT 0 NOT NULL,
  page_random REAL NOT NULL,
  page_touched BLOB NOT NULL, page_links_updated BLOB DEFAULT NULL,
  page_latest INTEGER  NOT NULL,
  page_len INTEGER  NOT NULL,
  page_content_model BLOB DEFAULT NULL,
  page_lang BLOB DEFAULT NULL
);
CREATE UNIQUE INDEX name_title ON /*_*/page (page_namespace, page_title);
CREATE INDEX page_random ON /*_*/page (page_random);
CREATE INDEX page_len ON /*_*/page (page_len);
CREATE INDEX page_redirect_namespace_len ON /*_*/page (
  page_is_redirect, page_namespace,
  page_len
);
CREATE TABLE /*_*/user (
  user_id INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
  user_name BLOB NOT NULL default '',
  user_real_name BLOB NOT NULL default '',
  user_password BLOB NOT NULL,
  user_newpassword BLOB NOT NULL,
  user_newpass_time BLOB,
  user_email TEXT NOT NULL,
  user_touched BLOB NOT NULL,
  user_token BLOB NOT NULL default '',
  user_email_authenticated BLOB,
  user_email_token BLOB,
  user_email_token_expires BLOB,
  user_registration BLOB,
  user_editcount INTEGER,
  user_password_expires BLOB DEFAULT NULL
) /*$wgDBTableOptions*/;
CREATE UNIQUE INDEX /*i*/user_name ON /*_*/user (user_name);
CREATE INDEX /*i*/user_email_token ON /*_*/user (user_email_token);
CREATE INDEX /*i*/user_email ON /*_*/user (user_email);
  CREATE TABLE /*_*/revision (
  rev_id INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
  rev_page INTEGER  NOT NULL,
  rev_comment_id INTEGER  NOT NULL default 0,
  rev_actor INTEGER  NOT NULL default 0,
  rev_timestamp BLOB NOT NULL default '',
  rev_minor_edit INTEGER  NOT NULL default 0,
  rev_deleted INTEGER  NOT NULL default 0,
  rev_len INTEGER ,
  rev_parent_id INTEGER  default NULL,
  rev_sha1 BLOB NOT NULL default ''
) /*$wgDBTableOptions*/;

CREATE INDEX /*i*/rev_page_id ON /*_*/revision (rev_page, rev_id);
CREATE INDEX /*i*/rev_timestamp ON /*_*/revision (rev_timestamp);
CREATE INDEX /*i*/page_timestamp ON /*_*/revision (rev_page,rev_timestamp);
CREATE INDEX /*i*/rev_actor_timestamp ON /*_*/revision (rev_actor,rev_timestamp,rev_id);
CREATE INDEX /*i*/rev_page_actor_timestamp ON /*_*/revision (rev_page,rev_actor,rev_timestamp);

CREATE TABLE /*_*/searchindex (
  si_page INTEGER  NOT NULL,
  si_title TEXT NOT NULL default '',
  si_text TEXT NOT NULL
);
CREATE UNIQUE INDEX /*i*/si_page ON /*_*/searchindex (si_page);
CREATE INDEX /*i*/si_title ON /*_*/searchindex (si_title);
CREATE INDEX /*i*/si_text ON /*_*/searchindex (si_text);
