-- 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 /*_*/nl_newsletters (
  nl_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  nl_name VARCHAR(64) NOT NULL,
  nl_desc BLOB DEFAULT NULL,
  nl_main_page_id INTEGER UNSIGNED NOT NULL,
  nl_active SMALLINT DEFAULT 1 NOT NULL,
  nl_subscriber_count INTEGER DEFAULT 0 NOT NULL
);

CREATE INDEX nl_name ON /*_*/nl_newsletters (nl_name);

CREATE INDEX nl_main_page_active ON /*_*/nl_newsletters (nl_main_page_id, nl_active);

CREATE INDEX nl_active ON /*_*/nl_newsletters (nl_active);

CREATE INDEX nl_active_subscriber_name ON /*_*/nl_newsletters (
  nl_active, nl_subscriber_count, nl_name
);


CREATE TABLE /*_*/nl_issues (
  nli_issue_id INTEGER UNSIGNED NOT NULL,
  nli_newsletter_id INTEGER NOT NULL,
  nli_page_id INTEGER NOT NULL,
  nli_publisher_id INTEGER NOT NULL,
  PRIMARY KEY(nli_newsletter_id, nli_issue_id)
);


CREATE TABLE /*_*/nl_subscriptions (
  nls_newsletter_id INTEGER NOT NULL,
  nls_subscriber_id INTEGER NOT NULL,
  PRIMARY KEY(
    nls_newsletter_id, nls_subscriber_id
  )
);

CREATE INDEX nls_subscriber_id ON /*_*/nl_subscriptions (nls_subscriber_id);


CREATE TABLE /*_*/nl_publishers (
  nlp_newsletter_id INTEGER UNSIGNED NOT NULL,
  nlp_publisher_id INTEGER NOT NULL,
  PRIMARY KEY(
    nlp_publisher_id, nlp_newsletter_id
  )
);

CREATE INDEX nlp_nl_id ON /*_*/nl_publishers (nlp_newsletter_id);
