create table if not exists projects
(
    id          integer primary key generated by default as identity,
    name        varchar    not null,
    description varchar,
    key         varchar(3) not null
);
insert into projects (name, key)
values ('madsky', 'MAD');

create table if not exists statuses
(
    id          integer primary key generated by default as identity,
    name        varchar           not null,
    description varchar,
    position    integer default 0 not null
);

insert into statuses (name)
values ('todo'),
       ('is working'),
       ('done');

create table if not exists issues
(
    id          integer primary key generated by default as identity,
    name        varchar                   not null,
    description varchar,
    position    integer     default 0     not null,
    created     timestamptz DEFAULT now() not null,
    status_id   integer                   not null,
    project_id  integer                   not null,
    foreign key (status_id) references statuses,
    foreign key (project_id) references projects
);

create table if not exists users
(
    id         integer primary key generated by default as identity,
    email      varchar not null unique,
    password   varchar,
    name       varchar,
    avatar     varchar,
    project_id integer,
    foreign key (project_id) references projects (id)
);
insert into users (email, password, name)
values ('admin@admin.ru', '1234', 'admin');

create table if not exists categories
(
    id          integer primary key generated by default as identity,
    name        varchar not null,
    description varchar,
    color       varchar(7) default '#ffffff',
    image       varchar,
    user_id     integer not null,
    foreign key (user_id) references users
);
insert into categories (name, color, user_id)
values ('Default', '#ffffff', 1);
