-- Schema: bird__language_corpus
CREATE SCHEMA IF NOT EXISTS "bird__language_corpus";

-- Table: biwords
CREATE TABLE "bird__language_corpus"."biwords" (
    "lid" BIGINT NOT NULL,
    "w1st" BIGINT NOT NULL,
    "w2nd" BIGINT NOT NULL,
    "occurrences" BIGINT DEFAULT 0,
    CONSTRAINT "biwords_pkey" PRIMARY KEY ("lid", "w1st", "w2nd")
);

-- Table: langs
CREATE TABLE "bird__language_corpus"."langs" (
    "lid" BIGINT NOT NULL,
    "lang" TEXT,
    "locale" TEXT,
    "pages" BIGINT DEFAULT 0,
    "words" BIGINT DEFAULT 0,
    CONSTRAINT "langs_pkey" PRIMARY KEY ("lid"),
    CONSTRAINT "langs_lang_key" UNIQUE ("lang"),
    CONSTRAINT "langs_locale_key" UNIQUE ("locale")
);

-- Table: langs_words
CREATE TABLE "bird__language_corpus"."langs_words" (
    "lid" BIGINT NOT NULL,
    "wid" BIGINT NOT NULL,
    "occurrences" BIGINT,
    CONSTRAINT "langs_words_pkey" PRIMARY KEY ("lid", "wid")
);

-- Table: pages
CREATE TABLE "bird__language_corpus"."pages" (
    "pid" BIGINT NOT NULL,
    "lid" BIGINT,
    "page" BIGINT,
    "revision" BIGINT,
    "title" TEXT,
    "words" BIGINT DEFAULT 0,
    CONSTRAINT "pages_pkey" PRIMARY KEY ("pid"),
    CONSTRAINT "pages_lid_page_title_key" UNIQUE ("lid", "page", "title")
);

-- Table: pages_words
CREATE TABLE "bird__language_corpus"."pages_words" (
    "pid" BIGINT NOT NULL,
    "wid" BIGINT NOT NULL,
    "occurrences" BIGINT DEFAULT 0,
    CONSTRAINT "pages_words_pkey" PRIMARY KEY ("pid", "wid")
);

-- Table: words
CREATE TABLE "bird__language_corpus"."words" (
    "wid" BIGINT NOT NULL,
    "word" TEXT,
    "occurrences" BIGINT DEFAULT 0,
    CONSTRAINT "words_pkey" PRIMARY KEY ("wid")
);

-- Foreign Keys
ALTER TABLE "bird__language_corpus"."biwords" ADD CONSTRAINT "fk_biwords_0" FOREIGN KEY ("w2nd") REFERENCES "bird__language_corpus"."words" ("wid") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "bird__language_corpus"."biwords" ADD CONSTRAINT "fk_biwords_1" FOREIGN KEY ("w1st") REFERENCES "bird__language_corpus"."words" ("wid") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "bird__language_corpus"."biwords" ADD CONSTRAINT "fk_biwords_2" FOREIGN KEY ("lid") REFERENCES "bird__language_corpus"."langs" ("lid") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "bird__language_corpus"."langs_words" ADD CONSTRAINT "fk_langs_words_0" FOREIGN KEY ("wid") REFERENCES "bird__language_corpus"."words" ("wid") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "bird__language_corpus"."langs_words" ADD CONSTRAINT "fk_langs_words_1" FOREIGN KEY ("lid") REFERENCES "bird__language_corpus"."langs" ("lid") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "bird__language_corpus"."pages" ADD CONSTRAINT "fk_pages_0" FOREIGN KEY ("lid") REFERENCES "bird__language_corpus"."langs" ("lid") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "bird__language_corpus"."pages_words" ADD CONSTRAINT "fk_pages_words_0" FOREIGN KEY ("wid") REFERENCES "bird__language_corpus"."words" ("wid") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "bird__language_corpus"."pages_words" ADD CONSTRAINT "fk_pages_words_1" FOREIGN KEY ("pid") REFERENCES "bird__language_corpus"."pages" ("pid") ON DELETE CASCADE ON UPDATE CASCADE;
