import { pool } from './src/db/migrate'; async function fixBrandsTable() { console.log('šŸ”§ Fixing brands table structure...\n'); try { // Drop old tables await pool.query('DROP TABLE IF EXISTS store_brands CASCADE'); await pool.query('DROP TABLE IF EXISTS product_brands CASCADE'); await pool.query('DROP TABLE IF EXISTS brands CASCADE'); console.log('āœ… Dropped old tables'); // Create brands table with correct structure await pool.query(` CREATE TABLE brands ( id SERIAL PRIMARY KEY, name VARCHAR(255) UNIQUE NOT NULL, logo_url TEXT, first_seen_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, last_seen_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) `); console.log('āœ… Created brands table'); // Create store_brands junction table await pool.query(` CREATE TABLE store_brands ( id SERIAL PRIMARY KEY, store_id INTEGER REFERENCES stores(id) ON DELETE CASCADE, brand_id INTEGER REFERENCES brands(id) ON DELETE CASCADE, first_seen_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, last_seen_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, active BOOLEAN DEFAULT true, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE(store_id, brand_id) ) `); console.log('āœ… Created store_brands table'); console.log('\nāœ… Brands tables fixed!'); } catch (error) { console.error('āŒ Error:', error); } finally { await pool.end(); } } fixBrandsTable();