-- Add submission_item_id to test_data_registry for proper dependency tracking
ALTER TABLE test_data_registry 
  ADD COLUMN IF NOT EXISTS submission_item_id UUID REFERENCES submission_items(id) ON DELETE CASCADE;

-- Add index for fast lookups
CREATE INDEX IF NOT EXISTS idx_test_data_registry_item_id 
  ON test_data_registry(submission_item_id);

-- Update existing records to have NULL submission_item_id (for backwards compatibility)
-- New records will populate this field