Files
blackbird/db2/scripts/patch_001_notes_views_and_indexes.sql
T
qing 986acab1c5 feat: Notes 新增 views 观看人数列,dnfs2 get_notes 打开节点时自增
- db2 补丁 patch_001:Notes 增加 views 列(默认 0),补齐 pid/owner 索引
- dnfs2 get_notes(pid) 打开节点时对 pid 的 views 读改写 +1(best-effort,失败不影响主流程)
2026-08-11 09:51:14 +00:00

17 lines
1.1 KiB
SQL
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.
-- 补丁 001:Notes 表新增观看人数列 + 补齐索引
-- 数据库类型: SQLite
-- 依赖: create_sqlite3.sql 已执行(Users / Notes / Logs 表已存在)
-- 幂等性: 索引部分可重复执行(IF NOT EXISTS);
-- ADD COLUMN 为一次性迁移,重复执行会报 "duplicate column name: views",
-- 请按迁移编号顺序执行一次。
-- ── Notes 新增观看人数列 ────────────────────────────────────────────
-- 观看人数(view count),非空、默认 0,保证旧数据与新插入兼容。
ALTER TABLE Notes ADD COLUMN views INTEGER NOT NULL DEFAULT 0;
-- ── 补齐此前缺失的索引 ──────────────────────────────────────────────
-- dnfs2 get_notes 按 pid 查询子节点,此前为全表扫描。
CREATE INDEX IF NOT EXISTS idx_notes_pid ON Notes(pid);
-- dnfs2 / ca 按 owner 做所有权校验,此前为全表扫描。
CREATE INDEX IF NOT EXISTS idx_notes_owner ON Notes(owner);