diff --git a/app/routers/cache.py b/app/routers/cache.py index abf940b..13b10f5 100644 --- a/app/routers/cache.py +++ b/app/routers/cache.py @@ -221,8 +221,8 @@ async def upload_content( raise HTTPException(400, error) return { - "cid": ipfs_cid, - "cid": cid, # Legacy, for backwards compatibility + "cid": ipfs_cid or cid, + "content_hash": cid, # Legacy, for backwards compatibility "filename": file.filename, "size": len(content), "uploaded": True, diff --git a/database.py b/database.py index 21b5818..dc20af9 100644 --- a/database.py +++ b/database.py @@ -78,6 +78,25 @@ DO $$ BEGIN EXCEPTION WHEN others THEN NULL; END $$; +-- Migration: rename content_hash to cid (for existing databases) +DO $$ BEGIN + IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'cache_items' AND column_name = 'content_hash') THEN + ALTER TABLE cache_items RENAME COLUMN content_hash TO cid; + END IF; + IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'item_types' AND column_name = 'content_hash') THEN + ALTER TABLE item_types RENAME COLUMN content_hash TO cid; + END IF; + IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'l2_shares' AND column_name = 'content_hash') THEN + ALTER TABLE l2_shares RENAME COLUMN content_hash TO cid; + END IF; + IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'storage_pins' AND column_name = 'content_hash') THEN + ALTER TABLE storage_pins RENAME COLUMN content_hash TO cid; + END IF; + IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'run_cache' AND column_name = 'output_hash') THEN + ALTER TABLE run_cache RENAME COLUMN output_hash TO output_cid; + END IF; +END $$; + -- Run cache: maps content-addressable run_id to output -- run_id is a hash of (sorted inputs + recipe), making runs deterministic CREATE TABLE IF NOT EXISTS run_cache (