CREATE TABLE configs(
    id SERIAL PRIMARY KEY,
    active BOOLEAN NOT NULL,
    name TEXT NOT NULL,
    description TEXT NOT NULL,
    copyright TEXT NOT NULL,
    owner_name TEXT NOT NULL,
    owner_email TEXT NOT NULL,
    owner_website TEXT
);

CREATE UNIQUE INDEX configs_active ON configs(active)
WHERE
    active;

INSERT INTO
    configs(
        active,
        name,
        description,
        copyright,
        owner_name,
        owner_email
    )
VALUES
    (
        TRUE,
        'generic blog',
        'just a generic blog',
        '(C) just a generic blog',
        'generic blog owner',
        'blog@example.com'
    );

CREATE TABLE tags(
    id SERIAL PRIMARY KEY,
    name TEXT UNIQUE NOT NULL
);

CREATE TABLE posts(
    id SERIAL PRIMARY KEY,
    name TEXT NOT NULL,
    slug TEXT UNIQUE NOT NULL,
    description TEXT NOT NULL,
    content TEXT NOT NULL,
    published_at DATE NOT NULL,
    edited_at DATE,
    active BOOLEAN NOT NULL
);
