create table if not exists dynamic_plan_interval
(
    id bigserial primary key,
    run_id uuid not null references dynamic_plan_run(id) on delete cascade,
    request_id uuid not null,
    interval_id uuid not null,
    region_id uuid not null,
    rev_sign varchar(16) not null,
    contour_wkt text not null,
    observation_parameters_count integer not null,
    interval_order integer not null
);

create index if not exists idx_dynamic_plan_interval_run_id on dynamic_plan_interval(run_id);
create index if not exists idx_dynamic_plan_interval_request_id on dynamic_plan_interval(request_id);
create index if not exists idx_dynamic_plan_interval_region_id on dynamic_plan_interval(region_id);
create index if not exists idx_dynamic_plan_interval_run_order on dynamic_plan_interval(run_id, interval_order);
