CREATE TABLE IF NOT EXISTS teams (
    id SERIAL PRIMARY KEY,
    team_name character(16) NOT NULL,
    team_board_id INT NOT NULL
);

CREATE TYPE role AS ENUM ('analytic', 'backend', 'designer', 'frontend', 'qa', 'project');

CREATE TABLE IF NOT EXISTS employees (
    id SERIAL PRIMARY KEY,
    employee_name TEXT,
    employee_login TEXT UNIQUE,
    employee_role role -- analytic|backend|designer|frontend|qa
);

CREATE TABLE IF NOT EXISTS team_members (
    id SERIAL PRIMARY KEY,
    team_id int not null REFERENCES teams(id) ON DELETE CASCADE,
    employee_id int not null REFERENCES employees(id) ON DELETE CASCADE,
    start_datetime TIMESTAMPTZ NOT NULL,
    end_datetime TIMESTAMPTZ DEFAULT NULL
);

CREATE TABLE IF NOT EXISTS sprints (
    id SERIAL PRIMARY KEY,
    jira_sprint_id INT NOT NULL,
    team_id int not null REFERENCES teams(id) ON DELETE CASCADE,
    sprint_name TEXT NOT NULL,
    sprint_activate_datetime TIMESTAMPTZ NOT NULL,
    sprint_complete_datetime TIMESTAMPTZ NOT NULL,
    sprint_completion_percentage real DEFAULT NULL
);
