Files
panel/migrate-contacts.mjs
RKWojs 60b79fa360 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.
2025-12-03 16:23:05 +01:00

47 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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