/** * Export tractatus-framework-research from dev and import to production */ const { MongoClient } = require('mongodb'); require('dotenv').config({ path: '/var/www/tractatus/.env' }); async function run() { // 1. Export from dev const devClient = new MongoClient('mongodb://localhost:27017'); await devClient.connect(); const devDoc = await devClient.db('tractatus_dev').collection('documents').findOne({ slug: 'tractatus-framework-research' }); await devClient.close(); if (!devDoc) { console.log('āŒ Document not found in dev'); process.exit(1); } console.log(`āœ… Exported from dev: ${devDoc.title}`); console.log(` Sections: ${devDoc.sections?.length}`); // 2. Prep for production delete devDoc._id; devDoc.category = 'research-theory'; devDoc.order = 2; devDoc.visibility = 'public'; devDoc.updated_at = new Date(); // 3. Import to production const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017'; const DB_NAME = process.env.MONGODB_DB || 'tractatus_prod'; const prodClient = new MongoClient(MONGODB_URI); await prodClient.connect(); const existing = await prodClient.db(DB_NAME).collection('documents').findOne({ slug: 'tractatus-framework-research' }); if (existing) { console.log('āš ļø Already exists - replacing...'); await prodClient.db(DB_NAME).collection('documents').replaceOne( { slug: 'tractatus-framework-research' }, devDoc ); } else { console.log('šŸ“ Inserting new...'); await prodClient.db(DB_NAME).collection('documents').insertOne(devDoc); } await prodClient.close(); console.log('āœ… Imported to production'); // 4. Now run the organization fix on dev too const devClient2 = new MongoClient('mongodb://localhost:27017'); await devClient2.connect(); console.log('\nšŸ“ Updating dev database...'); await devClient2.db('tractatus_dev').collection('documents').updateOne( { slug: 'executive-summary-tractatus-inflection-point' }, { $set: { category: 'research-theory', order: 1, updated_at: new Date() } } ); await devClient2.db('tractatus_dev').collection('documents').updateOne( { slug: 'tractatus-framework-research' }, { $set: { category: 'research-theory', order: 2, updated_at: new Date() } } ); console.log('āœ… Dev database updated'); await devClient2.close(); console.log('\nāœ… COMPLETE - Both documents now in research-theory'); } run().catch(console.error);