Kairy 课本
继续阅读
第 27 讲核心底座约 16 分钟

灾难恢复、历史分叉(ADR 0004)与 81 迁移

当线上库损坏或用户决定回档到昨天备份时,Kairy 如何保证“坏库证据不毁、未完副作用绝不重放、旧客户端永不串台”?

ADR 0004restore_databaseVACUUM INTOhistory_floor81 迁移Schema DDL
心智模型

回档(Restore)不是“把旧文件直接覆盖上去”那么简单

对普通工具来说,恢复备份就是 cp backup.db core.db。但在 Kairy 里,粗暴覆盖会连环引爆四场灾难:

  1. 如果直接把文件拷贝进 WAL 模式的运行目录,残留的旧 -wal / -shm 会在下次打开时把昨日数据强行重放到恢复库上,瞬间损坏全库!
  2. 如果当前线上库已经损坏,恢复逻辑试图先用 SQLite 打开它做备份,会直接报 SQLite error 26 卡死入口(BUG-0011)。
  3. 备份文件里可能刚好存着一个“当时正在写文件或发网络请求”的 running Run——实际上那个动作在备份之后的现实世界里可能早就执行过了,绝对不能在恢复后自动重放!
  4. 恢复后库里的 cursor 倒退了,正连着的客户端却还记着恢复前的更高游标与旧草稿。

8.1 ADR 0004 灾难恢复全流程与历史分叉状态机

Kairy 架构深度长课 EP05 · 分支 D:持久化底座、单写互斥锁、Outbox 同步与结构棘轮本章定位 40:1455:11
倍速
当前 00:00 · 开场动效:Kairy 架构深度长课 · EP05
ADR 0004 备份恢复历史分叉与崩溃防重放状态机分叉时间线试写回旧时间线观察拦截
旧时间线 authority_A(历史已废止)c=10c=30 备份起点history_floor = cursor 封底c=42 坏库搬走BUG-0011VACUUM INTO 净化先 integrity_check新分叉 authority_B全新 UUID + 崩断标记游标重设 +1n新端重拉全量快照
权威分叉与 RESTORE_INTERRUPTEDkairy-core/crates/adapters/src/storage/authority/maintenance.rs

生成新 authority_id 强制让客户端清掉恢复前记忆中的“未来版本”草稿与待审批卡;所有运行中 Run 标为 Interrupted。

  • accepted/running -> Interrupted
  • 绝不自动重放未完动作!

不变量 保留 commands 去重表与写入 restore_history 溯源审计记录。

图 8-1:ADR 0004 备份恢复四步状态机——从物理隔离坏库、VACUUM INTO 克隆到单事务历史分叉。
restore_database(database, source) 七步原子容灾流
  1. Step 1只读校验备份源与防自恢复检查inspect_backup(source) 以只读连接检验 SQLite >= 3.51.3、MAX_SCHEMA_VERSION 不高于当前 Core(拒降级),并执行 PRAGMA integrity_check == "ok" 提取 (source_authority, source_cursor);同时 canonicalize 比对禁止拿当前库自己恢复自己。不变量 损坏或未来版本的备份在动任何线上文件之前就被拒之门外。
  2. Step 2preserve_raw_cohort 原生文件系统物理取证 (BUG-0011)绝不用 SQLite 打开目标库!直接在磁盘建立 0700 目录 core.raw-before-restore-<uuid>/,把 database、-wal、-shm、-journal 整组原生 fs::copy 进去设为 0600 并逐个 sync_all() 与目录 fsync。不变量 哪怕线上库头字节完全损坏报 error 26,也能完整留存事故现场继续恢复。
  3. Step 3VACUUM INTO 构建纯净单文件候选镜像只读打开 source,调用 VACUUM INTO 输出到私有临时文件 .core.sqlite3.restore-pending-<uuid>,再做一次 inspect_backup 验证一致性,彻底消除源库若带 WAL 时的文件拷贝风险。不变量 候选镜像是经过 SQLite 引擎重新整理的自包含单文件,绝不含散落 WAL 碎片。
  4. Step 4若旧库尚健康则留下 pre-restore 备份并截断 WAL如果 Step 2 后探测原目标库仍可解析,则打开原库调用 current.backup() 生成 core.pre-restore-<uuid>.sqlite3 保险备份,并执行 PRAGMA wal_checkpoint(TRUNCATE) 确认返回 0 才关闭旧库。不变量 误操作恢复后仍有一份干净的恢复前瞬间快照可退回。
  5. Step 5单事务终止未完模型/动作/Run (RESTORE_INTERRUPTED)打开 pending 库开启单写事务:先 interrupt_model_generations(把流式碎片实体化再退役,BUG-0018),再 recover_actions(挂起未完动作要求人类重审),最后把所有 accepted/running 的 Run 改写为 status="interrupted" 且 error.code="RESTORE_INTERRUPTED"。不变量 备份时刻尚未完成的外部副作用绝不会在恢复后自动重放。
  6. Step 6历史分叉:生成新 authority_id + 抬升 cursor/history_floor + 记录溯源计算 cursor = max(source_cursor, outbox seq, previous_cursor) + 1;清空旧 outbox 并插入一条携带新 authority_id 与全量快照的 StateChanged;同步更新 authority 的 authority_id/latest_cursor/history_floor=cursor,写入 restore_history 审计行并提交事务。不变量 history_floor 永久封死老游标,新 authority_id 强制所有客户端清除旧时间线草稿与状态。
  7. Step 7清理旧 sidecars 并原子 rename 切换数据库checkpoint_close(&restored) 截断并关闭 pending 库,sync_all() 刷盘,删除原目标路径残留的 -wal/-shm/-journal 伴生文件(此时仍持有 AuthorityLease 独占锁),最后 fs::rename(&pending, database) 并 sync_parent。不变量 旧库残留的 -wal/-shm 绝没有机会被新替换上的数据库误挂载。

