import { pool } from './src/db/migrate.js'; async function fixBrandNames() { console.log('\n' + '='.repeat(60)); console.log('FIXING BRAND NAMES WITH DUPLICATED LETTERS'); console.log('='.repeat(60) + '\n'); // Get all brands with potential duplication (where first letter is duplicated) const result = await pool.query(` SELECT id, brand_slug, brand_name FROM brand_scrape_jobs WHERE dispensary_id = 112 AND LENGTH(brand_name) > 1 AND SUBSTRING(brand_name, 1, 1) = SUBSTRING(brand_name, 2, 1) ORDER BY brand_name `); console.log(`Found ${result.rows.length} brands with potential duplication:\n`); let fixed = 0; let skipped = 0; for (const row of result.rows) { const originalName = row.brand_name; // Remove the first letter const fixedName = originalName.substring(1); console.log(`${row.id}. "${originalName}" → "${fixedName}"`); // Update the database await pool.query(` UPDATE brand_scrape_jobs SET brand_name = $1, updated_at = NOW() WHERE id = $2 `, [fixedName, row.id]); // Also update products table if brand was already scraped const updateResult = await pool.query(` UPDATE products SET brand = $1, updated_at = CURRENT_TIMESTAMP WHERE dispensary_id = 112 AND brand = $2 `, [fixedName, originalName]); if (updateResult.rowCount && updateResult.rowCount > 0) { console.log(` ✓ Updated ${updateResult.rowCount} products`); } fixed++; } console.log('\n' + '='.repeat(60)); console.log(`✅ FIXED ${fixed} BRAND NAMES`); console.log('='.repeat(60) + '\n'); await pool.end(); } fixBrandNames().catch(console.error);