-- 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 SERIAL NOT NULL,
  nl_name VARCHAR(64) NOT NULL,
  nl_desc TEXT DEFAULT NULL,
  nl_main_page_id INT NOT NULL,
  nl_active SMALLINT DEFAULT 1 NOT NULL,
  nl_subscriber_count INT DEFAULT 0 NOT NULL,
  PRIMARY KEY(nl_id)
);

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 INT NOT NULL,
  nli_newsletter_id INT NOT NULL,
  nli_page_id INT NOT NULL,
  nli_publisher_id INT NOT NULL,
  PRIMARY KEY(nli_newsletter_id, nli_issue_id)
);


CREATE TABLE nl_subscriptions (
  nls_newsletter_id INT NOT NULL,
  nls_subscriber_id INT 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 INT NOT NULL,
  nlp_publisher_id INT NOT NULL,
  PRIMARY KEY(
    nlp_publisher_id, nlp_newsletter_id
  )
);

CREATE INDEX nlp_nl_id ON nl_publishers (nlp_newsletter_id);
