All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- Integrated MongoDB 7.0 with Mongoose ODM - Added CRUD API endpoints (GET, POST, PUT, DELETE) - Created Family model with validation - Added database seeding script with initial data - Implemented Add Family modal form in frontend - Updated docker-compose with MongoDB service - Updated Helm chart to v0.3.0 with MongoDB StatefulSet - Updated documentation with MongoDB setup instructions
60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
const mongoose = require('mongoose');
|
||
const Family = require('../models/Family');
|
||
|
||
const initialData = [
|
||
{ "family": "Kafe (קאפח)", "city": "Sana'a (צנעא)", "lat": 15.3545, "lng": 44.2064 },
|
||
{ "family": "Shiheb (שחב-שבח)", "city": "Sana'a (צנעא)", "lat": 15.3545, "lng": 44.2064 },
|
||
{ "family": "Uzeyri (עזירי-עוזרי)", "city": "Sana'a (צנעא)", "lat": 15.3545, "lng": 44.2064 },
|
||
{ "family": "Uzeyri (עזירי-עוזרי)", "city": "Manakhah (מנאכה)", "lat": 15.3019, "lng": 43.5983 },
|
||
{ "family": "Uzeyri (עזירי-עוזרי)", "city": "Dhamar (ד'מאר)", "lat": 14.5424, "lng": 44.4056 },
|
||
{ "family": "Salumi (סלומי-שלומי)", "city": "Al Kafla (אל קפלה)", "lat": 16.0240, "lng": 43.9790 },
|
||
{ "family": "Afgin (עפג'ין)", "city": "Sa'dah (צעדה)", "lat": 16.9402, "lng": 43.7639 },
|
||
{ "family": "Eraki (עראקי)", "city": "Sana'a (צנעא)", "lat": 15.3545, "lng": 44.2064 }
|
||
];
|
||
|
||
async function seedDatabase() {
|
||
try {
|
||
const mongoURI = process.env.MONGODB_URI || 'mongodb://localhost:27017/oramap';
|
||
|
||
await mongoose.connect(mongoURI, {
|
||
useNewUrlParser: true,
|
||
useUnifiedTopology: true,
|
||
});
|
||
|
||
console.log('✅ Connected to MongoDB');
|
||
|
||
// Check if data already exists
|
||
const existingCount = await Family.countDocuments();
|
||
|
||
if (existingCount > 0) {
|
||
console.log(`ℹ️ Database already has ${existingCount} families`);
|
||
const answer = process.argv.includes('--force');
|
||
|
||
if (answer) {
|
||
console.log('🗑️ Clearing existing data...');
|
||
await Family.deleteMany({});
|
||
} else {
|
||
console.log('ℹ️ Skipping seed. Use --force flag to override existing data');
|
||
process.exit(0);
|
||
}
|
||
}
|
||
|
||
// Insert initial data
|
||
console.log('📝 Seeding database...');
|
||
const result = await Family.insertMany(initialData);
|
||
|
||
console.log(`✅ Successfully seeded ${result.length} families`);
|
||
console.log('\nAdded families:');
|
||
result.forEach(family => {
|
||
console.log(` - ${family.family} | ${family.city}`);
|
||
});
|
||
|
||
process.exit(0);
|
||
} catch (error) {
|
||
console.error('❌ Seed error:', error);
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
seedDatabase();
|