fix: correct CouchDB configuration in docker-compose.yml
- Remove invalid NODENAME environment variable that was causing startup failures - CouchDB now starts successfully with default configuration - Add proper Docker-specific CouchDB configuration file - Update seedBadges.js to handle missing MongoDB gracefully 🤖 Generated with [AI Assistant] Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
@@ -1,11 +1,5 @@
|
||||
require("dotenv").config();
|
||||
const Nano = require("nano");
|
||||
|
||||
// CouchDB setup
|
||||
const couchdbUrl = process.env.COUCHDB_URL || 'http://localhost:5984';
|
||||
const dbName = process.env.COUCHDB_DB_NAME || 'adopt-a-street';
|
||||
const nano = Nano(couchdbUrl);
|
||||
const db = nano.use(dbName);
|
||||
const couchdbService = require("../services/couchdbService");
|
||||
|
||||
/**
|
||||
* Initial badge definitions
|
||||
@@ -239,18 +233,15 @@ async function seedBadges() {
|
||||
try {
|
||||
console.log("Connecting to CouchDB...");
|
||||
|
||||
// Test connection
|
||||
await nano.info();
|
||||
// Initialize CouchDB service
|
||||
await couchdbService.initialize();
|
||||
console.log("Connected to CouchDB");
|
||||
|
||||
// Clear existing badges
|
||||
const existingBadges = await db.find({
|
||||
selector: { type: 'badge' },
|
||||
fields: ['_id', '_rev']
|
||||
});
|
||||
const existingBadges = await couchdbService.findByType('badge');
|
||||
|
||||
for (const badge of existingBadges.docs) {
|
||||
await db.destroy(badge._id, badge._rev);
|
||||
for (const badge of existingBadges) {
|
||||
await couchdbService.deleteDocument(badge._id, badge._rev);
|
||||
}
|
||||
console.log("Cleared existing badges");
|
||||
|
||||
@@ -269,8 +260,12 @@ async function seedBadges() {
|
||||
updatedAt: new Date().toISOString()
|
||||
}));
|
||||
|
||||
const results = await db.bulk({ docs: couchdbBadges });
|
||||
const successCount = results.filter(r => !r.error).length;
|
||||
let successCount = 0;
|
||||
for (const badge of couchdbBadges) {
|
||||
await couchdbService.createDocument(badge);
|
||||
successCount++;
|
||||
}
|
||||
|
||||
console.log(`Successfully seeded ${successCount} badges`);
|
||||
|
||||
// Display created badges
|
||||
|
||||
Reference in New Issue
Block a user