CREATE TABLE ticketing_systems (
                                   id BIGINT IDENTITY(1, 1) PRIMARY KEY,
                                   project_id BIGINT NOT NULL REFERENCES projects(id),
                                    [type] NVARCHAR(64) NOT NULL,
                                    title NVARCHAR(64) NOT NULL,
                                   title_lower AS LOWER([title]),
                                    host NVARCHAR(125) NOT NULL,
                                    port NVARCHAR(10) NOT NULL,
                                    email NVARCHAR(225) NOT NULL,
                                    login NVARCHAR(50),
                                    [password] NVARCHAR(50),

                                    enabled BIT NOT NULL,
                                    deleted BIT NOT NULL,

                                   created_at DATETIMEOFFSET NOT NULL,
                                   updated_at DATETIMEOFFSET NOT NULL,
                                   deleted_at DATETIMEOFFSET
);

CREATE UNIQUE INDEX ticketing_systems_uniq ON ticketing_systems(project_id, title_lower) WHERE deleted = 0;
