跳转到内容

跟踪数据库和文件

Graft repository 以 worktree 为边界。一次 commit 可以同时包含多个 SQLite 数据库路径和普通应用文件。

project/
data.sqlite
analytics.sqlite
settings.json
attachments/report.pdf
.graft/
Kind含义
sqlite_database通过 Graft 跟踪的 SQLite snapshot。
text_fileUTF-8 文本文件。
binary_file二进制文件。

支持 --kind 的命令也接受 sqlitedbtextbinary 等别名。

Storage用途
sqlite_snapshotSQLite 数据库路径。
inline小文本文件,直接存入 object database。
external二进制文件、配置的 external path、大文本文件。

kind 表示内容类型,storage 表示存储策略。

Terminal window
graft status
graft add --all
graft commit -m "save app state"

按类型 stage:

Terminal window
graft add --all --kind sqlite_database
graft add --all --kind text_file
graft add --all --kind binary_file

单路径 stage:

Terminal window
graft add data.sqlite
graft add attachments/report.pdf
Terminal window
graft ls-files --json
graft ls-files --json --details
graft ls-files --json --others

--details 包含 object id、content hash 和 external payload 本地状态。 --others 列出可添加的 untracked paths。

Terminal window
graft config set files.inline_text_threshold 8 MB
graft config set files.external_paths "assets/**, attachments/**"

附件、导入、导出、生成媒体、模型等资源目录通常适合放入 external_paths

普通 SQLite 文件是默认 worktree 模式。应用照常提交 SQLite transaction,然后 stage 物理路径:

Terminal window
sqlite3 data.sqlite "INSERT INTO notes(body) VALUES ('external edit');"
graft add data.sqlite

graft add 使用 SQLite online backup 捕获一致的 committed state,包括已提交的 WAL frames,因此不需要手动 checkpoint。Graft 把快照与 staged/HEAD 基线按 4 KiB Graft storage chunk 比较,只写入变化的 chunks;这个粒度与物理数据库的 SQLite page size 无关。没有净变化时不会产生新的 storage commit。

需要 live page-storage 的应用仍可显式使用 Graft VFS,但同一个数据库应选择一种 写入路径,不要在普通文件模式和 VFS 模式之间混写。