create table parked_pieces (
    id bigserial primary key,
    created_at timestamp default current_timestamp,

    piece_cid text not null unique constraint parked_pieces_piece_cid_key,
    piece_padded_size bigint not null,
    piece_raw_size text not null,

    complete boolean not null default false,
    task_id bigint default null,

    foreign key (task_id) references harmony_task (id) on delete set null
);

/*
 * This table is used to keep track of the references to the parked pieces
 * so that we can delete them when they are no longer needed.
 *
 * All references into the parked_pieces table should be done through this table.
 *
 * data_url is optional for refs which also act as data sources.
 */
create table parked_piece_refs (
    ref_id bigserial primary key,
    piece_id bigint not null,

    data_url text,
    data_headers jsonb not null default '{}',

    foreign key (piece_id) references parked_pieces(id) on delete cascade
);
