tractatus/scripts/compare-databases.js
TheFlow 2af47035ac refactor: remove website code and fix critical startup crashes (Phase 8)
CRITICAL FIX: Server would CRASH ON STARTUP (multiple import errors)

REMOVED (2 scripts):
1. scripts/framework-watchdog.js
   - Monitored .claude/session-state.json (OUR Claude Code setup)
   - Monitored .claude/token-checkpoints.json (OUR file structure)
   - Implementers won't have our .claude/ directory

2. scripts/init-db.js
   - Created website collections: blog_posts, media_inquiries, case_submissions
   - Created website collections: resources, moderation_queue, users, citations
   - Created website collections: translations, koha_donations
   - Next steps referenced deleted scripts (npm run seed:admin)

REWRITTEN (2 files):

src/models/index.js (29 lines → 27 lines)
- REMOVED imports: Document, BlogPost, MediaInquiry, CaseSubmission, Resource
- REMOVED imports: ModerationQueue, User (all deleted in Phase 2)
- KEPT imports: AuditLog, DeliberationSession, GovernanceLog, GovernanceRule
- KEPT imports: Precedent, Project, SessionState, VariableValue, VerificationLog
- Result: Only framework models exported

src/server.js (284 lines → 163 lines, 43% reduction)
- REMOVED: Imports to deleted middleware (csrf-protection, response-sanitization)
- REMOVED: Stripe webhook handling (/api/koha/webhook)
- REMOVED: Static file caching (for deleted public/ directory)
- REMOVED: Static file serving (public/ deleted in Phase 6)
- REMOVED: CSRF token endpoint
- REMOVED: Website homepage with "auth, documents, blog, admin" references
- REMOVED: Instruction sync (scripts/sync-instructions-to-db.js reference)
- REMOVED: Hardcoded log path (${process.env.HOME}/var/log/tractatus/...)
- REMOVED: Website-specific security middleware
- KEPT: Security headers, rate limiting, CORS, body parsers
- KEPT: API routes, governance services, MongoDB connections
- RESULT: Clean framework-only server

RESULT: Repository can now start without crashes, all imports resolve

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 22:17:02 +13:00

69 lines
2.4 KiB
JavaScript

#!/usr/bin/env node
/**
* Compare Dev and Prod Databases
* Identifies documents that exist in one but not the other
*/
require('dotenv').config();
const { MongoClient } = require('mongodb');
async function compareDatabases() {
// Connect to local dev
console.log('🔌 Connecting to local dev database...');
const devClient = new MongoClient('mongodb://localhost:27017/tractatus_dev');
await devClient.connect();
const devDb = devClient.db('tractatus_dev');
const devColl = devDb.collection('documents');
// Connect to local prod (for comparison)
console.log('🔌 Connecting to local prod database...\n');
const prodClient = new MongoClient('mongodb://localhost:27017/tractatus_prod');
await prodClient.connect();
const prodDb = prodClient.db('tractatus_prod');
const prodColl = prodDb.collection('documents');
// Get all documents
const devDocs = await devColl.find({}).project({ slug: 1, title: 1, visibility: 1 }).sort({ slug: 1 }).toArray();
const prodDocs = await prodColl.find({}).project({ slug: 1, title: 1, visibility: 1 }).sort({ slug: 1 }).toArray();
const devSlugs = new Set(devDocs.map(d => d.slug));
const prodSlugs = new Set(prodDocs.map(d => d.slug));
const inDevNotProd = devDocs.filter(d => !prodSlugs.has(d.slug));
const inProdNotDev = prodDocs.filter(d => !devSlugs.has(d.slug));
console.log('='.repeat(70));
console.log('DATABASE COMPARISON');
console.log('='.repeat(70));
console.log(`Dev total: ${devDocs.length}`);
console.log(`Prod total: ${prodDocs.length}`);
console.log(`Difference: ${Math.abs(devDocs.length - prodDocs.length)}`);
console.log('='.repeat(70));
if (inDevNotProd.length > 0) {
console.log(`\n📋 Documents in DEV but NOT in PROD (${inDevNotProd.length}):\n`);
inDevNotProd.forEach(d => {
console.log(` - ${d.slug} [${d.visibility || 'public'}]`);
});
}
if (inProdNotDev.length > 0) {
console.log(`\n📋 Documents in PROD but NOT in DEV (${inProdNotDev.length}):\n`);
inProdNotDev.forEach(d => {
console.log(` - ${d.slug} [${d.visibility || 'public'}]`);
});
}
if (inDevNotProd.length === 0 && inProdNotDev.length === 0) {
console.log('\n✅ Dev and Prod have identical document sets!\n');
}
await devClient.close();
await prodClient.close();
process.exit(0);
}
compareDatabases().catch(error => {
console.error('❌ Comparison failed:', error);
process.exit(1);
});