-- 008: Replace __SUPABASE_STORAGE_PUBLIC_BASE_URL__ placeholder in paper URLs
--
-- The course-library seed (comp2211_course_library_papers.sql) was inserted
-- without substituting the placeholder.  This migration replaces it with the
-- real Supabase Storage public base URL for the `papers` bucket.

UPDATE papers
SET paper_file_url = REPLACE(
  paper_file_url,
  '__SUPABASE_STORAGE_PUBLIC_BASE_URL__',
  'https://pvcxipwovpwrurebouwg.supabase.co/storage/v1/object/public/papers'
)
WHERE paper_file_url LIKE '%__SUPABASE_STORAGE_PUBLIC_BASE_URL__%';

UPDATE papers
SET answer_file_url = REPLACE(
  answer_file_url,
  '__SUPABASE_STORAGE_PUBLIC_BASE_URL__',
  'https://pvcxipwovpwrurebouwg.supabase.co/storage/v1/object/public/papers'
)
WHERE answer_file_url LIKE '%__SUPABASE_STORAGE_PUBLIC_BASE_URL__%';

-- Verify: should return 0 rows
SELECT id, course_code, year, term, exam_type, paper_file_url, answer_file_url
FROM papers
WHERE paper_file_url  LIKE '%__SUPABASE_STORAGE_PUBLIC_BASE_URL__%'
   OR answer_file_url LIKE '%__SUPABASE_STORAGE_PUBLIC_BASE_URL__%';
