import 'dotenv/config'; import db from '../src/database/models/index.js'; const seedSystemConfigs = async () => { try { console.log('🚀 Starting System Configuration Seeding...'); // Test connection console.log('📡 Testing database connection...'); await db.sequelize.authenticate(); console.log('✅ Database connection established.'); const configs = [ { key: 'SECURITY_DEPOSIT', value: { amount: 500000, currency: 'INR' }, category: 'SECURITY_DEPOSIT', description: 'Default Security Deposit amount for new dealer onboarding' }, { key: 'FIRST_FILL', value: { amount: 1500000, currency: 'INR' }, category: 'SECURITY_DEPOSIT', description: 'Default First Fill amount for new dealer onboarding' } ]; console.log(`🌱 Seeding ${configs.length} configurations...`); for (const config of configs) { const [record, created] = await db.SystemConfiguration.findOrCreate({ where: { key: config.key }, defaults: { ...config, isActive: true } }); if (created) { console.log(`✅ Created config: ${config.key}`); } else { console.log(`â„šī¸ Config already exists: ${config.key}`); } } console.log('✨ System configurations seeded successfully.'); } catch (error) { console.error('❌ Error during seeding:', error); throw error; } }; // Execute seeding with proper error handling seedSystemConfigs() .then(() => { console.log('👋 Seeding process completed.'); process.exit(0); }) .catch((err) => { console.error('đŸ’Ĩ Fatal error:', err); process.exit(1); }); export default seedSystemConfigs;