-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: schema/tables.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE /*_*/oauth_registered_consumer (
  oarc_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  oarc_consumer_key BLOB NOT NULL, oarc_name BLOB NOT NULL,
  oarc_user_id INTEGER UNSIGNED NOT NULL,
  oarc_version BLOB NOT NULL, oarc_callback_url BLOB NOT NULL,
  oarc_callback_is_prefix BLOB DEFAULT NULL,
  oarc_description BLOB NOT NULL, oarc_email BLOB NOT NULL,
  oarc_email_authenticated BLOB DEFAULT NULL,
  oarc_developer_agreement SMALLINT DEFAULT 0 NOT NULL,
  oarc_owner_only SMALLINT DEFAULT 0 NOT NULL,
  oarc_wiki BLOB NOT NULL, oarc_grants BLOB NOT NULL,
  oarc_registration BLOB NOT NULL, oarc_secret_key BLOB DEFAULT NULL,
  oarc_rsa_key BLOB DEFAULT NULL, oarc_restrictions BLOB NOT NULL,
  oarc_stage SMALLINT UNSIGNED DEFAULT 0 NOT NULL,
  oarc_stage_timestamp BLOB NOT NULL,
  oarc_deleted SMALLINT UNSIGNED DEFAULT 0 NOT NULL,
  oarc_oauth_version SMALLINT DEFAULT 1 NOT NULL,
  oarc_oauth2_allowed_grants BLOB DEFAULT NULL,
  oarc_oauth2_is_confidential SMALLINT DEFAULT 1 NOT NULL
);

CREATE UNIQUE INDEX oarc_consumer_key ON /*_*/oauth_registered_consumer (oarc_consumer_key);

CREATE UNIQUE INDEX oarc_name_version_user ON /*_*/oauth_registered_consumer (
  oarc_name, oarc_user_id, oarc_version
);

CREATE INDEX oarc_user_id ON /*_*/oauth_registered_consumer (oarc_user_id);

CREATE INDEX oarc_stage_timestamp ON /*_*/oauth_registered_consumer (
  oarc_stage, oarc_stage_timestamp
);


CREATE TABLE /*_*/oauth_accepted_consumer (
  oaac_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  oaac_wiki BLOB NOT NULL, oaac_user_id INTEGER UNSIGNED NOT NULL,
  oaac_consumer_id INTEGER UNSIGNED NOT NULL,
  oaac_access_token BLOB NOT NULL, oaac_access_secret BLOB NOT NULL,
  oaac_grants BLOB NOT NULL, oaac_accepted BLOB NOT NULL,
  oaac_oauth_version SMALLINT DEFAULT 1 NOT NULL
);

CREATE UNIQUE INDEX oaac_access_token ON /*_*/oauth_accepted_consumer (oaac_access_token);

CREATE UNIQUE INDEX oaac_user_consumer_wiki ON /*_*/oauth_accepted_consumer (
  oaac_user_id, oaac_consumer_id, oaac_wiki
);

CREATE INDEX oaac_consumer_user ON /*_*/oauth_accepted_consumer (oaac_consumer_id, oaac_user_id);

CREATE INDEX oaac_user_id ON /*_*/oauth_accepted_consumer (oaac_user_id, oaac_id);


CREATE TABLE /*_*/oauth2_access_tokens (
  oaat_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  oaat_identifier VARCHAR(255) NOT NULL,
  oaat_expires BLOB NOT NULL,
  oaat_acceptance_id INTEGER UNSIGNED NOT NULL,
  oaat_revoked SMALLINT DEFAULT 0 NOT NULL
);

CREATE UNIQUE INDEX oaat_identifier ON /*_*/oauth2_access_tokens (oaat_identifier);

CREATE INDEX oaat_acceptance_id ON /*_*/oauth2_access_tokens (oaat_acceptance_id);
