CREATE TABLE ticketing_systems (
                                    id BIGINT PRIMARY KEY,
                                    project_id BIGINT NOT NULL REFERENCES projects(id),
                                    type VARCHAR(64) NOT NULL,
                                    title VARCHAR(64) NOT NULL,
                                    host VARCHAR(125) NOT NULL,
                                    port VARCHAR(10) NOT NULL,
                                    email VARCHAR(225) NOT NULL,
                                    login VARCHAR(50),
                                    password VARCHAR(50),

                                    enabled BOOLEAN NOT NULL,
                                    deleted BOOLEAN NOT NULL,

                                    created_at TIMESTAMP WITH TIME ZONE NOT NULL,
                                    updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
                                    deleted_at TIMESTAMP WITH TIME ZONE
);

CREATE SEQUENCE ticketing_systems_id_seq;

CREATE UNIQUE INDEX ticketing_systems_uniq ON ticketing_systems(project_id, LOWER(title)) WHERE deleted = FALSE;
