| 58 | } |
| 59 | |
| 60 | initializeDatabase() { |
| 61 | console.log('🔧 Initializing CSS-Inspiration tables...'); |
| 62 | |
| 63 | // CSS-Inspiration 项目表 |
| 64 | const createInspirationTableSQL = ` |
| 65 | CREATE TABLE IF NOT EXISTS css_inspiration ( |
| 66 | id INTEGER PRIMARY KEY, |
| 67 | category TEXT NOT NULL, |
| 68 | filename TEXT NOT NULL, |
| 69 | title TEXT NOT NULL, |
| 70 | description TEXT, |
| 71 | html_content TEXT, |
| 72 | css_content TEXT, |
| 73 | demo_url TEXT, |
| 74 | source_url TEXT, |
| 75 | tags TEXT, |
| 76 | difficulty_level TEXT, |
| 77 | browser_support TEXT, |
| 78 | created_at TEXT DEFAULT CURRENT_TIMESTAMP, |
| 79 | updated_at TEXT DEFAULT CURRENT_TIMESTAMP, |
| 80 | search_content TEXT, |
| 81 | UNIQUE(category, filename) |
| 82 | ) |
| 83 | `; |
| 84 | |
| 85 | // 代码片段表(用于存储提取的代码块) |
| 86 | const createCodeSnippetsTableSQL = ` |
| 87 | CREATE TABLE IF NOT EXISTS code_snippets ( |
| 88 | id INTEGER PRIMARY KEY, |
| 89 | inspiration_id INTEGER, |
| 90 | snippet_type TEXT, -- 'html', 'css', 'javascript' |
| 91 | code_content TEXT, |
| 92 | line_start INTEGER, |
| 93 | line_end INTEGER, |
| 94 | description TEXT, |
| 95 | FOREIGN KEY(inspiration_id) REFERENCES css_inspiration(id) |
| 96 | ) |
| 97 | `; |
| 98 | |
| 99 | // Demo 样式表(用于存储完整的可运行 demo) |
| 100 | const createDemoStylesTableSQL = ` |
| 101 | CREATE TABLE IF NOT EXISTS demo_styles ( |
| 102 | id INTEGER PRIMARY KEY, |
| 103 | inspiration_id INTEGER, |
| 104 | complete_html TEXT, |
| 105 | complete_css TEXT, |
| 106 | preview_image TEXT, |
| 107 | is_interactive BOOLEAN DEFAULT 0, |
| 108 | performance_notes TEXT, |
| 109 | FOREIGN KEY(inspiration_id) REFERENCES css_inspiration(id) |
| 110 | ) |
| 111 | `; |
| 112 | |
| 113 | this.db.serialize(() => { |
| 114 | this.db.run(createInspirationTableSQL) |
| 115 | .run(createCodeSnippetsTableSQL) |
| 116 | .run(createDemoStylesTableSQL); |
| 117 | |