create table if not exists test_upload_manifests (
    id varchar(64) primary key,
    session_id varchar(64) not null references test_upload_sessions(id) on delete cascade,
    file_name varchar(512) not null,
    content_type varchar(128),
    total_size_bytes bigint not null,
    part_size_bytes int not null,
    total_parts int not null,
    expected_sha256 char(64),
    status varchar(32) not null default 'uploading',
    upload_file_id varchar(64) references test_upload_files(id),
    created_at timestamptz not null default now(),
    completed_at timestamptz
);

create index if not exists idx_test_upload_manifests_session
    on test_upload_manifests(session_id, created_at);

create table if not exists test_upload_parts (
    id varchar(64) primary key,
    manifest_id varchar(64) not null references test_upload_manifests(id) on delete cascade,
    part_index int not null,
    size_bytes bigint not null,
    sha256 char(64) not null,
    created_at timestamptz not null default now(),
    unique(manifest_id, part_index)
);

create index if not exists idx_test_upload_parts_manifest
    on test_upload_parts(manifest_id, part_index);
