Files
cannaiq/backend/archive/fix-brand-names.ts
Kelly d91c55a344 feat: Add stale process monitor, users route, landing page, archive old scripts
- Add backend stale process monitoring API (/api/stale-processes)
- Add users management route
- Add frontend landing page and stale process monitor UI on /scraper-tools
- Move old development scripts to backend/archive/
- Update frontend build with new features

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 04:07:31 -07:00

59 lines
1.7 KiB
TypeScript

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);