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>
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
const { MongoClient } = require('mongodb');
|
|
|
|
async function queryAllDocuments() {
|
|
const client = new MongoClient('mongodb://localhost:27017');
|
|
|
|
try {
|
|
await client.connect();
|
|
const db = client.db('tractatus_dev');
|
|
const collection = db.collection('documents');
|
|
|
|
const documents = await collection.find({
|
|
visibility: 'public'
|
|
})
|
|
.sort({ category: 1, order: 1, 'metadata.date_created': -1 })
|
|
.toArray();
|
|
|
|
console.log(`\n=== TOTAL DOCUMENTS: ${documents.length} ===\n`);
|
|
|
|
const byCategory = {};
|
|
documents.forEach(doc => {
|
|
const cat = doc.category || 'none';
|
|
if (!byCategory[cat]) {
|
|
byCategory[cat] = [];
|
|
}
|
|
byCategory[cat].push({
|
|
title: doc.title,
|
|
slug: doc.slug,
|
|
order: doc.order || 999,
|
|
category: doc.category || 'none',
|
|
quadrant: doc.quadrant || 'N/A',
|
|
audience: doc.audience || 'general'
|
|
});
|
|
});
|
|
|
|
Object.keys(byCategory).sort().forEach(category => {
|
|
console.log(`\n━━━ CATEGORY: ${category} (${byCategory[category].length} docs) ━━━`);
|
|
byCategory[category].forEach((doc, i) => {
|
|
console.log(`${i + 1}. [order:${doc.order}] ${doc.title}`);
|
|
console.log(` slug: ${doc.slug}`);
|
|
console.log(` quadrant: ${doc.quadrant} | audience: ${doc.audience}`);
|
|
});
|
|
});
|
|
|
|
} finally {
|
|
await client.close();
|
|
}
|
|
}
|
|
|
|
queryAllDocuments().catch(console.error);
|