-- PM-28: owner-scoped upload staging for raw geometry bytes.
--
-- stageFile writes blobs to the authenticated actor's PDS first, then stores the
-- reassembly metadata needed by publishThing to build space.polymodel.library.defs#file.
CREATE TABLE upload_staging (
    owner_did TEXT NOT NULL,
    upload_id TEXT NOT NULL,
    sha256 TEXT NOT NULL,
    mime_type TEXT NOT NULL,
    size INTEGER NOT NULL,
    filename TEXT,
    status TEXT NOT NULL,
    file_json TEXT NOT NULL,
    chunks_json TEXT NOT NULL,
    created_at INTEGER NOT NULL,
    updated_at INTEGER NOT NULL,
    PRIMARY KEY (owner_did, upload_id)
);

CREATE INDEX idx_upload_staging_owner_updated
    ON upload_staging(owner_did, updated_at DESC);
