@qq33357486/oh-my-task 1.4.3 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/db/schema.sql +205 -0
  2. package/package.json +2 -2
@@ -0,0 +1,205 @@
1
+ -- oh-my-task Database Schema (v2)
2
+ -- 从零重写:移除 SOP、assignee、阶段性文档等旧功能
3
+ -- 新增 user_activity、sessions、inserted/notes 等字段
4
+
5
+ -- ============================================
6
+ -- 用户表
7
+ -- ============================================
8
+ CREATE TABLE IF NOT EXISTS users (
9
+ id TEXT PRIMARY KEY,
10
+ name TEXT NOT NULL,
11
+ email TEXT NOT NULL UNIQUE,
12
+ password_hash TEXT NOT NULL,
13
+ role TEXT NOT NULL DEFAULT 'member' CHECK (role IN ('admin', 'member')),
14
+ reset_token TEXT,
15
+ reset_token_expires DATETIME,
16
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
17
+ updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
18
+ );
19
+
20
+ -- ============================================
21
+ -- 用户 Token 表(用于 MCP/API 认证)
22
+ -- ============================================
23
+ CREATE TABLE IF NOT EXISTS user_tokens (
24
+ id TEXT PRIMARY KEY,
25
+ user_id TEXT NOT NULL,
26
+ name TEXT NOT NULL,
27
+ token TEXT NOT NULL UNIQUE,
28
+ last_used_at DATETIME,
29
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
30
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
31
+ );
32
+
33
+ -- ============================================
34
+ -- 用户活动表(用于 DAU/留存统计)
35
+ -- ============================================
36
+ CREATE TABLE IF NOT EXISTS user_activity (
37
+ id TEXT PRIMARY KEY,
38
+ user_id TEXT NOT NULL,
39
+ action TEXT NOT NULL,
40
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
41
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
42
+ );
43
+
44
+ -- ============================================
45
+ -- 项目表
46
+ -- ============================================
47
+ CREATE TABLE IF NOT EXISTS projects (
48
+ id TEXT PRIMARY KEY,
49
+ name TEXT NOT NULL,
50
+ description TEXT,
51
+ owner_id TEXT NOT NULL,
52
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
53
+ updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
54
+ FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
55
+ );
56
+
57
+ -- ============================================
58
+ -- 版本表
59
+ -- ============================================
60
+ CREATE TABLE IF NOT EXISTS versions (
61
+ id TEXT PRIMARY KEY,
62
+ project_id TEXT NOT NULL,
63
+ name TEXT NOT NULL,
64
+ description TEXT,
65
+ start_date DATE,
66
+ due_date DATE,
67
+ locked_at DATETIME DEFAULT NULL,
68
+ completed_at DATETIME DEFAULT NULL,
69
+ archived_at DATETIME DEFAULT NULL,
70
+ sort_order INTEGER NOT NULL DEFAULT 0,
71
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
72
+ updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
73
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
74
+ );
75
+
76
+ -- ============================================
77
+ -- 任务表
78
+ -- ============================================
79
+ CREATE TABLE IF NOT EXISTS tasks (
80
+ id TEXT PRIMARY KEY,
81
+ project_id TEXT NOT NULL,
82
+ version_id TEXT,
83
+ parent_id TEXT,
84
+ title TEXT NOT NULL,
85
+ description TEXT,
86
+ notes TEXT,
87
+ status TEXT NOT NULL DEFAULT 'planned' CHECK (status IN ('planned', 'in_progress', 'done')),
88
+ estimated_days INTEGER DEFAULT 1,
89
+ start_date DATE,
90
+ due_date DATE,
91
+ actual_start DATETIME,
92
+ actual_end DATETIME,
93
+ sort_order INTEGER NOT NULL DEFAULT 0,
94
+ inserted INTEGER NOT NULL DEFAULT 0 CHECK (inserted IN (0, 1)),
95
+ deleted_at DATETIME DEFAULT NULL,
96
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
97
+ updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
98
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
99
+ FOREIGN KEY (version_id) REFERENCES versions(id) ON DELETE SET NULL,
100
+ FOREIGN KEY (parent_id) REFERENCES tasks(id) ON DELETE CASCADE
101
+ );
102
+
103
+ -- ============================================
104
+ -- 任务历史表
105
+ -- ============================================
106
+ CREATE TABLE IF NOT EXISTS task_history (
107
+ id TEXT PRIMARY KEY,
108
+ task_id TEXT NOT NULL,
109
+ action TEXT NOT NULL CHECK (action IN ('created', 'updated', 'status_changed', 'noted')),
110
+ field TEXT,
111
+ old_value TEXT,
112
+ new_value TEXT,
113
+ reason TEXT,
114
+ changed_by TEXT,
115
+ changed_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
116
+ FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE,
117
+ FOREIGN KEY (changed_by) REFERENCES users(id) ON DELETE SET NULL
118
+ );
119
+
120
+ -- ============================================
121
+ -- 节假日表
122
+ -- ============================================
123
+ CREATE TABLE IF NOT EXISTS holidays (
124
+ date DATE PRIMARY KEY,
125
+ year INTEGER NOT NULL,
126
+ is_workday INTEGER NOT NULL DEFAULT 0 CHECK (is_workday IN (0, 1)),
127
+ name TEXT
128
+ );
129
+
130
+ -- ============================================
131
+ -- 系统配置表
132
+ -- ============================================
133
+ CREATE TABLE IF NOT EXISTS system_config (
134
+ key TEXT PRIMARY KEY,
135
+ value TEXT NOT NULL DEFAULT '',
136
+ description TEXT,
137
+ updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
138
+ );
139
+
140
+ -- ============================================
141
+ -- Sessions 表(express-session SQLite store)
142
+ -- better-sqlite3-session-store 需要 sid, sess, expire 列
143
+ -- ============================================
144
+ CREATE TABLE IF NOT EXISTS sessions (
145
+ sid TEXT NOT NULL PRIMARY KEY,
146
+ sess TEXT NOT NULL,
147
+ expire TEXT NOT NULL DEFAULT ''
148
+ );
149
+
150
+ -- 迁移:如果旧 sessions 表缺少 expire 列或有过时的 expired 列,进行修复
151
+ -- SQLite 不支持 DROP COLUMN,需要重建表
152
+ -- 注意:这里只在必要时执行,不影响已有 session 数据
153
+ -- better-sqlite3-session-store 会在构造时自动执行自己的 CREATE TABLE IF NOT EXISTS
154
+
155
+ -- ============================================
156
+ -- 初始系统配置
157
+ -- ============================================
158
+ INSERT OR IGNORE INTO system_config (key, value, description) VALUES
159
+ ('server_url', 'http://localhost:17173', '服务器 URL'),
160
+ ('smtp_host', '', 'SMTP 服务器地址'),
161
+ ('smtp_port', '587', 'SMTP 端口'),
162
+ ('smtp_user', '', 'SMTP 用户名'),
163
+ ('smtp_pass', '', 'SMTP 密码'),
164
+ ('smtp_from', '', '发件人邮箱'),
165
+ ('registration_enabled', '1', '是否开放注册'),
166
+ ('hcaptcha_site_key', '', 'hCaptcha Site Key'),
167
+ ('hcaptcha_secret_key', '', 'hCaptcha Secret Key');
168
+
169
+ -- ============================================
170
+ -- 索引
171
+ -- ============================================
172
+
173
+ -- users 索引
174
+ CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
175
+ CREATE INDEX IF NOT EXISTS idx_users_reset_token ON users(reset_token);
176
+
177
+ -- user_tokens 索引
178
+ CREATE INDEX IF NOT EXISTS idx_user_tokens_user_id ON user_tokens(user_id);
179
+ CREATE INDEX IF NOT EXISTS idx_user_tokens_token ON user_tokens(token);
180
+
181
+ -- user_activity 索引
182
+ CREATE INDEX IF NOT EXISTS idx_user_activity_user_id ON user_activity(user_id);
183
+ CREATE INDEX IF NOT EXISTS idx_user_activity_action ON user_activity(action);
184
+ CREATE INDEX IF NOT EXISTS idx_user_activity_created_at ON user_activity(created_at);
185
+
186
+ -- projects 索引
187
+ CREATE INDEX IF NOT EXISTS idx_projects_owner_id ON projects(owner_id);
188
+
189
+ -- versions 索引
190
+ CREATE INDEX IF NOT EXISTS idx_versions_project_id ON versions(project_id);
191
+ CREATE INDEX IF NOT EXISTS idx_versions_locked_at ON versions(locked_at);
192
+ CREATE INDEX IF NOT EXISTS idx_versions_archived_at ON versions(archived_at);
193
+
194
+ -- tasks 索引
195
+ CREATE INDEX IF NOT EXISTS idx_tasks_project_id ON tasks(project_id);
196
+ CREATE INDEX IF NOT EXISTS idx_tasks_parent_id ON tasks(parent_id);
197
+ CREATE INDEX IF NOT EXISTS idx_tasks_status ON tasks(status);
198
+ CREATE INDEX IF NOT EXISTS idx_tasks_deleted_at ON tasks(deleted_at);
199
+ CREATE INDEX IF NOT EXISTS idx_tasks_version_id ON tasks(version_id);
200
+
201
+ -- task_history 索引
202
+ CREATE INDEX IF NOT EXISTS idx_task_history_task_id ON task_history(task_id);
203
+
204
+ -- holidays 索引
205
+ CREATE INDEX IF NOT EXISTS idx_holidays_year ON holidays(year);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qq33357486/oh-my-task",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "文档驱动的 AI 编程协作系统 - 通过 MCP 工具管理任务",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "scripts": {
18
18
  "dev": "tsx watch src/index.ts",
19
19
  "dev:all": "tsx scripts/dev.ts",
20
- "build": "tsc",
20
+ "build": "tsc && node scripts/copy-schema.cjs",
21
21
  "start": "node dist/index.js",
22
22
  "mcp": "tsx src/mcp/server.ts",
23
23
  "db:init": "tsx src/db/init.ts"