create table if not exists users(
    id serial primary key,
    username varchar(16) not null unique,
    hash varchar(128) not null
);

create table if not exists boards(
    id serial primary key,
    name varchar(32) not null,
    description varchar(256)
);

create table if not exists categories(
    id serial primary key,
    name varchar(32) not null,
    board integer not null references boards(id) on delete cascade,
    unique(name, board)
);

create table if not exists tasks(
    id serial primary key,
    title varchar(128) not null,
    description varchar(32768) not null,
    author integer references users(id),
    category integer not null references categories(id) on delete cascade,
    created timestamp not null,
    deadline timestamp
);

create table if not exists task_assigned(
    id serial primary key,
    task integer references tasks(id) on delete cascade,
    member integer references users(id) on delete cascade
);

