import db from './src/lib/db.js'; import initializeDatabase from './src/lib/init-db.js'; console.log('šŸš€ Initializing contacts tables...\n'); try { // Run database initialization which will create the new contacts tables initializeDatabase(); console.log('āœ… Contacts tables created successfully!\n'); // Check if there are projects with contact data in the old text field const projectsWithContacts = db.prepare(` SELECT project_id, project_name, contact FROM projects WHERE contact IS NOT NULL AND contact != '' `).all(); if (projectsWithContacts.length > 0) { console.log(`šŸ“‹ Found ${projectsWithContacts.length} projects with contact information in the old text field.\n`); console.log('Sample contacts that could be migrated:'); projectsWithContacts.slice(0, 5).forEach(p => { console.log(` - ${p.project_name}: "${p.contact}"`); }); console.log('\nā„¹ļø You can manually create contacts from the /contacts page and link them to projects.'); console.log(' The old contact field will remain in the database for reference.\n'); } else { console.log('ā„¹ļø No existing contact data found in projects.\n'); } // Show table statistics const contactsCount = db.prepare('SELECT COUNT(*) as count FROM contacts').get(); const projectContactsCount = db.prepare('SELECT COUNT(*) as count FROM project_contacts').get(); console.log('šŸ“Š Database Statistics:'); console.log(` - Contacts: ${contactsCount.count}`); console.log(` - Project-Contact Links: ${projectContactsCount.count}`); console.log('\n✨ Migration complete! You can now:'); console.log(' 1. Visit /contacts to manage your contacts'); console.log(' 2. Add/edit projects to link contacts'); console.log(' 3. View linked contacts in project details\n'); } catch (error) { console.error('āŒ Error during migration:', error); process.exit(1); }