SUMMARY:
Completed migration from deprecated 'public: true/false' field to modern
'visibility' field across entire codebase. Ensures single source of truth
for document visibility state.
MIGRATION EXECUTION:
✓ Created migration script with dry-run support
✓ Migrated 120 documents in database (removed deprecated field)
✓ Post-migration: 0 documents with 'public' field, 127 with 'visibility'
✓ Zero data loss - all documents already had visibility set correctly
CODE CHANGES:
1. Database Migration (scripts/migrate-public-to-visibility.js):
- Created safe migration with dry-run mode
- Handles documents with both fields (cleanup)
- Post-migration verification built-in
- Execution: node scripts/migrate-public-to-visibility.js --execute
2. Document Model (src/models/Document.model.js):
- Removed 'public' field from create() method
- Updated findByQuadrant() to use visibility: 'public'
- Updated findByAudience() to use visibility: 'public'
- Updated search() to use visibility: 'public'
3. API Controller (src/controllers/documents.controller.js):
- Removed legacy filter: { public: true, visibility: { $exists: false } }
- listDocuments() now uses clean filter: visibility: 'public'
- searchDocuments() now uses clean filter: visibility: 'public'
4. Scripts Updated:
- upload-document.js: Removed public: true
- seed-architectural-safeguards-document.js: Removed public: true
- import-5-archives.js: Removed public: true
- verify-34-documents.js: Updated query filter to use visibility
- query-all-documents.js: Updated query filter to use visibility
VERIFICATION:
✓ 0 remaining 'public: true/false' usages in src/ and scripts/
✓ All documents use visibility field exclusively
✓ API queries now filter on visibility only
✓ Backward compatibility code removed
DATA MODEL:
Before: { public: true, visibility: 'public' } (redundant)
After: { visibility: 'public' } (single source of truth)
BENEFITS:
- Cleaner data model
- Single source of truth for visibility
- Simplified API logic
- Removed backward compatibility overhead
- Consistent with document security model
FRAMEWORK COMPLIANCE:
Addresses SCHEDULED_TASKS.md item "Legacy public Field Migration"
Completes Sprint 2 Medium Priority task
NEXT STEPS (Optional):
- Deploy migration to production
- Monitor for any edge cases
- Consider adding visibility to database indexes
🤖 Generated with Claude Code (https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
65 lines
2.1 KiB
JavaScript
65 lines
2.1 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Verify All 34 Public Documents
|
|
*
|
|
* Lists all 34 documents that should be visible on the frontend
|
|
*/
|
|
|
|
require('dotenv').config();
|
|
|
|
const { MongoClient } = require('mongodb');
|
|
|
|
async function verify34Documents() {
|
|
const client = new MongoClient('mongodb://localhost:27017');
|
|
|
|
try {
|
|
await client.connect();
|
|
const db = client.db('tractatus_dev');
|
|
const collection = db.collection('documents');
|
|
|
|
// Get documents with proper categories (not 'none')
|
|
const documents = await collection.find({
|
|
visibility: { $in: ['public', 'archived'] },
|
|
category: { $in: ['getting-started', 'technical-reference', 'research-theory', 'advanced-topics', 'case-studies', 'business-leadership', 'archives'] }
|
|
})
|
|
.sort({ category: 1, order: 1 })
|
|
.toArray();
|
|
|
|
console.log(`\n=== VERIFICATION: 34 Public Documents ===`);
|
|
console.log(`Found: ${documents.length} documents\n`);
|
|
|
|
const byCategory = {};
|
|
documents.forEach(doc => {
|
|
const cat = doc.category;
|
|
if (!byCategory[cat]) {
|
|
byCategory[cat] = [];
|
|
}
|
|
byCategory[cat].push({
|
|
order: doc.order,
|
|
title: doc.title,
|
|
slug: doc.slug,
|
|
visibility: doc.visibility || 'public',
|
|
sections: doc.sections ? doc.sections.length : 0
|
|
});
|
|
});
|
|
|
|
Object.keys(byCategory).sort().forEach(category => {
|
|
console.log(`\n━━━ ${category.toUpperCase()} (${byCategory[category].length} docs) ━━━`);
|
|
byCategory[category].forEach(doc => {
|
|
const sectionStatus = doc.sections > 0 ? `✅ ${doc.sections} sections` : `❌ No sections`;
|
|
console.log(`${doc.order}. ${doc.title}`);
|
|
console.log(` ${doc.slug} | ${doc.visibility} | ${sectionStatus}`);
|
|
});
|
|
});
|
|
|
|
console.log(`\n═══════════════════════════════════════════════════`);
|
|
console.log(`Total: ${documents.length} documents`);
|
|
|
|
await client.close();
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
}
|
|
}
|
|
|
|
verify34Documents();
|