Files
session-mcp/migrate-external-archive.mjs
Christian Gick 25bed341e9 Add migration scripts for archive database migration
Three migration scripts for complete file-to-database migration:
- migrate-all-docs-batch.mjs: Main migration (1,172 files)
- migrate-missed-docs.mjs: Supplementary for hidden dirs (34 files)
- migrate-external-archive.mjs: External archive cleanup (5 files)

Total migrated: 1,211 files (~15MB) to project_archives table
All with semantic embeddings for vector search

Related: CF-267, CF-268

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 15:01:18 +02:00

107 lines
2.9 KiB
JavaScript

#!/usr/bin/env node
/**
* Migrate remaining 5 files from external archive directory to database
* These files were manually created in ~/Documents/ClaudeFramework-Archive/
*/
import { readFileSync, statSync } from 'fs';
import dotenv from 'dotenv';
import { archiveAdd } from './dist/tools/archives.js';
dotenv.config();
const FILES_TO_MIGRATE = [
{
path: '/Users/christian.gick/Documents/ClaudeFramework-Archive/research/IAP_GUIDE.md',
type: 'research',
project: 'CF'
},
{
path: '/Users/christian.gick/Documents/ClaudeFramework-Archive/archive/audits/CREDENTIAL_AUDIT_2025-12-08.md',
type: 'audit',
project: 'CF'
},
{
path: '/Users/christian.gick/Documents/ClaudeFramework-Archive/archive/history/CLAUDE_HISTORY_ARCHIVE_1.md',
type: 'session',
project: 'CF'
},
{
path: '/Users/christian.gick/Documents/ClaudeFramework-Archive/archive/history/CLAUDE_HISTORY_ARCHIVE_2.md',
type: 'session',
project: 'CF'
},
{
path: '/Users/christian.gick/Documents/ClaudeFramework-Archive/archive/CLAUDE_HISTORY_FULL.md',
type: 'session',
project: 'CF'
}
];
function extractTitle(content, filename) {
const lines = content.split('\n');
for (const line of lines) {
if (line.startsWith('# ')) {
return line.slice(2).trim().substring(0, 500);
}
}
return filename.replace('.md', '').replace(/_/g, ' ').substring(0, 500);
}
async function migrateFile(fileInfo) {
try {
const content = readFileSync(fileInfo.path, 'utf-8');
const filename = fileInfo.path.split('/').pop();
const title = extractTitle(content, filename);
const fileSize = statSync(fileInfo.path).size;
console.log(`\nMigrating: ${filename}`);
console.log(` Title: ${title}`);
console.log(` Size: ${Math.round(fileSize / 1024)}KB`);
console.log(` Type: ${fileInfo.type}`);
const result = await archiveAdd({
project: fileInfo.project,
archive_type: fileInfo.type,
title,
content,
original_path: fileInfo.path,
file_size: fileSize
});
console.log(` ✓ Migrated (ID: ${result.id})`);
return { success: true, filename, fileSize };
} catch (error) {
console.error(` ✗ Error: ${error.message}`);
return { success: false, filename: fileInfo.path.split('/').pop(), error: error.message };
}
}
async function main() {
console.log('Migrating 5 external archive files...\n');
let totalSuccess = 0;
let totalFailed = 0;
let totalSize = 0;
for (const file of FILES_TO_MIGRATE) {
const result = await migrateFile(file);
if (result.success) {
totalSuccess++;
totalSize += result.fileSize || 0;
} else {
totalFailed++;
}
}
console.log(`\n✓ Migration complete: ${totalSuccess}/${FILES_TO_MIGRATE.length} files (${Math.round(totalSize / 1024)}KB)`);
if (totalFailed > 0) {
console.log(`✗ Failed: ${totalFailed} files`);
}
}
main().catch(error => {
console.error('Fatal error:', error);
process.exit(1);
});