8.2 源码精读:单事务内的历史分叉与防重放提交

以下节选自 kairy-core/crates/adapters/src/storage/authority/maintenance.rs 第 298–404 行,浓缩了 ADR 0004 最核心的原子分叉逻辑:

RUSTrestore_database 事务体:中断未完任务、计算 max+1 游标并写入 restore_historykairy-core/crates/adapters/src/storage/authority/maintenance.rs · L298-L404
298 // 在同一恢复事务内先物化片段并终结未完成的模型生成,确保保留全部负责人已有文本且推进聚合版本号。1
299 restored
300 .interrupt_model_generations(&mut tx, now, true)
301 .await
302 .map_err(|error| error.to_string())?;
303 // 恢复后的未完结动作必须重新征求负责人决策,绝不重放旧审批凭证。
304 restored
305 .recover_actions(&mut tx, now, true)
306 .await
307 .map_err(|error| error.to_string())?;
308 let (_, state) = authority(&mut tx).await.map_err(|error| error.to_string())?;
309 let encoded: Vec<String> = sqlx::query_scalar(2
310 "SELECT run_json FROM runs WHERE status IN ('accepted','running')",
311 )
312 .fetch_all(&mut *tx)
313 .await
314 .map_err(|e| e.to_string())?;
315 for json in encoded {
316 let mut run: kairy_domain::runtime::Run =
317 serde_json::from_str(&json).map_err(|e| e.to_string())?;
318 run.status = kairy_domain::runtime::RunStatus::Interrupted;
319 run.revision += 1;
320 run.updated_at_ms = now;
321 run.error = Some(kairy_domain::runtime::ErrorInfo {
322 code: "RESTORE_INTERRUPTED".into(),
323 message: format!(
324 "Unfinished work from backup authority {source_authority} at cursor {source_cursor} was not replayed; it may already have executed after that backup"
325 ),
326 retryable: false,
327 });
328 sqlx::query("UPDATE runs SET status='interrupted',run_json=? WHERE run_id=?")
329 .bind(serde_json::to_string(&run).map_err(|e| e.to_string())?)
330 .bind(&run.id)
331 .execute(&mut *tx)
332 .await
333 .map_err(|e| e.to_string())?;
334 }
335 let sequence: i64 = sqlx::query_scalar(3
336 "SELECT COALESCE((SELECT seq FROM sqlite_sequence WHERE name='outbox'),0)",
337 )
338 .fetch_one(&mut *tx)
339 .await
340 .map_err(|error| error.to_string())?;
341 let new_authority = Uuid::new_v4().to_string();
342 let cursor = source_cursor
343 .parse::<i64>()
344 .map_err(|e| e.to_string())?
345 .max(sequence)
346 .max(
347 previous_info
348 .as_ref()
349 .and_then(|(_, cursor)| cursor.parse::<i64>().ok())
350 .unwrap_or(0),
351 )
352 .checked_add(1)
353 .ok_or("Cursor space exhausted")?;
354 sqlx::query("DELETE FROM outbox")4
355 .execute(&mut *tx)
356 .await
357 .map_err(|e| e.to_string())?;
358 let event = kairy_domain::runtime::DurableEvent {
359 state: Some(state.clone()),
360 ..kairy_domain::runtime::DurableEvent::new(
361 kairy_domain::runtime::EventKind::StateChanged,
362 &new_authority,
363 cursor,
364 )
365 };
366 sqlx::query("INSERT INTO outbox(cursor,event_json) VALUES(?,?)")
367 .bind(cursor)
368 .bind(serde_json::to_string(&event).map_err(|e| e.to_string())?)
369 .execute(&mut *tx)
370 .await
371 .map_err(|e| e.to_string())?;
372 sqlx::query(
373 "UPDATE authority SET authority_id=?,latest_cursor=?,history_floor=? WHERE singleton=1",
374 )
375 .bind(&new_authority)
376 .bind(cursor)
377 .bind(cursor)
378 .execute(&mut *tx)
379 .await
380 .map_err(|e| e.to_string())?;
381 sqlx::query(
382 "INSERT INTO restore_history(
383 restoration_id,source_authority_id,source_cursor,previous_authority_id,previous_cursor,
384 new_authority_id,new_cursor,raw_cohort_path,created_at_ms
385 ) VALUES(?,?,?,?,?,?,?,?,?)",
386 )
387 .bind(Uuid::new_v4().to_string())
388 .bind(&source_authority)
389 .bind(source_cursor.parse::<i64>().map_err(|e| e.to_string())?)
390 .bind(previous_info.as_ref().map(|(id, _)| id))
391 .bind(
392 previous_info
393 .as_ref()
394 .and_then(|(_, cursor)| cursor.parse::<i64>().ok()),
395 )
396 .bind(new_authority)
397 .bind(cursor)
398 .bind(raw.to_string_lossy().as_ref())
399 .bind(now as i64)
400 .execute(&mut *tx)
401 .await
402 .map_err(|e| e.to_string())?;
403 tx.commit().await.map_err(|e| e.to_string())?;
404 checkpoint_close(&restored).await?;

