--- target-violations

create table target_violations (
    id number(19) primary key,
    project_id number(19) not null references projects(id),
    target_id number(19) not null references targets(id),
    user_id number(19) not null references users(id),

    ticket_id number(19) references tickets(id),
    status_id number(19) references statuses(id),
    resolved number(1) not null,
    
    created_at timestamp with time zone not null,
    updated_at timestamp with time zone not null,
    started_at timestamp with time zone not null
);

create sequence target_violations_id_seq;

create index target_viol_project_started_ix 
on target_violations(project_id, started_at);

create index target_viol_target_ticket_ix 
on target_violations(target_id, ticket_id, user_id);

create index target_viol_target_status_ix
on target_violations(target_id, status_id);
