@carllee1983/dbcli 1.5.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.dev.md +51 -54
- package/README.md +85 -17
- package/README.zh-TW.md +79 -15
- package/assets/SKILL.md +95 -500
- package/assets/reference.md +510 -0
- package/assets/snippets/.keep +0 -0
- package/assets/snippets/README.md +18 -0
- package/assets/snippets/diag/cache-hit.mysql.sql +19 -0
- package/assets/snippets/diag/cache-hit.postgres.sql +18 -0
- package/assets/snippets/diag/connections.mysql.sql +16 -0
- package/assets/snippets/diag/connections.postgres.sql +16 -0
- package/assets/snippets/diag/db-size.mysql.sql +10 -0
- package/assets/snippets/diag/db-size.postgres.sql +9 -0
- package/assets/snippets/diag/index-usage.mysql.sql +15 -0
- package/assets/snippets/diag/index-usage.postgres.sql +14 -0
- package/assets/snippets/diag/locks.mysql.sql +14 -0
- package/assets/snippets/diag/locks.postgres.sql +15 -0
- package/assets/snippets/diag/long-running.mysql.sql +14 -0
- package/assets/snippets/diag/long-running.postgres.sql +19 -0
- package/assets/snippets/diag/missing-indexes.mysql.sql +13 -0
- package/assets/snippets/diag/missing-indexes.postgres.sql +15 -0
- package/assets/snippets/diag/table-sizes.mysql.sql +14 -0
- package/assets/snippets/diag/table-sizes.postgres.sql +13 -0
- package/dist/cli.mjs +2591 -514
- package/package.json +2 -2
package/README.zh-TW.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
**核心價值:** AI 代理可透過單一、具權限控管的 CLI 工具,在敏感資料保護下安全且智慧地存取專案資料庫。
|
|
8
8
|
|
|
9
|
+
> **安全性更新:** `dbcli init` 現在只會在 `./.dbcli/config.json` 寫入一個很小的專案綁定 stub。完整的連線設定會存放在 `~/.config/dbcli/projects/<project-id>/config.json`,因此敏感設定預設不會留在專案工作區內。
|
|
10
|
+
|
|
9
11
|
## 國際化(i18n)
|
|
10
12
|
|
|
11
13
|
dbcli 透過環境變數 `DBCLI_LANG` 支援多語系:
|
|
@@ -88,8 +90,8 @@ dbcli schema users
|
|
|
88
90
|
# 查詢資料
|
|
89
91
|
dbcli query "SELECT * FROM users"
|
|
90
92
|
|
|
91
|
-
#
|
|
92
|
-
dbcli migrate create posts --column "id:
|
|
93
|
+
# 預覽結構變更(DDL,預設 dry-run;實際套用請加 --execute)
|
|
94
|
+
dbcli migrate create posts --column "id:serial:pk" --column "title:varchar(200):not-null"
|
|
93
95
|
|
|
94
96
|
# 產生 AI 代理 skill
|
|
95
97
|
dbcli skill --install claude
|
|
@@ -146,7 +148,7 @@ dbcli init --conn-name staging --env-file .env.staging
|
|
|
146
148
|
dbcli init --conn-name prod --env-file .env.production --use-env-refs
|
|
147
149
|
```
|
|
148
150
|
|
|
149
|
-
每一條具名連線可以設定不同的 **`--permission`**(例如正式環境只給 `query-only
|
|
151
|
+
每一條具名連線可以設定不同的 **`--permission`**(例如正式環境只給 `query-only`)。現在專案內的 `.dbcli` 主要扮演**綁定 + 快取層**;真正的連線設定會存到使用者家目錄下的 `~/.config/dbcli/projects/<project-id>/`,避免敏感設定留在工作區。
|
|
150
152
|
|
|
151
153
|
### 管理連線(`use` / 移除 / 更名)
|
|
152
154
|
|
|
@@ -187,13 +189,14 @@ dbcli init [OPTIONS]
|
|
|
187
189
|
```
|
|
188
190
|
|
|
189
191
|
**選項 (基本):**
|
|
190
|
-
- `--system <type>` — 資料庫系統:`postgresql`、`mysql`、`mariadb`
|
|
192
|
+
- `--system <type>` — 資料庫系統:`postgresql`、`mysql`、`mariadb`、`mongodb`
|
|
191
193
|
- `--host <host>` — 主機
|
|
192
194
|
- `--port <port>` — 埠號
|
|
193
195
|
- `--user <user>` — 使用者
|
|
194
196
|
- `--password <pass>` — 密碼
|
|
195
197
|
- `--name <db>` — 資料庫名稱
|
|
196
198
|
- `--permission <level>` — 權限等級:`query-only`、`read-write`、`data-admin`、`admin`
|
|
199
|
+
- **僅 MongoDB:** `--uri <uri>` — 完整連線 URI(`mongodb://…` 或 `mongodb+srv://…`);`--auth-source <db>` — 驗證資料庫(使用帳密時預設為 `admin`)
|
|
197
200
|
- `--use-env-refs` — 在設定檔中儲存環境變數名稱參照,而非實際值
|
|
198
201
|
- `--skip-test` — 略過連線測試
|
|
199
202
|
- `--no-interactive` — 非互動模式(須提供所有必要選項)
|
|
@@ -208,7 +211,7 @@ dbcli init [OPTIONS]
|
|
|
208
211
|
**行為:**
|
|
209
212
|
- 若存在 `.env` 會讀取(自動帶入 DATABASE_URL、DB_* 等變數)
|
|
210
213
|
- 缺少的欄位會互動提示(主機、埠、使用者、密碼、資料庫名、權限等級)
|
|
211
|
-
-
|
|
214
|
+
- 在 `.dbcli/config.json` 建立專案綁定 stub,並將完整設定儲存在 `~/.config/dbcli/projects/<project-id>/`
|
|
212
215
|
- 儲存前會測試資料庫連線
|
|
213
216
|
|
|
214
217
|
**範例:**
|
|
@@ -258,6 +261,8 @@ dbcli use --list
|
|
|
258
261
|
|
|
259
262
|
> **`--use-env-refs`:** 啟用後,設定檔會儲存環境變數名稱(例如 `{"$env": "DB_HOST"}`)而非實際值,避免將憑證寫入檔案,適合多環境與 CI/CD。連線時 dbcli 會自動從對應環境變數讀取實際值。
|
|
260
263
|
|
|
264
|
+
> **儲存模型:** 專案內的 `.dbcli` 現在是綁定 + 快取層,不再是秘密資訊的最終儲存地。若你查看 `./.dbcli/config.json`,應只會看到綁定 metadata;完整設定會放在前述 home storage 路徑中。
|
|
265
|
+
|
|
261
266
|
---
|
|
262
267
|
|
|
263
268
|
#### `dbcli list`
|
|
@@ -506,8 +511,8 @@ dbcli skill --install cursor # 安裝至 Cursor IDE
|
|
|
506
511
|
```
|
|
507
512
|
|
|
508
513
|
**行為:**
|
|
509
|
-
-
|
|
510
|
-
- 可輸出至 **stdout**、以 **`--output`**
|
|
514
|
+
- 內建 **`assets/SKILL.md`** 與 **`assets/reference.md`**(單一來源:精簡 skill+完整指令參考)
|
|
515
|
+
- 可輸出至 **stdout**、以 **`--output`** 寫入主要 skill 檔,或以 **`--install`** 複製到**各平台預設路徑**(`--install` 時一併寫入同目錄的 `reference.md`)
|
|
511
516
|
- 實際能否存取資料庫仍由 `.dbcli` 的**權限等級**與**黑名單**決定;skill 文字描述的是完整 CLI 能力
|
|
512
517
|
|
|
513
518
|
**範例:**
|
|
@@ -610,6 +615,10 @@ dbcli check orders --checks nulls,orphans --format table
|
|
|
610
615
|
|
|
611
616
|
# 掃描所有資料表
|
|
612
617
|
dbcli check --all
|
|
618
|
+
|
|
619
|
+
# 以表格顯示單表/掃全庫僅執行部分檢查
|
|
620
|
+
dbcli check orders --format table
|
|
621
|
+
dbcli check --all --checks nulls,duplicates --format json
|
|
613
622
|
```
|
|
614
623
|
|
|
615
624
|
---
|
|
@@ -700,7 +709,7 @@ dbcli upgrade --check # 僅檢查,不安裝
|
|
|
700
709
|
|
|
701
710
|
**背景檢查(stderr;使用 `--quiet` 或執行 `upgrade` / `skill` 時略過):**
|
|
702
711
|
- **CLI 版本:** dbcli 會查詢 npm registry(有快取,約每 24 小時一次)。若有新版,一般指令結束後會印一行提示。
|
|
703
|
-
- **已安裝的 skill:** 若曾執行 `dbcli skill --install <platform>`,dbcli
|
|
712
|
+
- **已安裝的 skill:** 若曾執行 `dbcli skill --install <platform>`,dbcli 會比對各平台**主 skill 檔**(`SKILL.md` 或 Cursor 的 `dbcli.mdc`)與套件內的 `assets/SKILL.md`;若不一致,會提示需重新安裝的平台(`dbcli skill --install <platform>`)。執行 `dbcli upgrade` 時也會一併顯示 skill 與版本資訊。重新安裝時也會一併更新技能旁的 `reference.md`。
|
|
704
713
|
|
|
705
714
|
#### `dbcli shell`
|
|
706
715
|
|
|
@@ -770,6 +779,43 @@ dbcli migrate drop-enum status --execute --force
|
|
|
770
779
|
|
|
771
780
|
---
|
|
772
781
|
|
|
782
|
+
## 查詢風險規劃
|
|
783
|
+
|
|
784
|
+
使用 `plan` 在執行前檢查 SQL 安全性。它只讀取本機 dbcli 設定、權限、黑名單規則與已快取的 schema metadata;不會連線到資料庫。
|
|
785
|
+
|
|
786
|
+
```bash
|
|
787
|
+
dbcli plan "UPDATE users SET status='inactive'" --format json
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
決策結果:
|
|
791
|
+
|
|
792
|
+
- `ALLOW` — 未偵測到明顯風險。
|
|
793
|
+
- `WARN` — 執行前應檢查警告。
|
|
794
|
+
- `BLOCK` — 不安全、不支援,或違反安全設定。
|
|
795
|
+
|
|
796
|
+
文字輸出保持精簡,適合人工閱讀:
|
|
797
|
+
|
|
798
|
+
```text
|
|
799
|
+
Decision: BLOCK
|
|
800
|
+
Operation: UPDATE
|
|
801
|
+
Target tables: users
|
|
802
|
+
|
|
803
|
+
Risk factors:
|
|
804
|
+
- UPDATE statement has no WHERE clause.
|
|
805
|
+
|
|
806
|
+
Recommendations:
|
|
807
|
+
- Add a WHERE clause.
|
|
808
|
+
- Use --dry-run on the actual write command.
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
JSON 輸出會包含給 AI agent 使用的 `suggestedCommands`:
|
|
812
|
+
|
|
813
|
+
```bash
|
|
814
|
+
dbcli plan "SELECT id FROM users WHERE id = 1 LIMIT 1" --format json
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
---
|
|
818
|
+
|
|
773
819
|
## 全域選項
|
|
774
820
|
|
|
775
821
|
所有指令皆支援下列全域選項:
|
|
@@ -954,9 +1000,26 @@ Query-only 代理無法寫入任何表,也無法讀取黑名單表或欄位
|
|
|
954
1000
|
|
|
955
1001
|
---
|
|
956
1002
|
|
|
1003
|
+
## 已保存查詢片段(Saved queries)
|
|
1004
|
+
|
|
1005
|
+
將參數化的 SELECT 片段保存於版控,並依名稱重複執行:
|
|
1006
|
+
|
|
1007
|
+
```bash
|
|
1008
|
+
dbcli queries list
|
|
1009
|
+
dbcli queries show @dau
|
|
1010
|
+
dbcli q @dau --param days=30 --format json
|
|
1011
|
+
```
|
|
1012
|
+
|
|
1013
|
+
片段位於兩層儲存:`.dbcli-shared/queries/`(commit 進版控、團隊共享)與
|
|
1014
|
+
`.dbcli/queries/`(gitignore、個人覆蓋)。每個 `.sql` 檔以 `-- ---` 區塊
|
|
1015
|
+
宣告 frontmatter(name、description、engine、params、tags),完整 schema 見
|
|
1016
|
+
`assets/reference.md`。
|
|
1017
|
+
|
|
1018
|
+
---
|
|
1019
|
+
|
|
957
1020
|
## AI 整合指南
|
|
958
1021
|
|
|
959
|
-
dbcli
|
|
1022
|
+
dbcli 內建供 AI 使用的 skill 文件(`assets/SKILL.md` 與 `assets/reference.md`),並可複製到常見 AI 開發工具的目錄。
|
|
960
1023
|
|
|
961
1024
|
### 快速開始
|
|
962
1025
|
|
|
@@ -988,7 +1051,7 @@ dbcli skill --install cursor
|
|
|
988
1051
|
4. 重新啟動 Claude Code 擴充
|
|
989
1052
|
5. 在對話中詢問:「顯示資料庫 schema」或「查詢作用中使用者」
|
|
990
1053
|
|
|
991
|
-
**Skill 路徑:** `~/.claude/skills/dbcli
|
|
1054
|
+
**Skill 路徑:** `~/.claude/skills/dbcli/`(`SKILL.md` + `reference.md`)
|
|
992
1055
|
|
|
993
1056
|
---
|
|
994
1057
|
|
|
@@ -1000,7 +1063,7 @@ dbcli skill --install cursor
|
|
|
1000
1063
|
4. 啟動 Gemini:`gemini start`
|
|
1001
1064
|
5. 在對話中請求:「查詢 users 表」或「列出資料庫資料表」
|
|
1002
1065
|
|
|
1003
|
-
**Skill 路徑:** `~/.gemini/skills/dbcli
|
|
1066
|
+
**Skill 路徑:** `~/.gemini/skills/dbcli/`(`SKILL.md` + `reference.md`)
|
|
1004
1067
|
|
|
1005
1068
|
---
|
|
1006
1069
|
|
|
@@ -1012,7 +1075,7 @@ dbcli skill --install cursor
|
|
|
1012
1075
|
4. 安裝 Copilot CLI:`npm install -g @github-next/github-copilot-cli`
|
|
1013
1076
|
5. 使用 `copilot --help` 並探索與 dbcli 的整合
|
|
1014
1077
|
|
|
1015
|
-
**Skill 路徑:** 執行 `dbcli skill --install copilot`
|
|
1078
|
+
**Skill 路徑:** 執行 `dbcli skill --install copilot` 於專案根目錄時,寫入 **`.github/skills/dbcli/`**(`SKILL.md` + `reference.md`)。
|
|
1016
1079
|
|
|
1017
1080
|
---
|
|
1018
1081
|
|
|
@@ -1024,7 +1087,7 @@ dbcli skill --install cursor
|
|
|
1024
1087
|
4. 開啟 Cursor
|
|
1025
1088
|
5. 在 Composer 中:「新增一筆使用者」或「匯出使用者資料」
|
|
1026
1089
|
|
|
1027
|
-
**Skill 路徑:**
|
|
1090
|
+
**Skill 路徑:** 在**目前工作目錄**執行 `dbcli skill --install cursor` 時,寫入 **`.cursor/rules/dbcli.mdc`**(摘要與工作流程)及 **`.cursor/skills/dbcli/reference.md`**(完整旗標與範例)。
|
|
1028
1091
|
|
|
1029
1092
|
---
|
|
1030
1093
|
|
|
@@ -1051,7 +1114,7 @@ dbcli skill --install claude
|
|
|
1051
1114
|
|
|
1052
1115
|
### 升級後更新 skill
|
|
1053
1116
|
|
|
1054
|
-
`dbcli skill`
|
|
1117
|
+
`dbcli skill` 會複製套件內的 **`assets/SKILL.md`**;使用 **`--install`** 時另會複製 **`assets/reference.md`** 至技能旁。**不會**依你即時的 `.dbcli` 設定重新產生內文。當**升級 dbcli** 或內建 skill 變更時,請對所使用平台重新執行:
|
|
1055
1118
|
|
|
1056
1119
|
```bash
|
|
1057
1120
|
dbcli skill --install claude
|
|
@@ -1059,7 +1122,7 @@ dbcli skill --install gemini
|
|
|
1059
1122
|
# …依需求
|
|
1060
1123
|
```
|
|
1061
1124
|
|
|
1062
|
-
|
|
1125
|
+
若本機**主 skill 檔**早於套件內 `assets/SKILL.md`,多數指令結束後會在 **stderr** 提醒(見 **`dbcli upgrade`**)。**權限**與**黑名單**變更會影響執行期允許的操作—建議搭配 `dbcli status`、`dbcli blacklist list` 讓代理掌握現況;skill 內文仍可能列出完整指令表。
|
|
1063
1126
|
|
|
1064
1127
|
---
|
|
1065
1128
|
|
|
@@ -1230,6 +1293,7 @@ chmod +x dist/cli.mjs
|
|
|
1230
1293
|
- **PostgreSQL:** 12.0+
|
|
1231
1294
|
- **MySQL:** 8.0+
|
|
1232
1295
|
- **MariaDB:** 10.5+
|
|
1296
|
+
- **MongoDB:** 4.4+(`mongodb://` 與 `mongodb+srv://` 查詢與列集合;見前文 **MongoDB Atlas / SRV 連線**)
|
|
1233
1297
|
|
|
1234
1298
|
### 執行環境
|
|
1235
1299
|
|