8.3 81 个追加式 SQLite 迁移与核心表 DDL 精解

Kairy 的数据库演进采用编译期嵌入 + SHA-256 不可变校验(authority/core.rs + authority/migrations.rs),从 0001_authority.sql 至 0081_side_brain_ab_experiments.sql 共 81 个只增不改的 SQL 迁移(MAX_SCHEMA_VERSION = 81)。启动时 SqliteStore::migrate() 会核对每个已安装版本的 sha256——若有人试图修改历史迁移文件,立刻报错拒绝启动;若数据库 MAX(version) > MAX_SCHEMA_VERSION(例如拿老版 Core 打开新版库),直接拒绝降级写入。

交互实验室

79 个 SQLite 迁移的演进图谱

SHA-256 只增不改
Era 1 · 持久权威、Outbox 与恢复分叉M13 个迁移

SQLite 单例权威、命令幂等去重、Outbox 游标与 ADR 0004 备份恢复新 authorityId/history_floor。

  • 0001_authority.sql authority, commands, runs, outbox, imports, provenance
  • 0002_run_indexes.sql runs_status_order, commands_run_lookup
  • 0003_restored_history.sql restore_history 溯源与 authority.history_floor
Era 2 · 模型流式、动作网关与 Agent 循环M2 – M3a.211 个迁移

流式片段、action_intents/receipts、run_steps/agent_loops、反馈归因与两阶段 GC。

  • 0004_model_generations.sql generations, generation_fragments
  • 0005_actions.sql actions
  • 0006_action_intents.sql action_intents, action_receipts
  • 0007_agent_loop.sql run_steps, tool_outputs, agent_loops, feedback_signals
  • 0008_resume_attempts.sql resume_attempts, runs.outcome
  • 0009..0012 message_runs 投影、归因与 revision
  • 0013_artifact_gc.sql & 0014_conversation_cleanup.sql 崩溃安全 GC 与两阶段清理
Era 3 · 沙箱租约、网络治理与三档权限M3a.3 – M3a.47 个迁移

SandboxLease、egress_authority 污点 epoch、托管文件版本与 30 天回收站、导出与三档权限。

  • 0015_sandbox_leases.sql sandbox_leases, sandbox_artifacts
  • 0016_network_governance.sql egress_authority, run_taint, egress_rules, network_reads
  • 0017_fetch_publication.sql network_tool_publications, actions.record_format
  • 0018..0020 managed_file_versions, managed_file_trash, file_exports
  • 0021_owner_permissions.sql permission_previews, workspace_permission_rules
