-- v11.1 hardening delta. Do not edit prior migrations.

create index if not exists ix_outbox_pending
    on building_blocks.outbox_message (occurred_at, message_id)
    where published_at is null;

create index if not exists ix_job_run_status_started
    on building_blocks.job_run (status, started_at);

alter table signal_engine.signal_decision
    add constraint ck_signal_decision_policy_id_not_blank
    check (length(trim(policy_id)) > 0) not valid;

alter table signal_engine.signal_decision
    validate constraint ck_signal_decision_policy_id_not_blank;

drop trigger if exists signal_decision_immutable on signal_engine.signal_decision;
create trigger signal_decision_immutable
before update or delete on signal_engine.signal_decision
for each row execute function signal_engine.prevent_immutable_change();

create unique index if not exists ux_reentry_stage_executed_cycle
    on signal_engine.reentry_stage (executed_cycle_id)
    where executed_cycle_id is not null;
