#!/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);