Skip to main content
Glama
migrate-documents.jsโ€ข6.75 kB
#!/usr/bin/env node /** * Document Management System Migration * Adds document tables to existing WorkflowMCP SQLite database * Usage: node migrate-documents.js */ import sqlite3 from 'sqlite3'; import { open } from 'sqlite'; import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Database path const DB_PATH = path.resolve(__dirname, '../../data/workflow.db'); const SCHEMA_PATH = path.resolve(__dirname, 'schema.sql'); async function migrateDocuments() { console.log('๐Ÿš€ Starting Document Management System Migration...'); if (!fs.existsSync(DB_PATH)) { console.error('โŒ Database not found:', DB_PATH); process.exit(1); } const db = await open({ filename: DB_PATH, driver: sqlite3.Database }); try { // Enable foreign keys await db.exec('PRAGMA foreign_keys = ON'); console.log('๐Ÿ“‹ Reading schema file...'); const schema = fs.readFileSync(SCHEMA_PATH, 'utf8'); // Extract document-related DDL from schema const documentSchemaStart = schema.indexOf('-- Document Management System'); const documentSchema = schema.substring(documentSchemaStart); // Split into individual statements const statements = documentSchema .split(';') .map(stmt => stmt.trim()) .filter(stmt => stmt && !stmt.startsWith('--')); console.log('๐Ÿ”ง Creating document management tables...'); // Execute each statement for (const [index, stmt] of statements.entries()) { try { if (stmt.trim()) { await db.exec(stmt + ';'); console.log(`โœ… Statement ${index + 1} executed successfully`); } } catch (error) { console.warn(`โš ๏ธ Statement ${index + 1} skipped (might already exist):`, error.message); } } console.log('๐Ÿ“Š Verifying table creation...'); // Check if tables were created const tables = await db.all(` SELECT name FROM sqlite_master WHERE type='table' AND name LIKE '%document%' `); console.log('๐Ÿ“‹ Document tables created:'); tables.forEach(table => { console.log(` โœ… ${table.name}`); }); // Check if FTS table exists const ftsCheck = await db.get(` SELECT name FROM sqlite_master WHERE type='table' AND name='documents_fts' `); if (ftsCheck) { console.log('๐Ÿ” Full-text search index created successfully'); } console.log('๐ŸŽ‰ Document Management System migration completed successfully!'); return true; } catch (error) { console.error('โŒ Migration failed:', error); return false; } finally { db.close(); } } // Import existing test documents async function importExistingDocs() { console.log('๐Ÿ“ Importing existing test documents...'); const db = await open({ filename: DB_PATH, driver: sqlite3.Database }); try { const insertDoc = await db.prepare(` INSERT INTO documents (title, content, doc_type, category, file_path, tags, summary, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?) `); // Import Phase 2.6 test guide const testGuidePath = path.resolve(__dirname, '../../docs/PHASE_2.6_TEST_GUIDE.md'); if (fs.existsSync(testGuidePath)) { const testGuideContent = fs.readFileSync(testGuidePath, 'utf8'); await insertDoc.run( 'Phase 2.6 SvelteKit Dashboard ํ…Œ์ŠคํŠธ ๊ฐ€์ด๋“œ', testGuideContent, 'test_guide', 'phase_2.6', testGuidePath, JSON.stringify(['testing', 'sveltekit', 'phase_2.6', 'dashboard']), 'SvelteKit ์›น ๋Œ€์‹œ๋ณด๋“œ์˜ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ๊ฒ€์ฆํ•˜๊ณ  SQLite ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€์˜ ์—ฐ๋™ ํ…Œ์ŠคํŠธ', 'approved' ); console.log('โœ… Imported: Phase 2.6 Test Guide'); } // Import test results const testResultsPath = path.resolve(__dirname, '../../docs/PHASE_2.6_TEST_RESULTS.md'); if (fs.existsSync(testResultsPath)) { const testResultsContent = fs.readFileSync(testResultsPath, 'utf8'); await insertDoc.run( 'Phase 2.6 SvelteKit Dashboard ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ ๋ณด๊ณ ์„œ', testResultsContent, 'test_results', 'phase_2.6', testResultsPath, JSON.stringify(['testing', 'results', 'phase_2.6', 'sveltekit']), 'ํ†ต๊ณผ์œจ 85.7%๋กœ ํ•ต์‹ฌ ๊ธฐ๋Šฅ์ด ๋ชจ๋‘ ์ •์ƒ ์ž‘๋™ํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธ', 'approved' ); console.log('โœ… Imported: Phase 2.6 Test Results'); } // Import quick checklist const checklistPath = path.resolve(__dirname, '../../docs/QUICK_TEST_CHECKLIST.md'); if (fs.existsSync(checklistPath)) { const checklistContent = fs.readFileSync(checklistPath, 'utf8'); await insertDoc.run( 'Phase 2.6 ๋น ๋ฅธ ํ…Œ์ŠคํŠธ ์ฒดํฌ๋ฆฌ์ŠคํŠธ', checklistContent, 'checklist', 'phase_2.6', checklistPath, JSON.stringify(['testing', 'checklist', 'quick_test']), '5๋ถ„ ๋‚ด ํ•ต์‹ฌ ๊ธฐ๋Šฅ ํ™•์ธ์„ ์œ„ํ•œ 10๊ฐœ ์ฒดํฌํฌ์ธํŠธ', 'approved' ); console.log('โœ… Imported: Quick Test Checklist'); } // Show import results const docCount = await db.get('SELECT COUNT(*) as count FROM documents'); console.log(`๐Ÿ“Š Total documents in database: ${docCount.count}`); return true; } catch (error) { console.error('โŒ Document import failed:', error); return false; } finally { db.close(); } } // Main execution async function main() { const migrationSuccess = await migrateDocuments(); if (migrationSuccess) { await importExistingDocs(); console.log('\n๐ŸŽฏ Next steps:'); console.log('1. Update sqlite-server.js to include document management tools'); console.log('2. Add document management UI to SvelteKit dashboard'); console.log('3. Test document CRUD operations'); } } main().catch(console.error);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/foswmine/workflow-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server