Era 4 · 四层学习栈、墓碑与 DreamingM4 & M5.512 个迁移

claims/tombstones/derived_from/无正文 FTS5、反思、经验、例程、SKILL 账本、Pack 实验与梦游防重。

  • 0022_memory_storage.sql documents, claims, tombstones, derived_from, search_words/trigrams
  • 0023_memory_epochs.sql memory_epochs
  • 0024_reflection.sql reflection_jobs/state/usage
  • 0025_experience.sql experience_entries/evidence/uses
  • 0026..0029 routine_runs, routine_requests, hidden generations
  • 0030_skills.sql skills, skill_versions, skill_ledger
  • 0031_evolution.sql pack_versions, pack_active, experiments, negative_ideas
  • 0032..0033 reflection_state.runs_after, dream_nights
Era 5 · CoW memory_lines、Candle 向量与话题KAIRY-0038 – 006613 个迁移

MEMORY.md 行归属、512 维 Candle 向量、话题判断与折叠、附件转码与 SOUL diff 冷静期。

  • 0034_memory_lines.sql memory_lines (Owner/Kairy 行归属)
  • 0035_memory_vectors.sql memory_vectors (512d BGE)
  • 0036..0039 topic_judgments, topic_compactions, search_items_next
  • 0040..0042 attachments, soul_proposals (7d reject), model_media_type
  • 0043..0046 goal_usage, tool_catalog 基线
Era 6 · 多会话、Wide Research 与 SpacesKAIRY-0069 M1–M77 个迁移

多对话、邮箱、单 Manager 约束 Wide Research、遗忘计划、Spaces 运行时与三层主动引擎。

  • 0047_chats_mailbox_and_runs.sql chats, chat_messages, agent_message_mailbox, subagent_spawns
  • 0048_m2_hardening.sql 唯一激活 wide_research Manager
  • 0049_m3_skills_and_forget.sql skill_invalidation_state, forget_plans
  • 0050_home_documents.sql AGENTS.md / HEARTBEAT.md
  • 0051_spaces_runtime.sql spaces, space_action_invocations, space_cron_jobs
  • 0052_subcontext_network_governance.sql 赋能子代理/旁聊沙箱 (BUG-0171)
  • 0053_scheduler_proactive_and_alignment.sql goals, scheduler_jobs, hooks, feed_runs
Era 7 · 目标追踪、Owner 兜底、Feed v5 与 3D 图标KAIRY-0075 – 008012 个迁移

goal_state 追踪、全权设置、自启动、owner_sites 强确认、3D PNG 图标与 Feed v5 信号。

  • 0054..0058 goal_state/tasks, autonomy_settings, self_started, idea_sources
  • 0059_autonomy_hardening.sql owner_sites, owner_corrections
  • 0060..0065 goal_looking, entity_icons/origin_icons, feed_v5_units/signals
Era 8 · Initiative、Wiki、盲视护栏、收件箱与一等旁聊KAIRY-0081 – 00989 个迁移

有机联系引擎、4 层记忆与知识图谱、ActionGuard 审计、event_inbox 串行锁、统一 10M 池、Single-Kairy Topics 与非阻塞旁聊。

  • 0066_proactive_initiative_and_ledger.sql follow_up_timers, reported_ledger
  • 0067_memory_tiers_and_wiki.sql memory_tier_state, knowledge_pages/links
  • 0068_action_classifier.sql autonomy_guard_settings, action_classifier_audits
  • 0069_event_inbox_and_deferred.sql event_inbox(scope_key), deferred_routine_runs, goal_milestones
  • 0070_eval_hillclimb_and_compartments.sql evolution_diagnostics, goal_compartments
  • 0071_unified_background_pool.sql background_settings_v2(10M), background_usage_breakdown, dream_night_maintenance
  • 0072_side_chat_runs.sql run_chat_meta, chat_origins
  • 0073_personas_and_chat_bindings.sql personas, chat_bindings, persona_compartments
  • 0074_deferred_side_runs.sql deferred_side_runs (旁聊 30m TTL 非阻塞恢复)
Era 9 · 连接器插件平台、步骤摘录与二进制文件生命周期KAIRY-0100 – 0118 (v0.1.0)5 个迁移

