-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
-- Source: sql/abstractSchemaChanges/patch-imagelinks-add-il_target_id.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TEMPORARY TABLE /*_*/__temp__imagelinks AS
SELECT
  il_from,
  il_to,
  il_from_namespace
FROM /*_*/imagelinks;

DROP TABLE /*_*/imagelinks;


CREATE TABLE /*_*/imagelinks (
  il_from INTEGER UNSIGNED DEFAULT 0 NOT NULL,
  il_to BLOB DEFAULT '' NOT NULL,
  il_from_namespace INTEGER DEFAULT 0 NOT NULL,
  il_target_id BIGINT UNSIGNED DEFAULT NULL,
  PRIMARY KEY(il_from, il_to)
);

INSERT INTO /*_*/imagelinks (
  il_from, il_to, il_from_namespace
)
SELECT
  il_from,
  il_to,
  il_from_namespace
FROM
  /*_*/__temp__imagelinks;

DROP TABLE /*_*/__temp__imagelinks;

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 INDEX il_target_id ON /*_*/imagelinks (il_target_id, il_from);

CREATE INDEX il_backlinks_namespace_target_id ON /*_*/imagelinks (
  il_from_namespace, il_target_id,
  il_from
);
