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

                                    enabled NUMBER(1) NOT NULL,
                                    deleted NUMBER(1) 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 (
                                                                   CASE WHEN deleted = 0
                                                                            THEN project_id
                                                                       END,
                                                                   CASE WHEN deleted = 0
                                                                            THEN LOWER(title)
                                                                       END
    );
