-- Normalize existing folder paths in user_ebook_folders table
-- This script will clean up inconsistent path formatting

UPDATE user_ebook_folders 
SET folder_path = REPLACE(REPLACE(folder_path, '\\', '/'), '//', '/')
WHERE folder_path LIKE '%\\%' OR folder_path LIKE '%//%';

-- Remove trailing slashes from non-root paths
UPDATE user_ebook_folders 
SET folder_path = CASE 
    WHEN folder_path = '/' THEN '/'
    WHEN RIGHT(folder_path, 1) = '/' THEN LEFT(folder_path, LENGTH(folder_path) - 1)
    ELSE folder_path
END
WHERE folder_path != '/' AND RIGHT(folder_path, 1) = '/';