tractatus/scripts/diagnose-research-migration.js
TheFlow be53ab36f8 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

80 lines
3.2 KiB
JavaScript
Raw Permalink 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.

/**
* Diagnose research document migration issue
*/
const { MongoClient } = require('mongodb');
require('dotenv').config({ path: '/var/www/tractatus/.env' });
async function run() {
console.log('═══════════════════════════════════════════════════════════');
console.log(' DIAGNOSING RESEARCH DOCUMENT MIGRATION');
console.log('═══════════════════════════════════════════════════════════\n');
// 1. Check dev database
console.log('1⃣ Checking DEV database...\n');
const devClient = new MongoClient('mongodb://localhost:27017');
await devClient.connect();
const devDoc = await devClient.db('tractatus_dev').collection('documents').findOne({
slug: 'tractatus-framework-research'
});
if (devDoc) {
console.log(` ✅ Found in dev: ${devDoc.title}`);
console.log(` Category: ${devDoc.category}`);
console.log(` Order: ${devDoc.order}`);
console.log(` Sections: ${devDoc.sections?.length || 0}`);
console.log(` Visibility: ${devDoc.visibility}`);
} else {
console.log(' ❌ NOT found in dev');
}
await devClient.close();
// 2. Check production database
console.log('\n2⃣ Checking PRODUCTION database...\n');
const MONGODB_URI = process.env.MONGODB_URI;
const DB_NAME = process.env.MONGODB_DB || 'tractatus_prod';
console.log(` URI: ${MONGODB_URI?.replace(/:[^:]*@/, ':***@')}`);
console.log(` Database: ${DB_NAME}\n`);
const prodClient = new MongoClient(MONGODB_URI);
await prodClient.connect();
const prodDoc = await prodClient.db(DB_NAME).collection('documents').findOne({
slug: 'tractatus-framework-research'
});
if (prodDoc) {
console.log(` ✅ Found in production: ${prodDoc.title}`);
console.log(` Category: ${prodDoc.category}`);
console.log(` Order: ${prodDoc.order}`);
console.log(` Sections: ${prodDoc.sections?.length || 0}`);
console.log(` Visibility: ${prodDoc.visibility}`);
} else {
console.log(' ❌ NOT found in production');
}
// 3. Check all research-theory documents in production
console.log('\n3⃣ All research-theory documents in production:\n');
const researchDocs = await prodClient.db(DB_NAME).collection('documents')
.find({ category: 'research-theory' })
.project({ slug: 1, title: 1, order: 1 })
.sort({ order: 1 })
.toArray();
researchDocs.forEach(doc => {
console.log(` [${doc.order}] ${doc.slug}`);
console.log(` ${doc.title}`);
});
console.log(`\n Total: ${researchDocs.length} documents in research-theory`);
await prodClient.close();
console.log('\n═══════════════════════════════════════════════════════════');
console.log(' DIAGNOSIS COMPLETE');
console.log('═══════════════════════════════════════════════════════════\n');
}
run().catch(console.error);