-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: extensions/CheckUser/schema/tables.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE cu_changes (
  cuc_id SERIAL NOT NULL,
  cuc_namespace INT DEFAULT 0 NOT NULL,
  cuc_title TEXT DEFAULT '' NOT NULL,
  cuc_user INT DEFAULT 0 NOT NULL,
  cuc_user_text VARCHAR(255) DEFAULT '' NOT NULL,
  cuc_actor BIGINT DEFAULT 0 NOT NULL,
  cuc_actiontext TEXT DEFAULT '' NOT NULL,
  cuc_comment TEXT DEFAULT '' NOT NULL,
  cuc_comment_id BIGINT DEFAULT 0 NOT NULL,
  cuc_minor SMALLINT DEFAULT 0 NOT NULL,
  cuc_page_id INT DEFAULT 0 NOT NULL,
  cuc_this_oldid INT DEFAULT 0 NOT NULL,
  cuc_last_oldid INT DEFAULT 0 NOT NULL,
  cuc_type SMALLINT DEFAULT 0 NOT NULL,
  cuc_timestamp TIMESTAMPTZ NOT NULL,
  cuc_ip VARCHAR(255) DEFAULT '',
  cuc_ip_hex VARCHAR(255) DEFAULT NULL,
  cuc_xff TEXT DEFAULT '',
  cuc_xff_hex VARCHAR(255) DEFAULT NULL,
  cuc_agent TEXT DEFAULT NULL,
  cuc_private TEXT DEFAULT NULL,
  PRIMARY KEY(cuc_id)
);

CREATE INDEX cuc_ip_hex_time ON cu_changes (cuc_ip_hex, cuc_timestamp);

CREATE INDEX cuc_user_ip_time ON cu_changes (cuc_user, cuc_ip, cuc_timestamp);

CREATE INDEX cuc_xff_hex_time ON cu_changes (cuc_xff_hex, cuc_timestamp);

CREATE INDEX cuc_timestamp ON cu_changes (cuc_timestamp);

CREATE INDEX cuc_actor_ip_time ON cu_changes (cuc_actor, cuc_ip, cuc_timestamp);


CREATE TABLE cu_log (
  cul_id SERIAL NOT NULL,
  cul_timestamp TIMESTAMPTZ NOT NULL,
  cul_user INT NOT NULL,
  cul_user_text TEXT NOT NULL,
  cul_actor BIGINT DEFAULT 0 NOT NULL,
  cul_reason TEXT NOT NULL,
  cul_reason_id BIGINT DEFAULT 0 NOT NULL,
  cul_reason_plaintext_id BIGINT DEFAULT 0 NOT NULL,
  cul_type TEXT NOT NULL,
  cul_target_id INT DEFAULT 0 NOT NULL,
  cul_target_text TEXT NOT NULL,
  cul_target_hex TEXT DEFAULT '' NOT NULL,
  cul_range_start TEXT DEFAULT '' NOT NULL,
  cul_range_end TEXT DEFAULT '' NOT NULL,
  PRIMARY KEY(cul_id)
);

CREATE INDEX cul_user ON cu_log (cul_user, cul_timestamp);

CREATE INDEX cul_actor_time ON cu_log (cul_actor, cul_timestamp);

CREATE INDEX cul_type_target ON cu_log (
  cul_type, cul_target_id, cul_timestamp
);

CREATE INDEX cul_target_hex ON cu_log (cul_target_hex, cul_timestamp);

CREATE INDEX cul_range_start ON cu_log (cul_range_start, cul_timestamp);

CREATE INDEX cul_timestamp ON cu_log (cul_timestamp);
