Files
adopt-a-street/scripts/migrate-production.js
William Valentin 4b710aae62 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>
2025-11-02 23:29:22 -08:00

70 lines
2.5 KiB
JavaScript
Raw 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.

#!/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');
class ProductionMigration {
constructor() {
this.setup = new CouchDBSetup();
this.migrator = new MongoToCouchMigrator();
}
async run() {
console.log('🚀 Starting production setup for CouchDB...\n');
try {
// Step 1: Setup CouchDB
console.log('=== Step 1: Setting up CouchDB ===');
await this.setup.initialize();
await this.setup.createDatabase();
await this.setup.createIndexes();
await this.setup.createSecurityDocument();
await this.setup.seedBadges();
console.log('✅ CouchDB setup 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 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');
} catch (error) {
console.error('\n❌ Production setup failed:', error.message);
console.error('\n📋 Troubleshooting steps:');
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);
}
}
}
// Run migration if called directly
if (require.main === module) {
const migration = new ProductionMigration();
migration.run().catch(console.error);
}
module.exports = ProductionMigration;