import { pool } from './src/db/migrate'; import { dutchieTemplate } from './src/scrapers/templates/dutchie'; async function fixCategoryUrls() { console.log('šŸ”§ Fixing category URLs for Dutchie stores\n'); try { // Get all categories with /shop/ in the URL const result = await pool.query(` SELECT id, store_id, name, slug, dutchie_url FROM categories WHERE dutchie_url LIKE '%/shop/%' ORDER BY store_id, id `); console.log(`Found ${result.rows.length} categories to fix:\n`); for (const category of result.rows) { console.log(`Category: ${category.name}`); console.log(` Old URL: ${category.dutchie_url}`); // Extract base URL (everything before /shop/) const baseUrl = category.dutchie_url.split('/shop/')[0]; // Use template to build correct URL const newUrl = dutchieTemplate.buildCategoryUrl(baseUrl, category.name); console.log(` New URL: ${newUrl}`); // Update the category await pool.query(` UPDATE categories SET dutchie_url = $1 WHERE id = $2 `, [newUrl, category.id]); console.log(` āœ… Updated\n`); } console.log(`\nāœ… All category URLs fixed!`); } catch (error) { console.error('āŒ Error:', error); } finally { await pool.end(); } } fixCategoryUrls();