Add database migration for content_hash -> cid rename
- Add DO block to migrate existing columns: - cache_items.content_hash -> cid - item_types.content_hash -> cid - l2_shares.content_hash -> cid - storage_pins.content_hash -> cid - run_cache.output_hash -> output_cid - Fix duplicate key bug in upload response Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
19
database.py
19
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 (
|
||||
|
||||
Reference in New Issue
Block a user