SOUL 提案审计、连接器四驱安装与 SHA-256 锁定、游标轮询与 goal_waits、子代理步骤真实 stdout 摘录,以及 10 MiB 二进制文件版本与回收站。

  • 0075_soul_proposal_outcomes.sql SOUL 提案结果追踪
  • 0076_connectors_foundation.sql connectors (四驱、trust_tier、manifest_sha256)
  • 0077_connector_events_and_waits.sql connector_cursors, goal_waits, event_inbox 重建纳入 connector_event
  • 0078_step_output_excerpts.sql step_output_excerpts (子代理/分组步骤有界真实输出)
  • 0079_owner_binary_file_lifecycle.sql managed_file_versions 扩至 10 MiB (live/deleted 软删恢复)
TABLE authority0001_authority.sql + 0003_restored_history.sql

全库唯一的单例权威根表(CHECK(singleton=1)),保存当前权威身份、完整权威状态 JSON、最新游标与恢复历史水位线。

字段类型约束职责
singletonINTEGERPRIMARY KEY CHECK(singleton=1)硬性单行约束,从数据库物理层面保证整库永远最多只有 1 个当前权威
authority_idTEXTNOT NULL当前可写时间线的 UUID 标识;每次 <code>restore_database</code> 分叉时更新
state_jsonTEXTNOT NULL全量快照底座 JSON(<code>SqliteStore::authority()</code> 会叠加上投影列如 <code>state_revision</code>)
latest_cursorINTEGERNOT NULL DEFAULT 0当前已提交的最新 Outbox 单调递增游标
history_floorINTEGERNOT NULL DEFAULT 0 (0003)恢复分叉后的游标下界;任何低于此值的 SSE 订阅直接返回 <code>CURSOR_EXPIRED</code>
查看原始 CREATE TABLE
CREATE TABLE authority (
    singleton INTEGER PRIMARY KEY CHECK(singleton=1),
    authority_id TEXT NOT NULL,
    state_json TEXT NOT NULL,
    latest_cursor INTEGER NOT NULL DEFAULT 0
);
-- 0003_restored_history.sql
ALTER TABLE authority ADD COLUMN history_floor INTEGER NOT NULL DEFAULT 0;
TABLE commands0001_authority.sql

客户端命令幂等去重账本,靠 command_id 主键与 canonical_payload 防止重发串改与重复建 Run。

字段类型约束职责
command_idTEXTPRIMARY KEY客户端提交的 1–128 字符幂等键
canonical_payloadTEXTNOT NULL规范化 JSON 载荷(或被遗忘后的哈希指纹),用于拦截同 ID 异参冲突
run_idTEXTNOT NULL UNIQUE一对一绑定的服务端生成 Run UUID
operation_jsonTEXTNOT NULL解码后的领域 <code>Operation</code> JSON
accepted_cursorINTEGERNOT NULL DEFAULT 0受理该命令时写入 Outbox 的游标
查看原始 CREATE TABLE
CREATE TABLE commands (
    command_id TEXT PRIMARY KEY,
    canonical_payload TEXT NOT NULL,
    run_id TEXT NOT NULL UNIQUE,
    operation_json TEXT NOT NULL,
    accepted_cursor INTEGER NOT NULL DEFAULT 0
);
TABLE runs0001_authority.sql

任务执行实例表,与 commands 构成强外键 1:1 绑定,记录运行生命周期状态(accepted/running/completed/failed/cancelled/interrupted)。

字段类型约束职责
run_idTEXTPRIMARY KEY任务实例唯一 UUID
command_idTEXTNOT NULL UNIQUE REFERENCES commands(command_id)外键强制每条 Run 必源自合法登记的 Command
statusTEXTNOT NULL生命周期状态索引列(供队列扫描 <code>IN ('accepted','running')</code> 使用)
run_jsonTEXTNOT NULL完整 <code>Run</code> 领域对象 JSON(后续由 <code>0004_model_generations.sql:4</code> 增加 <code>work_kind</code>,<code>0007_agent_loop.sql:1-2</code> 追加 <code>outcome</code> 与 <code>outcome_reason</code>;<code>0008</code> 仅改 <code>agent_loops.resume_attempts</code>)
查看原始 CREATE TABLE
CREATE TABLE runs (
    run_id TEXT PRIMARY KEY,
    command_id TEXT NOT NULL UNIQUE REFERENCES commands(command_id),
    status TEXT NOT NULL,
    run_json TEXT NOT NULL
);
TABLE outbox0001_authority.sql

