feat: add contact management functionality
- Implemented ContactForm component for creating and editing contacts. - Added ProjectContactSelector component to manage project-specific contacts. - Updated ProjectForm to include ProjectContactSelector for associating contacts with projects. - Enhanced Card component with a new CardTitle subcomponent for better structure. - Updated Navigation to include a link to the contacts page. - Added translations for contact-related terms in the i18n module. - Initialized contacts database schema and created necessary tables for contact management. - Developed queries for CRUD operations on contacts, including linking and unlinking contacts to projects. - Created a test script to validate contact queries against the database.
This commit is contained in:
46
migrate-contacts.mjs
Normal file
46
migrate-contacts.mjs
Normal file
@@ -0,0 +1,46 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user