migrate_image_urls.sql 1.0 KB

1234567891011121314151617
  1. -- ============================================================
  2. -- 图片 URL 迁移(Python 版迁移脚本的配套 SQL)
  3. -- ============================================================
  4. -- 此 SQL 文件仅供回退参考,实际迁移通过 Python 脚本执行:
  5. -- cd /opt/pharmacopoeia-ai/data-pipeline && source venv/bin/activate && python migrate_image_urls.py
  6. -- ============================================================
  7. -- 查询当前旧 URL 数据量
  8. SELECT 'drugs' AS tbl, COUNT(*) FROM drugs WHERE sections::text LIKE '%/images/drugs/%'
  9. UNION ALL
  10. SELECT 'drug_chunks', COUNT(*) FROM drug_chunks WHERE content LIKE '%/images/drugs/%';
  11. -- 手动回滚(极端情况下):
  12. -- UPDATE drugs SET sections = regexp_replace(sections::text, '/images/([a-f0-9]{8})_', '/images/drugs/', 'g')::jsonb
  13. -- WHERE sections::text LIKE '%/images/%';
  14. -- UPDATE drug_chunks SET content = regexp_replace(content, '/images/([a-f0-9]{8})_', '/images/drugs/', 'g')
  15. -- WHERE content LIKE '%/images/%' AND content NOT LIKE '%/images/drugs/%';