-- This file is auto-generated by the migration script
-- for reference purposes only. DO NOT EDIT.

CREATE TABLE title (
    id text,
    name text,
    site text,
    cover_ext text,
    chapters text,
    alt_names text,
    descriptions text,
    updated_at text default (datetime('now')), is_webtoon boolean not null default false, descriptions_format text not null default 'text',

    unique(id, site)
);
CREATE TABLE user (
    id integer primary key,
    username text unique,
    password text,
    created_at text default (datetime('now'))
);
CREATE TABLE follow (
    user_id integer not null,
    title_id text not null,
    site text not null,
    created_at text default (datetime('now')),

    foreign key (title_id, site) references title (id, site),
    foreign key (user_id) references user (id),
    unique(user_id, title_id, site)
);
CREATE TABLE keyval_store (
    key text primary key,
    value text not null,
    updated_at text default (datetime('now'))
);
CREATE TABLE token (
    user_id integer not null,
    token text unique not null,
    created_at text not null default (datetime('now')),
    last_accessed_at text not null default (datetime('now')),
    lifespan text not null, -- '+1 day', '+365 days', etc.

    foreign key (user_id) references user (id)
);
CREATE TABLE IF NOT EXISTS "read" (
    user_id integer not null,
    site text not null,
    title_id text, -- nullable to accomodate existing mangadex rows, urgh.
    chapter_id text not null,
    updated_at text default (datetime('now')),

    foreign key (user_id) references user (id),
    unique(user_id, site, title_id, chapter_id)
);
CREATE TABLE IF NOT EXISTS "chapter" (
    id text,
    title_id text,
    site text,
    num_major integer,
    num_minor integer,
    name text,
    pages text,
    groups text,
    updated_at text default (datetime('now')),
    pages_alt text not null default '[]',
    foreign key (title_id, site) references title (id, site),
    unique(site, title_id, id)
);
