#!/usr/bin/env node
/**
* Simple Document Management System Migration
*/
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');
async function simpleMigrate() {
console.log('π Simple Document Management 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 {
await db.exec('PRAGMA foreign_keys = ON');
console.log('π§ Creating documents table...');
// Create documents table
await db.exec(`
CREATE TABLE IF NOT EXISTS documents (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
content TEXT NOT NULL,
doc_type TEXT NOT NULL,
category TEXT,
file_path TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
version INTEGER DEFAULT 1,
created_by TEXT,
tags TEXT,
summary TEXT,
status TEXT DEFAULT 'draft'
)
`);
console.log('π§ Creating document_links table...');
// Create document_links table
await db.exec(`
CREATE TABLE IF NOT EXISTS document_links (
id INTEGER PRIMARY KEY AUTOINCREMENT,
document_id INTEGER NOT NULL,
linked_entity_type TEXT NOT NULL,
linked_entity_id TEXT NOT NULL,
link_type TEXT DEFAULT 'notes',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE
)
`);
console.log('π Verifying tables...');
const tables = await db.all(`
SELECT name FROM sqlite_master
WHERE type='table' AND name LIKE '%document%'
`);
console.log('π Created tables:');
tables.forEach(table => {
console.log(` β
${table.name}`);
});
console.log('π Importing test documents...');
// Import documents
const testGuidePath = path.resolve(__dirname, '../../docs/PHASE_2.6_TEST_GUIDE.md');
if (fs.existsSync(testGuidePath)) {
const content = fs.readFileSync(testGuidePath, 'utf8');
const result = await db.run(`
INSERT INTO documents (title, content, doc_type, category, file_path, tags, summary, status, created_by)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
`, [
'Phase 2.6 SvelteKit Dashboard ν
μ€νΈ κ°μ΄λ',
content,
'test_guide',
'phase_2.6',
testGuidePath,
JSON.stringify(['testing', 'sveltekit', 'phase_2.6', 'dashboard']),
'SvelteKit μΉ λμ보λμ λͺ¨λ κΈ°λ₯μ κ²μ¦νκ³ SQLite λ°μ΄ν°λ² μ΄μ€μμ μ°λ ν
μ€νΈ',
'approved',
'migration'
]);
console.log(`β
Imported test guide (ID: ${result.lastID})`);
}
// Import test results
const testResultsPath = path.resolve(__dirname, '../../docs/PHASE_2.6_TEST_RESULTS.md');
if (fs.existsSync(testResultsPath)) {
const content = fs.readFileSync(testResultsPath, 'utf8');
const result = await db.run(`
INSERT INTO documents (title, content, doc_type, category, file_path, tags, summary, status, created_by)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
`, [
'Phase 2.6 SvelteKit Dashboard ν
μ€νΈ κ²°κ³Ό λ³΄κ³ μ',
content,
'test_results',
'phase_2.6',
testResultsPath,
JSON.stringify(['testing', 'results', 'phase_2.6', 'sveltekit']),
'ν΅κ³Όμ¨ 85.7%λ‘ ν΅μ¬ κΈ°λ₯μ΄ λͺ¨λ μ μ μλνλ κ²μ νμΈ',
'approved',
'migration'
]);
console.log(`β
Imported test results (ID: ${result.lastID})`);
}
// Import checklist
const checklistPath = path.resolve(__dirname, '../../docs/QUICK_TEST_CHECKLIST.md');
if (fs.existsSync(checklistPath)) {
const content = fs.readFileSync(checklistPath, 'utf8');
const result = await db.run(`
INSERT INTO documents (title, content, doc_type, category, file_path, tags, summary, status, created_by)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
`, [
'Phase 2.6 λΉ λ₯Έ ν
μ€νΈ 체ν¬λ¦¬μ€νΈ',
content,
'checklist',
'phase_2.6',
checklistPath,
JSON.stringify(['testing', 'checklist', 'quick_test']),
'5λΆ λ΄ ν΅μ¬ κΈ°λ₯ νμΈμ μν 10κ° μ²΄ν¬ν¬μΈνΈ',
'approved',
'migration'
]);
console.log(`β
Imported checklist (ID: ${result.lastID})`);
}
// Show final count
const count = await db.get('SELECT COUNT(*) as total FROM documents');
console.log(`π Total documents: ${count.total}`);
console.log('π Document management system ready!');
return true;
} catch (error) {
console.error('β Migration failed:', error);
return false;
} finally {
await db.close();
}
}
simpleMigrate().catch(console.error);