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>
186 lines
6.2 KiB
JavaScript
186 lines
6.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Import 5 Missing Archives Documents
|
|
*
|
|
* Imports the 5 MD files that are in Archives but not in the database:
|
|
* 1. Case Studies - Real-World LLM Failure Modes
|
|
* 2. Python API Integration Examples
|
|
* 3. Tractatus Framework Enforcement for Claude Code
|
|
* 4. Concurrent Session Architecture Limitations
|
|
* 5. Rule Proliferation and Transactional Overhead
|
|
*/
|
|
|
|
require('dotenv').config();
|
|
|
|
const fs = require('fs').promises;
|
|
const path = require('path');
|
|
const { connect, close } = require('../src/utils/db.util');
|
|
const Document = require('../src/models/Document.model');
|
|
const { markdownToHtml, extractTOC, generateSlug } = require('../src/utils/markdown.util');
|
|
|
|
const FILES_TO_IMPORT = [
|
|
{
|
|
path: '/home/theflow/projects/tractatus/docs/markdown/case-studies.md',
|
|
slug: 'case-studies-real-world-llm-failure-modes-appendix',
|
|
title: 'Appendix B: Case Studies - Real-World LLM Failure Modes',
|
|
category: 'archives',
|
|
order: 2,
|
|
archiveNote: 'Internal project tracking document. Not relevant for public documentation.'
|
|
},
|
|
{
|
|
path: '/home/theflow/projects/tractatus/docs/api/examples-python.md',
|
|
slug: 'implementation-guide-python-examples',
|
|
title: 'Implementation Guide: Python Code Examples',
|
|
category: 'archives',
|
|
order: 3,
|
|
archiveNote: 'Internal project tracking document. Not relevant for public documentation.'
|
|
},
|
|
{
|
|
path: '/home/theflow/projects/tractatus/docs/claude-code-framework-enforcement.md',
|
|
slug: 'tractatus-framework-enforcement-claude-code',
|
|
title: 'Tractatus Framework Enforcement for Claude Code',
|
|
category: 'archives',
|
|
order: 4,
|
|
archiveNote: 'Development tool documentation. See Implementation Guide for production deployment.'
|
|
},
|
|
{
|
|
path: '/home/theflow/projects/tractatus/docs/research/concurrent-session-architecture-limitations.md',
|
|
slug: 'research-topic-concurrent-session-architecture',
|
|
title: 'Research Topic: Concurrent Session Architecture Limitations in Claude Code Governance',
|
|
category: 'archives',
|
|
order: 5,
|
|
archiveNote: 'Research analysis. See Architectural Overview for current framework status.'
|
|
},
|
|
{
|
|
path: '/home/theflow/projects/tractatus/docs/research/rule-proliferation-and-transactional-overhead.md',
|
|
slug: 'research-topic-rule-proliferation-transactional-overhead',
|
|
title: 'Research Topic: Rule Proliferation and Transactional Overhead in AI Governance',
|
|
category: 'archives',
|
|
order: 6,
|
|
archiveNote: 'Research analysis. See Architectural Overview for current framework status.'
|
|
}
|
|
];
|
|
|
|
function extractFrontMatter(content) {
|
|
const frontMatterRegex = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
|
|
const match = content.match(frontMatterRegex);
|
|
|
|
if (!match) {
|
|
return { frontMatter: {}, content };
|
|
}
|
|
|
|
const frontMatterText = match[1];
|
|
const remainingContent = match[2];
|
|
|
|
const frontMatter = {};
|
|
frontMatterText.split('\n').forEach(line => {
|
|
const [key, ...valueParts] = line.split(':');
|
|
if (key && valueParts.length > 0) {
|
|
const value = valueParts.join(':').trim();
|
|
frontMatter[key.trim()] = value.replace(/^["']|["']$/g, '');
|
|
}
|
|
});
|
|
|
|
return { frontMatter, content: remainingContent };
|
|
}
|
|
|
|
async function importDocument(fileInfo) {
|
|
console.log(`\n📄 Importing: ${fileInfo.title}`);
|
|
console.log(` File: ${fileInfo.path}`);
|
|
|
|
try {
|
|
// Read markdown file
|
|
const rawContent = await fs.readFile(fileInfo.path, 'utf-8');
|
|
const { frontMatter, content } = extractFrontMatter(rawContent);
|
|
|
|
// Convert to HTML
|
|
const content_html = markdownToHtml(content);
|
|
|
|
// Extract TOC
|
|
const toc = extractTOC(content);
|
|
|
|
// Check if document already exists
|
|
const existing = await Document.findBySlug(fileInfo.slug);
|
|
if (existing) {
|
|
console.log(` ⚠️ Document already exists: ${fileInfo.slug}`);
|
|
console.log(` Skipping import.`);
|
|
return { success: false, reason: 'exists' };
|
|
}
|
|
|
|
// Create document
|
|
const doc = await Document.create({
|
|
title: fileInfo.title,
|
|
slug: fileInfo.slug,
|
|
quadrant: frontMatter.quadrant || null,
|
|
persistence: frontMatter.persistence || 'MEDIUM',
|
|
audience: frontMatter.audience || 'general',
|
|
visibility: 'archived',
|
|
category: fileInfo.category,
|
|
order: fileInfo.order,
|
|
archiveNote: fileInfo.archiveNote,
|
|
content_html,
|
|
content_markdown: content,
|
|
toc,
|
|
metadata: {
|
|
author: frontMatter.author || 'John Stroh',
|
|
version: frontMatter.version || '1.0',
|
|
document_code: frontMatter.identifier || null,
|
|
tags: [],
|
|
original_filename: path.basename(fileInfo.path),
|
|
migrated_at: new Date()
|
|
},
|
|
search_index: content.toLowerCase(),
|
|
translations: {},
|
|
download_formats: {}
|
|
});
|
|
|
|
console.log(` ✅ Imported successfully`);
|
|
console.log(` ID: ${doc._id}`);
|
|
console.log(` Slug: ${doc.slug}`);
|
|
|
|
return { success: true, doc };
|
|
|
|
} catch (error) {
|
|
console.error(` ❌ Error importing: ${error.message}`);
|
|
return { success: false, error: error.message };
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
try {
|
|
console.log('🚀 Importing 5 Missing Archives Documents\n');
|
|
console.log('═══════════════════════════════════════════════════\n');
|
|
|
|
await connect();
|
|
|
|
let imported = 0;
|
|
let skipped = 0;
|
|
let failed = 0;
|
|
|
|
for (const fileInfo of FILES_TO_IMPORT) {
|
|
const result = await importDocument(fileInfo);
|
|
if (result.success) {
|
|
imported++;
|
|
} else if (result.reason === 'exists') {
|
|
skipped++;
|
|
} else {
|
|
failed++;
|
|
}
|
|
}
|
|
|
|
console.log('\n═══════════════════════════════════════════════════');
|
|
console.log('\n📊 Import Summary:');
|
|
console.log(` ✅ Imported: ${imported}`);
|
|
console.log(` ⏭️ Skipped (already exists): ${skipped}`);
|
|
console.log(` ❌ Failed: ${failed}`);
|
|
console.log(` 📦 Total: ${FILES_TO_IMPORT.length}`);
|
|
|
|
await close();
|
|
|
|
} catch (error) {
|
|
console.error('\n❌ Fatal error:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|