同事务状态事件发布队列;依赖 SQLite AUTOINCREMENT 保证 cursor 永不回退复用(即使清空表)。

字段类型约束职责
cursorINTEGERPRIMARY KEY AUTOINCREMENT全局严格递增事件游标,写入 <code>sqlite_sequence</code> 并在恢复时参与 max+1 计算
event_jsonTEXTNOT NULL序列化后的 <code>DurableEvent</code>(受 512 行与 64 MiB 双上限滑动裁剪)
查看原始 CREATE TABLE
CREATE TABLE outbox (
    cursor INTEGER PRIMARY KEY AUTOINCREMENT,
    event_json TEXT NOT NULL
);
TABLE restore_history0003_restored_history.sql

ADR 0004 备份恢复谱系审计表,记录每一次时间线分叉的前世今生与物理坏库保留路径。

字段类型约束职责
restoration_idTEXTPRIMARY KEY本次恢复操作的唯一 UUID
source_authority_idTEXTNOT NULL被选为恢复源的备份所属权威 ID
source_cursorINTEGERNOT NULL备份源当时的最新游标
previous_authority_idTEXTNULL恢复前原目标库的权威 ID(若原库损坏不可读则为 NULL)
previous_cursorINTEGERNULL恢复前原目标库的游标(若原库不可读则为 NULL)
new_authority_idTEXTNOT NULL分叉后新时间线的 UUID 权威 ID
new_cursorINTEGERNOT NULL分叉后的新起始游标(= history_floor)
raw_cohort_pathTEXTNOT NULL原库物理取证目录 <code>core.raw-before-restore-&lt;uuid&gt;</code> 路径
created_at_msINTEGERNOT NULL恢复完成时的 Unix 毫秒时间戳
查看原始 CREATE TABLE
CREATE TABLE restore_history (
    restoration_id TEXT PRIMARY KEY,
    source_authority_id TEXT NOT NULL,
    source_cursor INTEGER NOT NULL,
    previous_authority_id TEXT,
    previous_cursor INTEGER,
    new_authority_id TEXT NOT NULL,
    new_cursor INTEGER NOT NULL,
    raw_cohort_path TEXT NOT NULL,
    created_at_ms INTEGER NOT NULL
);
TABLE actions0005_actions.sql

高危动作状态机持久化表,利用 (origin_run_id, origin_tool_call_id) 联合唯一约束防模型重入重复建卡。

字段类型约束职责
action_idTEXTPRIMARY KEY动作提案唯一 ID
authority_idTEXTNOT NULL所属权威时间线 ID,配合 <code>phase</code> 建联合索引 <code>actions_phase</code>
phaseTEXTNOT NULL状态机阶段索引(如待审批、Running、已结束或恢复挂起)
action_jsonTEXTNOT NULL完整动作载荷、参数哈希、来源与执行回执 JSON
origin_run_idTEXTNOT NULL发起该动作的父 Run ID
origin_tool_call_idTEXTNULL模型工具调用 ID;与 <code>origin_run_id</code> 组成 <code>UNIQUE</code> 约束防同一步骤重复落盘
查看原始 CREATE TABLE
CREATE TABLE actions (
    action_id TEXT PRIMARY KEY,
    authority_id TEXT NOT NULL,
    phase TEXT NOT NULL,
    action_json TEXT NOT NULL,
    origin_run_id TEXT NOT NULL,
    origin_tool_call_id TEXT,
    UNIQUE(origin_run_id,origin_tool_call_id)
);
CREATE INDEX actions_phase ON actions(authority_id,phase);

真实踩坑:本讲关联的 Bug 复盘

Owner 审阅清单

  1. 所有 SQL 迁移(kairy-core/migrations/0001..0081,MAX_SCHEMA_VERSION = 81)绝对不可事后修改已提交文件:SqliteStore::migrate() 校验 SHA-256,改一个空格都会让现有库启动失败;新表结构改动只能追加新编号迁移。
  2. 需要做线上冷/热备份时,永远调用 Core 提供的 VACUUM INTO 接口(POST /v1/maintenance/backup,transport/http/router.rs:440),严禁在运行时直接 cp core.sqlite3 漏掉 -wal 事务日志。
  3. 遇到数据库故障需要修复时,不要手删坏库——先查看数据目录下的 core.raw-before-restore-* 与 core.pre-restore-* 取证副本。

自测:合上书能答出来吗

进度只存在这台电脑的浏览器里。