-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: backend/schema/tables.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE /*_*/flaggedpages (
  fp_page_id INTEGER UNSIGNED NOT NULL,
  fp_reviewed SMALLINT DEFAULT 0 NOT NULL,
  fp_pending_since BLOB DEFAULT NULL,
  fp_stable INTEGER UNSIGNED NOT NULL,
  fp_quality SMALLINT DEFAULT NULL,
  PRIMARY KEY(fp_page_id)
);

CREATE INDEX fp_reviewed_page ON /*_*/flaggedpages (fp_reviewed, fp_page_id);

CREATE INDEX fp_quality_page ON /*_*/flaggedpages (fp_quality, fp_page_id);

CREATE INDEX fp_pending_since ON /*_*/flaggedpages (fp_pending_since);


CREATE TABLE /*_*/flaggedpage_pending (
  fpp_page_id INTEGER UNSIGNED NOT NULL,
  fpp_quality SMALLINT NOT NULL,
  fpp_rev_id INTEGER UNSIGNED NOT NULL,
  fpp_pending_since BLOB NOT NULL,
  PRIMARY KEY(fpp_page_id, fpp_quality)
);

CREATE INDEX fpp_quality_pending ON /*_*/flaggedpage_pending (fpp_quality, fpp_pending_since);


CREATE TABLE /*_*/flaggedrevs (
  fr_rev_id INTEGER UNSIGNED NOT NULL,
  fr_rev_timestamp BLOB NOT NULL,
  fr_page_id INTEGER UNSIGNED NOT NULL,
  fr_user INTEGER UNSIGNED NOT NULL,
  fr_timestamp BLOB NOT NULL,
  fr_quality SMALLINT DEFAULT 0 NOT NULL,
  fr_tags BLOB NOT NULL,
  fr_flags BLOB NOT NULL,
  PRIMARY KEY(fr_rev_id)
);

CREATE INDEX fr_page_rev ON /*_*/flaggedrevs (fr_page_id, fr_rev_id);

CREATE INDEX fr_page_time ON /*_*/flaggedrevs (fr_page_id, fr_rev_timestamp);

CREATE INDEX fr_page_qal_rev ON /*_*/flaggedrevs (
  fr_page_id, fr_quality, fr_rev_id
);

CREATE INDEX fr_page_qal_time ON /*_*/flaggedrevs (
  fr_page_id, fr_quality, fr_rev_timestamp
);

CREATE INDEX fr_user ON /*_*/flaggedrevs (fr_user);


CREATE TABLE /*_*/flaggedpage_config (
  fpc_page_id INTEGER UNSIGNED NOT NULL,
  fpc_override SMALLINT NOT NULL,
  fpc_level BLOB DEFAULT NULL,
  fpc_expiry BLOB NOT NULL,
  PRIMARY KEY(fpc_page_id)
);

CREATE INDEX fpc_expiry ON /*_*/flaggedpage_config (fpc_expiry);


CREATE TABLE /*_*/flaggedrevs_tracking (
  ftr_from INTEGER UNSIGNED DEFAULT 0 NOT NULL,
  ftr_namespace INTEGER DEFAULT 0 NOT NULL,
  ftr_title BLOB DEFAULT '' NOT NULL,
  PRIMARY KEY(
    ftr_from, ftr_namespace, ftr_title
  )
);

CREATE INDEX frt_namespace_title_from ON /*_*/flaggedrevs_tracking (
  ftr_namespace, ftr_title, ftr_from
);


CREATE TABLE /*_*/flaggedrevs_promote (
  frp_user_id INTEGER UNSIGNED NOT NULL,
  frp_user_params BLOB NOT NULL,
  PRIMARY KEY(frp_user_id)
);


CREATE TABLE /*_*/flaggedrevs_statistics (
  frs_timestamp BLOB NOT NULL,
  frs_stat_key VARCHAR(255) NOT NULL,
  frs_stat_val BIGINT NOT NULL,
  PRIMARY KEY(frs_stat_key, frs_timestamp)
);

CREATE INDEX frs_timestamp ON /*_*/flaggedrevs_statistics (frs_timestamp);
