-- Repairs attachment rows saved with an absolute server filesystem path
-- (e.g. /home/deploy/.../uploads/misc/xxx.png) instead of a proper
-- web-relative path (/uploads/misc/xxx.png). Only touches rows that
-- don't already look correct, so it's safe to run after the code fix
-- is deployed and new uploads are already storing the right format.

UPDATE requirement_attachments
SET file_path = CONCAT('/uploads/', SUBSTRING_INDEX(REPLACE(file_path, '\\', '/'), 'uploads/', -1))
WHERE file_path NOT LIKE '/uploads/%';

UPDATE offer_attachments
SET file_path = CONCAT('/uploads/', SUBSTRING_INDEX(REPLACE(file_path, '\\', '/'), 'uploads/', -1))
WHERE file_path NOT LIKE '/uploads/%';
