Dealer_Onboarding_Backend/scripts/seed-system-configs.ts

101 lines
3.5 KiB
TypeScript
Raw Permalink 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 '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'
},
{
key: 'AUTO_ASSIGN_ONBOARDING',
value: { enabled: true },
category: 'ASSIGNMENT',
description: 'Enable/Disable auto-assignment of participants for Onboarding module'
},
{
key: 'AUTO_ASSIGN_RELOCATION',
value: { enabled: true },
category: 'ASSIGNMENT',
description: 'Enable/Disable auto-assignment of participants for Relocation module'
},
{
key: 'AUTO_ASSIGN_TERMINATION',
value: { enabled: true },
category: 'ASSIGNMENT',
description: 'Enable/Disable auto-assignment of participants for Termination module'
},
{
key: 'AUTO_ASSIGN_CONSTITUTIONAL',
value: { enabled: true },
category: 'ASSIGNMENT',
description: 'Enable/Disable auto-assignment of participants for Constitutional module'
},
{
key: 'AUTO_ASSIGN_RESIGNATION',
value: { enabled: true },
category: 'ASSIGNMENT',
description: 'Enable/Disable auto-assignment of participants for Resignation module'
},
{
key: 'AUTO_ASSIGN_FNF',
value: { enabled: true },
category: 'ASSIGNMENT',
description: 'Enable/Disable auto-assignment of participants for F&F module'
}
];
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;