-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: sql/tables.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE /*_*/flow_workflow (
  workflow_id BLOB NOT NULL,
  workflow_wiki BLOB NOT NULL,
  workflow_namespace INTEGER NOT NULL,
  workflow_page_id INTEGER UNSIGNED NOT NULL,
  workflow_title_text BLOB NOT NULL,
  workflow_name BLOB NOT NULL,
  workflow_last_update_timestamp BLOB NOT NULL,
  workflow_lock_state INTEGER UNSIGNED NOT NULL,
  workflow_type BLOB NOT NULL,
  PRIMARY KEY(workflow_id)
);

CREATE INDEX flow_workflow_lookup ON /*_*/flow_workflow (
  workflow_wiki, workflow_namespace,
  workflow_title_text
);

CREATE INDEX flow_workflow_update_timestamp ON /*_*/flow_workflow (workflow_last_update_timestamp);


CREATE TABLE /*_*/flow_topic_list (
  topic_list_id BLOB NOT NULL,
  topic_id BLOB NOT NULL,
  PRIMARY KEY(topic_list_id, topic_id)
);

CREATE INDEX flow_topic_list_topic_id ON /*_*/flow_topic_list (topic_id);


CREATE TABLE /*_*/flow_tree_revision (
  tree_rev_id BLOB NOT NULL,
  tree_rev_descendant_id BLOB NOT NULL,
  tree_orig_user_id BIGINT UNSIGNED NOT NULL,
  tree_orig_user_ip BLOB DEFAULT NULL,
  tree_orig_user_wiki BLOB NOT NULL,
  tree_parent_id BLOB DEFAULT NULL,
  PRIMARY KEY(tree_rev_id)
);

CREATE INDEX flow_tree_descendant_rev_id ON /*_*/flow_tree_revision (
  tree_rev_descendant_id, tree_rev_id
);


CREATE TABLE /*_*/flow_revision (
  rev_id BLOB NOT NULL,
  rev_type BLOB NOT NULL,
  rev_type_id BLOB DEFAULT '' NOT NULL,
  rev_user_id BIGINT UNSIGNED NOT NULL,
  rev_user_ip BLOB DEFAULT NULL,
  rev_user_wiki BLOB NOT NULL,
  rev_parent_id BLOB DEFAULT NULL,
  rev_flags BLOB NOT NULL,
  rev_content BLOB NOT NULL,
  rev_change_type BLOB DEFAULT NULL,
  rev_mod_state BLOB NOT NULL,
  rev_mod_user_id BIGINT UNSIGNED DEFAULT NULL,
  rev_mod_user_ip BLOB DEFAULT NULL,
  rev_mod_user_wiki BLOB DEFAULT NULL,
  rev_mod_timestamp BLOB DEFAULT NULL,
  rev_mod_reason BLOB DEFAULT NULL,
  rev_last_edit_id BLOB DEFAULT NULL,
  rev_edit_user_id BIGINT UNSIGNED DEFAULT NULL,
  rev_edit_user_ip BLOB DEFAULT NULL,
  rev_edit_user_wiki BLOB DEFAULT NULL,
  rev_content_length INTEGER DEFAULT 0 NOT NULL,
  rev_previous_content_length INTEGER DEFAULT 0 NOT NULL,
  PRIMARY KEY(rev_id)
);

CREATE UNIQUE INDEX flow_revision_unique_parent ON /*_*/flow_revision (rev_parent_id);

CREATE INDEX flow_revision_type_id ON /*_*/flow_revision (rev_type, rev_type_id);

CREATE INDEX flow_revision_user ON /*_*/flow_revision (
  rev_user_id, rev_user_ip, rev_user_wiki
);


CREATE TABLE /*_*/flow_tree_node (
  tree_ancestor_id BLOB NOT NULL,
  tree_descendant_id BLOB NOT NULL,
  tree_depth SMALLINT NOT NULL,
  PRIMARY KEY(
    tree_ancestor_id, tree_descendant_id
  )
);

CREATE UNIQUE INDEX flow_tree_constraint ON /*_*/flow_tree_node (tree_descendant_id, tree_depth);


CREATE TABLE /*_*/flow_wiki_ref (
  ref_id BLOB NOT NULL,
  ref_src_wiki BLOB NOT NULL,
  ref_src_object_id BLOB NOT NULL,
  ref_src_object_type BLOB NOT NULL,
  ref_src_workflow_id BLOB NOT NULL,
  ref_src_namespace INTEGER NOT NULL,
  ref_src_title BLOB NOT NULL,
  ref_target_namespace INTEGER NOT NULL,
  ref_target_title BLOB NOT NULL,
  ref_type BLOB NOT NULL,
  PRIMARY KEY(ref_id)
);

CREATE INDEX flow_wiki_ref_idx_v2 ON /*_*/flow_wiki_ref (
  ref_src_wiki, ref_src_namespace,
  ref_src_title, ref_type, ref_target_namespace,
  ref_target_title, ref_src_object_type,
  ref_src_object_id
);

CREATE INDEX flow_wiki_ref_revision_v2 ON /*_*/flow_wiki_ref (
  ref_src_wiki, ref_src_namespace,
  ref_src_title, ref_src_object_type,
  ref_src_object_id, ref_type, ref_target_namespace,
  ref_target_title
);


CREATE TABLE /*_*/flow_ext_ref (
  ref_id BLOB NOT NULL,
  ref_src_wiki BLOB NOT NULL,
  ref_src_object_id BLOB NOT NULL,
  ref_src_object_type BLOB NOT NULL,
  ref_src_workflow_id BLOB NOT NULL,
  ref_src_namespace INTEGER NOT NULL,
  ref_src_title BLOB NOT NULL,
  ref_target BLOB NOT NULL,
  ref_type BLOB NOT NULL,
  PRIMARY KEY(ref_id)
);

CREATE INDEX flow_ext_ref_idx_v3 ON /*_*/flow_ext_ref (
  ref_src_wiki, ref_src_namespace,
  ref_src_title, ref_type, ref_target,
  ref_src_object_type, ref_src_object_id
);

CREATE INDEX flow_ext_ref_revision_v2 ON /*_*/flow_ext_ref (
  ref_src_wiki, ref_src_namespace,
  ref_src_title, ref_src_object_type,
  ref_src_object_id, ref_type, ref_target
);
