refactor: update all scripts to use CouchDB instead of MongoDB
- Updated backend/scripts/seedBadges.js to use only CouchDB - Removed MongoDB dependencies and conditional logic - Created new scripts/seedBadges.js for root directory usage - Updated scripts/migrate-production.js to make MongoDB migration optional - Fixed module path resolution for all scripts to work from any directory - Cleaned up scripts/migrate-to-couchdb.js imports - All scripts now work with CouchDB service without MongoDB dependencies 🤖 Generated with [AI Assistant] Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Setup module path to include backend node_modules
|
||||
const path = require('path');
|
||||
const backendPath = path.join(__dirname, '..', 'backend');
|
||||
process.env.NODE_PATH = path.join(backendPath, 'node_modules') + ':' + (process.env.NODE_PATH || '');
|
||||
require('module').Module._initPaths();
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const CouchDBSetup = require('./setup-couchdb');
|
||||
const MongoToCouchMigrator = require('./migrate-to-couchdb');
|
||||
|
||||
@@ -10,7 +17,7 @@ class ProductionMigration {
|
||||
}
|
||||
|
||||
async run() {
|
||||
console.log('🚀 Starting production migration to CouchDB...\n');
|
||||
console.log('🚀 Starting production setup for CouchDB...\n');
|
||||
|
||||
try {
|
||||
// Step 1: Setup CouchDB
|
||||
@@ -22,31 +29,32 @@ class ProductionMigration {
|
||||
await this.setup.seedBadges();
|
||||
console.log('✅ CouchDB setup completed\n');
|
||||
|
||||
// Step 2: Migrate data from MongoDB
|
||||
console.log('=== Step 2: Migrating data from MongoDB ===');
|
||||
await this.migrator.runMigration();
|
||||
console.log('✅ Data migration completed\n');
|
||||
// Step 2: Optional - Migrate data from MongoDB if available
|
||||
if (process.env.MONGO_URI && process.env.MIGRATE_FROM_MONGO === 'true') {
|
||||
console.log('=== Step 2: Migrating data from MongoDB ===');
|
||||
await this.migrator.runMigration();
|
||||
console.log('✅ Data migration completed\n');
|
||||
} else {
|
||||
console.log('ℹ️ Skipping MongoDB migration (not requested or no MONGO_URI provided)\n');
|
||||
}
|
||||
|
||||
// Step 3: Final verification
|
||||
console.log('=== Step 3: Final verification ===');
|
||||
await this.setup.verifySetup();
|
||||
console.log('✅ Verification completed\n');
|
||||
|
||||
console.log('🎉 Production migration completed successfully!');
|
||||
console.log('🎉 Production setup completed successfully!');
|
||||
console.log('\n📋 Next steps:');
|
||||
console.log('1. Update your application configuration to use CouchDB');
|
||||
console.log('2. Deploy the updated application');
|
||||
console.log('3. Monitor the application for any issues');
|
||||
console.log('4. Keep MongoDB backup for a rollback period');
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n❌ Production migration failed:', error.message);
|
||||
console.error('\n❌ Production setup failed:', error.message);
|
||||
console.error('\n📋 Troubleshooting steps:');
|
||||
console.error('1. Check MongoDB connection and data integrity');
|
||||
console.error('2. Verify CouchDB is running and accessible');
|
||||
console.error('3. Check environment variables and credentials');
|
||||
console.error('4. Review migration logs for specific errors');
|
||||
console.error('5. Consider running migration in smaller batches');
|
||||
console.error('1. Verify CouchDB is running and accessible');
|
||||
console.error('2. Check environment variables and credentials');
|
||||
console.error('3. Review setup logs for specific errors');
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user