tractatus/scripts/export-research-and-import.js
TheFlow b199a3e265 fix(security): secure archived documents endpoint and reorganize docs UI
Security:
- Add authentication to /api/documents/archived endpoint (admin-only)
- Prevent public exposure of 108 archived/internal documents

Documentation UI:
- Remove duplicate hardcoded Resources section from docs.html
- Add Resources category to docs-app.js for implementation guides
- Move 3 implementation guides from Getting Started to Resources
- Move Glossary from Technical Reference to Getting Started
- Set Research & Theory section to collapsed by default
- Update service worker cache version to 0.1.4

Migration Scripts:
- Add scripts for document category reorganization
- Add scripts for research document migration to production
- Add scripts for glossary verification and comparison

Files changed:
- public/docs.html: Remove duplicate Resources section
- public/js/docs-app.js: Add Resources category, collapse Research
- public/service-worker.js: Bump cache to v0.1.4
- src/routes/documents.routes.js: Secure /archived endpoint
- scripts/*: Add 10 migration/diagnostic scripts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-26 00:03:13 +13:00

91 lines
2.5 KiB
JavaScript

/**
* 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);