資料配置
最後更新
KuraDB 在磁碟上存放檔案的位置,以及每個資料庫 SQLite 資料表的結構。
目錄結構
- ~/.config/kuradb/
- ├── db.json registry: [{"db": "<name>", "createAt": "<RFC 3339 UTC>"}]
- ├── config.json port and remote settings
- ├── endpoint daemon URL, present while the HTTP server runs
- ├── runtime.uid {"uid", "pid", "started_at"} of the running daemon
- ├── daemon.log daemon output, appended
- └── <name>/
- ├── inbox/ watched folder; drop files here
- ├── data.db SQLite database (WAL mode, plus -wal and -shm files)
- └── record.json watcher snapshot of the inbox tree
- ~/Kura_<name> symlink to ~/.config/kuradb/<name>/inbox
~/Kura_<name> 不存在或指向他處時,每次 daemon 啟動都會重建;若該路徑上是非 symlink 的檔案,該資料庫會記錄警告後略過。file_data 資料表
每個資料庫只有一張資料表,由
internal/database/schema/file_data.sql 建立:| 欄位 | 型別 | 意義 |
|---|---|---|
id | INTEGER PRIMARY KEY | 資料列 id;搜尋的第二排序鍵 |
source | TEXT NOT NULL | 檔案在 inbox 內的絕對路徑 |
chunk | INTEGER NOT NULL | 檔案內從 1 起算的 chunk 編號 |
total | INTEGER NOT NULL | 寫入當下該檔的 chunk 總數 |
content | TEXT NOT NULL | chunk 內容 |
dismiss | BOOLEAN NOT NULL DEFAULT FALSE | chunk 被取代或檔案被移除後為 TRUE |
created_at、updated_at | TIMESTAMP | 插入與更新時設為 CURRENT_TIMESTAMP |
(source, chunk) 為唯一鍵,idx_file_data_source 為 source 建立索引。SQLite 連線
每個
data.db 透過 go-sqlkit 開啟,一條寫入連線加上 8 條的讀取連線池。兩者都使用 WAL journal 與 50 秒 busy timeout;讀取連線池以唯讀模式開啟檔案。因此 kura mcp 程序可在 daemon 寫入時同時讀取。