dvirlabs 02074aa4a6
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Add MongoDB integration with CRUD UI
- 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
2026-03-25 01:51:46 +02:00

60 lines
2.2 KiB
JavaScript
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.

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