INFRASTRUCTURE COMPLETE (22 public documents from 129 total): CATEGORY CONSOLIDATION (12 → 5): - Eliminated chaotic category proliferation - Defined 5 canonical categories with icons, descriptions - Updated frontend sidebar (public/js/docs-app.js) - Categories: getting-started, research-theory, technical-reference, advanced-topics, business-leadership SCRIPTS CREATED: - comprehensive-document-audit.js: Systematic audit of all 129 docs - generate-public-pdfs.js: Puppeteer-based PDF generation (22 PDFs) - migrate-documents-final.js: DB migration (22 updated, 104 archived) - export-for-production.js: Export 22 docs for production - import-from-export.js: Import documents to production DB - analyze-categories.js: Category analysis tool - prepare-public-docs.js: Document preparation validator AUDIT RESULTS: - docs/DOCUMENT_AUDIT_REPORT.json: Full analysis with recommendations - 22 documents recommended for public visibility - 104 documents to archive (internal/obsolete/poor quality) REMAINING WORK: - Fix inst_016/017/018 violations in 22 public documents (85 violations) • inst_016: Statistics need citations or [NEEDS VERIFICATION] • inst_017: Replace absolute assurance terms with evidence-based language • inst_018: Remove maturity claims or add documented evidence - Regenerate PDFs after content fixes - Regenerate production export file (compliant version) - Deploy to production Database migration already executed in dev (22 updated, 104 archived). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
99 lines
3.4 KiB
JavaScript
99 lines
3.4 KiB
JavaScript
/**
|
|
* Import Documents from Export File
|
|
*
|
|
* Imports curated documents into production database
|
|
* Handles upsert (insert or update) based on slug
|
|
*
|
|
* Usage: node scripts/import-from-export.js <export-file.json>
|
|
*/
|
|
|
|
const { MongoClient } = require('mongodb');
|
|
const fs = require('fs').promises;
|
|
|
|
const PROD_URI = 'mongodb://localhost:27017';
|
|
const PROD_DB = 'tractatus_production';
|
|
|
|
async function run() {
|
|
const args = process.argv.slice(2);
|
|
|
|
if (args.length === 0) {
|
|
console.error('Usage: node scripts/import-from-export.js <export-file.json>');
|
|
process.exit(1);
|
|
}
|
|
|
|
const exportFile = args[0];
|
|
|
|
try {
|
|
// Read export file
|
|
const content = await fs.readFile(exportFile, 'utf8');
|
|
const exportData = JSON.parse(content);
|
|
|
|
console.log('═══════════════════════════════════════════════════════════');
|
|
console.log(' IMPORTING DOCUMENTS TO PRODUCTION');
|
|
console.log('═══════════════════════════════════════════════════════════\n');
|
|
console.log(` Source: ${exportFile}`);
|
|
console.log(` Exported: ${exportData.exported_at}`);
|
|
console.log(` Documents: ${exportData.total_documents}\n`);
|
|
|
|
const client = new MongoClient(PROD_URI);
|
|
await client.connect();
|
|
|
|
const db = client.db(PROD_DB);
|
|
const collection = db.collection('documents');
|
|
|
|
const stats = {
|
|
inserted: 0,
|
|
updated: 0,
|
|
errors: []
|
|
};
|
|
|
|
for (const doc of exportData.documents) {
|
|
try {
|
|
const result = await collection.replaceOne(
|
|
{ slug: doc.slug },
|
|
doc,
|
|
{ upsert: true }
|
|
);
|
|
|
|
if (result.upsertedCount > 0) {
|
|
console.log(` ✓ Inserted: ${doc.title}`);
|
|
stats.inserted++;
|
|
} else if (result.modifiedCount > 0) {
|
|
console.log(` ✓ Updated: ${doc.title}`);
|
|
stats.updated++;
|
|
} else {
|
|
console.log(` - No change: ${doc.title}`);
|
|
}
|
|
} catch (error) {
|
|
console.error(` ✗ Error importing ${doc.slug}: ${error.message}`);
|
|
stats.errors.push({ slug: doc.slug, error: error.message });
|
|
}
|
|
}
|
|
|
|
console.log('\n═══════════════════════════════════════════════════════════');
|
|
console.log(' IMPORT SUMMARY');
|
|
console.log('═══════════════════════════════════════════════════════════\n');
|
|
console.log(` ✅ Inserted: ${stats.inserted}`);
|
|
console.log(` ✅ Updated: ${stats.updated}`);
|
|
console.log(` ✗ Errors: ${stats.errors.length}\n`);
|
|
|
|
if (stats.errors.length > 0) {
|
|
console.log(' Errors:');
|
|
stats.errors.forEach(e => console.log(` - ${e.slug}: ${e.error}`));
|
|
console.log('');
|
|
}
|
|
|
|
console.log(' Next steps:');
|
|
console.log(' 1. Verify documents in production database');
|
|
console.log(' 2. Restart production server to pick up changes');
|
|
console.log(' 3. Test https://agenticgovernance.digital/docs.html\n');
|
|
|
|
await client.close();
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('Import error:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
run();
|