AstroResearch/migrations/20260629000000_fix_foreign_key_on_update.sql
Asfmq f885c0a4a8 refactor: 服务层抽象下沉、异步锁全栈迁移、客户端韧性加固与移动端适配
- 服务层拆分:删除 api/helpers.rs,新增 citation/note/session/pipeline/paper/vision 独立服务模块
  - Agent 工具精简:paper_content+paper_outline 合并为 paper.rs,图片分析逻辑下沉至 services/vision
  - 并发模型升级:std::sync::{Mutex,RwLock} → tokio::sync::{Mutex,RwLock},消除 async
  上下文中的阻塞风险
  - 客户端加固:HTTP 客户端统一超时配置、ADS 429 / arXiv 503 自动重试、构造函数返回 Result
  - 启动安全:全局 panic hook 日志化、空密码拒绝启动、向量表维度不匹配需显式确认
  - CLI 扩展:构建完整 AppState 复用服务层,新增 Content/Outline/Citations/Search/Process 子命令
  - 前端:移动端汉堡菜单、侧栏滑出面板、引用星系触屏手势(单指拖拽/双指缩放)
2026-06-30 19:26:01 +08:00

73 lines
2.7 KiB
SQL

-- migrations/20260629000000_fix_foreign_key_on_update.sql
-- 修复外键级联更新约束 (ON UPDATE CASCADE)
PRAGMA foreign_keys = OFF;
-- 1. 重建 notes 表
CREATE TABLE notes_new (
id INTEGER PRIMARY KEY AUTOINCREMENT,
bibcode TEXT NOT NULL,
paragraph_index INTEGER NOT NULL,
note_text TEXT NOT NULL DEFAULT '',
highlight_color TEXT NOT NULL DEFAULT 'yellow',
selected_text TEXT NOT NULL DEFAULT '',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (bibcode) REFERENCES papers(bibcode) ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO notes_new (id, bibcode, paragraph_index, note_text, highlight_color, selected_text, created_at)
SELECT id, bibcode, paragraph_index, note_text, highlight_color, selected_text, created_at FROM notes;
DROP TABLE notes;
ALTER TABLE notes_new RENAME TO notes;
CREATE INDEX IF NOT EXISTS idx_notes_bibcode ON notes(bibcode);
-- 2. 重建 paper_chunks_content 表
CREATE TABLE paper_chunks_content_new (
rowid INTEGER PRIMARY KEY AUTOINCREMENT,
bibcode TEXT,
paragraph_index INTEGER,
content TEXT,
headings TEXT DEFAULT 'Document',
section_index INTEGER DEFAULT 0,
FOREIGN KEY(bibcode) REFERENCES papers(bibcode) ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO paper_chunks_content_new (rowid, bibcode, paragraph_index, content, headings, section_index)
SELECT rowid, bibcode, paragraph_index, content, headings, section_index FROM paper_chunks_content;
DROP TABLE paper_chunks_content;
ALTER TABLE paper_chunks_content_new RENAME TO paper_chunks_content;
-- 3. 重建 paper_targets 表
CREATE TABLE paper_targets_new (
id INTEGER PRIMARY KEY AUTOINCREMENT,
bibcode TEXT,
target_name TEXT,
ra TEXT,
dec TEXT,
parallax REAL,
spectral_type TEXT,
v_magnitude REAL,
aliases TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
otype TEXT,
oname TEXT,
pm_ra REAL,
pm_de REAL,
radial_velocity REAL,
parallax_err REAL,
photometry TEXT,
FOREIGN KEY(bibcode) REFERENCES papers(bibcode) ON DELETE CASCADE ON UPDATE CASCADE,
UNIQUE(bibcode, target_name)
);
INSERT INTO paper_targets_new (id, bibcode, target_name, ra, dec, parallax, spectral_type, v_magnitude, aliases, created_at, otype, oname, pm_ra, pm_de, radial_velocity, parallax_err, photometry)
SELECT id, bibcode, target_name, ra, dec, parallax, spectral_type, v_magnitude, aliases, created_at, otype, oname, pm_ra, pm_de, radial_velocity, parallax_err, photometry FROM paper_targets;
DROP TABLE paper_targets;
ALTER TABLE paper_targets_new RENAME TO paper_targets;
CREATE INDEX IF NOT EXISTS idx_paper_targets_name ON paper_targets(target_name);
PRAGMA foreign_keys = ON;