Files
JARVIS/docs/superpowers/plans/2026-03-20-daily-todo-migration.md

45 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Daily Todo 数据库迁移
## 自动迁移
SQLAlchemy 会在应用启动时通过 `init_db()` 自动创建所有表,包括 `daily_todos` 表。
## 手动迁移(如需)
如果需要手动创建表,执行以下 SQL
```sql
CREATE TABLE IF NOT EXISTS daily_todos (
id VARCHAR(36) PRIMARY KEY,
user_id VARCHAR(36) NOT NULL,
title VARCHAR(500) NOT NULL,
is_completed BOOLEAN NOT NULL DEFAULT 0,
source VARCHAR(20) NOT NULL DEFAULT 'manual',
source_detail VARCHAR(500),
source_ref_id VARCHAR(36),
todo_date VARCHAR(10) NOT NULL,
completed_at TIMESTAMP NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_daily_todos_user_date ON daily_todos(user_id, todo_date);
CREATE INDEX IF NOT EXISTS idx_daily_todos_user_id ON daily_todos(user_id);
```
## 表说明
| 字段 | 类型 | 说明 |
|------|------|------|
| id | VARCHAR(36) | 主键UUID |
| user_id | VARCHAR(36) | 所属用户,索引 |
| title | VARCHAR(500) | 待办标题 |
| is_completed | BOOLEAN | 是否完成,默认 false |
| source | VARCHAR(20) | 来源ai_kanban / ai_chat / manual |
| source_detail | VARCHAR(500) | 来源说明文本 |
| source_ref_id | VARCHAR(36) | 来源原始ID看板TaskID或对话ID |
| todo_date | VARCHAR(10) | 所属日期 YYYY-MM-DD |
| completed_at | TIMESTAMP | 完成时间 |
| created_at | TIMESTAMP | 创建时间 |
| updated_at | TIMESTAMP | 更新时间 |