003_candidate_items_content_mode.sql 1.1 KB

1234567891011121314151617181920212223242526272829
  1. -- 003: add formal candidate item content_mode.
  2. -- Applied to database: creation_knowledge_prod
  3. ALTER TABLE creation_knowledge.candidate_items
  4. ADD COLUMN IF NOT EXISTS content_mode text;
  5. UPDATE creation_knowledge.candidate_items ci
  6. SET content_mode = CASE
  7. WHEN ci.platform = 'weixin' THEN 'article'
  8. WHEN EXISTS (
  9. SELECT 1 FROM creation_knowledge.media_assets ma
  10. WHERE ma.item_id = ci.id AND ma.media_type = 'video'
  11. ) THEN 'video_post'
  12. WHEN EXISTS (
  13. SELECT 1 FROM creation_knowledge.media_assets ma
  14. WHERE ma.item_id = ci.id AND ma.media_type IN ('image', 'cover', 'frame')
  15. ) OR NULLIF(ci.raw_summary, '') IS NOT NULL THEN 'image_post'
  16. ELSE 'unsupported'
  17. END
  18. WHERE ci.content_mode IS NULL;
  19. CREATE INDEX IF NOT EXISTS idx_candidate_items_content_mode
  20. ON creation_knowledge.candidate_items(content_mode);
  21. INSERT INTO creation_knowledge.schema_migrations(version, description)
  22. VALUES ('003_candidate_items_content_mode', 'Add candidate_items.content_mode and backfill business media modes')
  23. ON CONFLICT (version) DO UPDATE
  24. SET description = EXCLUDED.description,
  25. applied_at = now();