-- ====================================================================
-- Seed placeholder images as PNG (2026-09-28)
--   The demo data (create_data.sql) points product/category images at
--   placehold.co, which serves SVG by default. next/image's optimizer
--   refuses SVG (allowing it is a security risk), so those images showed
--   as broken everywhere. Asking placehold.co for PNG ("/png" before the
--   query string) fixes every screen at once. Only rows that still use
--   placehold.co are touched; real uploads (Cloudinary) are untouched.
-- Safe to run more than once.
--   npm run db:migrate -- 2026-09-28_placeholder_images_png.sql
-- ====================================================================

UPDATE `product_images`
SET `image_url` = CONCAT(SUBSTRING_INDEX(`image_url`, '?', 1), '/png?', SUBSTRING_INDEX(`image_url`, '?', -1))
WHERE `image_url` LIKE 'https://placehold.co/%?%' AND `image_url` NOT LIKE '%/png?%';

UPDATE `categories`
SET `icon` = CONCAT(SUBSTRING_INDEX(`icon`, '?', 1), '/png?', SUBSTRING_INDEX(`icon`, '?', -1))
WHERE `icon` LIKE 'https://placehold.co/%?%' AND `icon` NOT LIKE '%/png?%';

-- Snapshots copied from product images (cart, wishlist, past orders)
UPDATE `cart_items`
SET `image_url` = CONCAT(SUBSTRING_INDEX(`image_url`, '?', 1), '/png?', SUBSTRING_INDEX(`image_url`, '?', -1))
WHERE `image_url` LIKE 'https://placehold.co/%?%' AND `image_url` NOT LIKE '%/png?%';

UPDATE `wishlists`
SET `image_url` = CONCAT(SUBSTRING_INDEX(`image_url`, '?', 1), '/png?', SUBSTRING_INDEX(`image_url`, '?', -1))
WHERE `image_url` LIKE 'https://placehold.co/%?%' AND `image_url` NOT LIKE '%/png?%';

UPDATE `order_items`
SET `image_url` = CONCAT(SUBSTRING_INDEX(`image_url`, '?', 1), '/png?', SUBSTRING_INDEX(`image_url`, '?', -1))
WHERE `image_url` LIKE 'https://placehold.co/%?%' AND `image_url` NOT LIKE '%/png?%';
