@carllee1983/dbcli 1.4.1 → 1.5.2

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 CHANGED
@@ -5,15 +5,21 @@ All notable changes to dbcli are documented here.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [1.4.1] - 2026-04-21
8
+ ## [1.5.2] - 2026-04-22
9
9
 
10
- ### Added
10
+ ### Fixed
11
11
 
12
- - **Documentation Update**: Added per-connection schema isolation details to `SKILL.md` for AI agents.
13
- - Clarified schema storage layout in `.dbcli/schemas/`.
14
- - Added usage examples for `--use <connection>` with schema commands.
12
+ - **Doctor diagnostics for MongoDB SRV**: `dbcli doctor` now reports whether the current execution environment can resolve `mongodb+srv://` connections directly or only through the DNS-over-HTTPS fallback used by the MongoDB adapter.
13
+ - **Documentation**: Clarified the new MongoDB SRV environment diagnostic in README, README.zh-TW, and `assets/SKILL.md`.
15
14
 
16
- ## [1.4.0] - 2026-04-21
15
+ ## [1.5.1] - 2026-04-22
16
+
17
+ ### Fixed
18
+
19
+ - **MongoDB SRV Connections**: `mongodb+srv://` URIs are now expanded and connected through the MongoDB adapter, and MongoDB operations consistently use the configured database.
20
+ - **MongoDB Documentation**: Clarified SRV URI support and configured-database behavior in README, README.zh-TW, and `assets/SKILL.md`.
21
+
22
+ ## [1.5.0] - 2026-04-21
17
23
 
18
24
  ### Added
19
25
 
@@ -22,6 +28,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
22
28
  - Layered schema loading (Hot/Cold) integrated into `configModule`.
23
29
  - Per-connection isolation: Each connection now has its own schema directory (`.dbcli/schemas/<connection>/`).
24
30
  - **Improved Migration UX**: Added proactive hints during schema migration to ensure data consistency.
31
+ - **Documentation Update**: Added per-connection schema isolation details to `SKILL.md` for AI agents.
32
+ - Clarified schema storage layout in `.dbcli/schemas/`.
33
+ - Added usage examples for `--use <connection>` with schema commands.
34
+
35
+ ## [1.4.1] - 2026-04-21
25
36
 
26
37
  ## [1.3.0] - 2026-04-02
27
38
 
package/README.dev.md CHANGED
@@ -17,6 +17,14 @@ Before running `npm publish`:
17
17
  bun test --run unit/
18
18
  ```
19
19
 
20
+ For live database integration tests, use an explicit config path if needed:
21
+ ```bash
22
+ LIVE_DB_CONFIG_PATH=/path/to/.dbcli bun test tests/integration/live-db.test.ts
23
+ ```
24
+
25
+ If no live config is available, `tests/integration/live-db.test.ts` skips
26
+ instead of falling back to the default PostgreSQL configuration.
27
+
20
28
  3. **Update version in package.json:**
21
29
  ```bash
22
30
  npm version minor # Updates package.json version + creates git tag
@@ -101,6 +109,9 @@ Then publish a patch fix.
101
109
  - **Cross-platform support:** Shebang `#!/usr/bin/env bun` works on all platforms
102
110
  - macOS/Linux: Direct shebang execution
103
111
  - Windows: npm creates .cmd wrapper automatically (no manual creation needed)
112
+ - **Live integration tests:** `tests/integration/live-db.test.ts` reads `.dbcli/config.json`
113
+ by default or `LIVE_DB_CONFIG_PATH` when you need to point at another config
114
+ directory. Set `SKIP_INTEGRATION_TESTS=true` to skip all integration tests.
104
115
 
105
116
  ### Troubleshooting
106
117
 
package/README.md CHANGED
@@ -89,6 +89,23 @@ dbcli query "SELECT * FROM users"
89
89
  dbcli skill --install claude
90
90
  ```
91
91
 
92
+ ### MongoDB Atlas / SRV Connections
93
+
94
+ MongoDB connections are supported via both standard `mongodb://` URIs and Atlas-style `mongodb+srv://` URIs.
95
+
96
+ ```bash
97
+ # Atlas / SRV connection
98
+ dbcli init --system mongodb --conn-name atlas --uri "mongodb+srv://user:pass@cluster.example.mongodb.net/mydb"
99
+
100
+ # List collections in the configured MongoDB database
101
+ dbcli list --use atlas
102
+
103
+ # Query a collection with JSON filter or pipeline
104
+ dbcli query '{"status":"active"}' --collection users --use atlas
105
+ ```
106
+
107
+ For MongoDB, `list` and `query` operate on the database configured for the connection, and `query` requires `--collection <name>`.
108
+
92
109
  ---
93
110
 
94
111
  ## Multi-connection Support (v2)
@@ -637,6 +654,7 @@ dbcli doctor --format json # JSON output for AI agents
637
654
  - **Environment:** Bun version compatibility, dbcli version (compares with npm registry)
638
655
  - **Configuration:** Config file exists/valid, permission level, blacklist completeness
639
656
  - **Connection & Data:** Database connectivity, schema cache freshness (> 7 days warning), large table warnings (> 1M rows)
657
+ - **MongoDB SRV diagnostics:** For `mongodb+srv://` connections, `doctor` reports whether the current execution environment can resolve SRV records directly or only through the DNS-over-HTTPS fallback used by `dbcli`
640
658
 
641
659
  **Options:** `--format <text|json>`
642
660
  **Exit code:** 0 = all pass or warnings only, 1 = errors found
@@ -1236,6 +1254,17 @@ bun run test:docker # integration tests with docker-compose.test.yml (MySQ
1236
1254
  bun run build # bundle CLI to dist/ (used before publish)
1237
1255
  ```
1238
1256
 
1257
+ Live database integration tests use `.dbcli/config.json` by default. If your live
1258
+ config lives elsewhere, set `LIVE_DB_CONFIG_PATH=/path/to/.dbcli` before running:
1259
+
1260
+ ```bash
1261
+ LIVE_DB_CONFIG_PATH=/path/to/.dbcli bun test tests/integration/live-db.test.ts
1262
+ ```
1263
+
1264
+ If no live config is available, `tests/integration/live-db.test.ts` skips instead
1265
+ of falling back to the default PostgreSQL configuration. Set
1266
+ `SKIP_INTEGRATION_TESTS=true` to skip all integration tests.
1267
+
1239
1268
  See [CONTRIBUTING.md](./CONTRIBUTING.md) for full setup, testing, and release process.
1240
1269
 
1241
1270
  ---
package/README.zh-TW.md CHANGED
@@ -95,6 +95,23 @@ dbcli migrate create posts --column "id:int:pk" "title:varchar(100)"
95
95
  dbcli skill --install claude
96
96
  ```
97
97
 
98
+ ### MongoDB Atlas / SRV 連線
99
+
100
+ MongoDB 連線同時支援標準 `mongodb://` URI 與 Atlas 常用的 `mongodb+srv://` URI。
101
+
102
+ ```bash
103
+ # Atlas / SRV 連線
104
+ dbcli init --system mongodb --conn-name atlas --uri "mongodb+srv://user:pass@cluster.example.mongodb.net/mydb"
105
+
106
+ # 列出該 MongoDB 連線中的集合
107
+ dbcli list --use atlas
108
+
109
+ # 以 JSON filter 或 pipeline 查詢某個集合
110
+ dbcli query '{"status":"active"}' --collection users --use atlas
111
+ ```
112
+
113
+ 對 MongoDB 而言,`list` 與 `query` 會使用該連線設定中的資料庫;`query` 也必須指定 `--collection <名稱>`。
114
+
98
115
  ---
99
116
 
100
117
  ## 多重連線支援 (v2)
@@ -647,6 +664,7 @@ dbcli doctor --format json # JSON 輸出(供 AI 代理)
647
664
  - **環境:** Bun 版本相容性、dbcli 版本(與 npm registry 比對)
648
665
  - **設定:** 設定檔是否存在/有效、權限等級、黑名單完整性
649
666
  - **連線與資料:** 資料庫連線、schema 快取新鮮度(超過 7 天警告)、大表警告(超過 100 萬列)
667
+ - **MongoDB SRV 偵測:** 對 `mongodb+srv://` 連線,`doctor` 會回報目前執行環境能否直接解析 SRV 記錄,或只能依賴 dbcli 內建的 DNS-over-HTTPS fallback
650
668
 
651
669
  **選項:** `--format <text|json>`
652
670
  **結束代碼:** 0 = 全部通過或僅警告,1 = 有錯誤
@@ -1236,6 +1254,17 @@ bun run test:docker # 搭配 docker-compose.test.yml(MySQL + PostgreSQL
1236
1254
  bun run build # 建置 CLI 至 dist/(發布前使用)
1237
1255
  ```
1238
1256
 
1257
+ live DB 整合測試預設讀取 `.dbcli/config.json`。如果你的 live 設定放在其他位置,
1258
+ 可先指定 `LIVE_DB_CONFIG_PATH=/path/to/.dbcli` 再執行:
1259
+
1260
+ ```bash
1261
+ LIVE_DB_CONFIG_PATH=/path/to/.dbcli bun test tests/integration/live-db.test.ts
1262
+ ```
1263
+
1264
+ 如果沒有可用的 live config,`tests/integration/live-db.test.ts` 會直接 skip,
1265
+ 不再回退到預設 PostgreSQL 設定。若要跳過所有整合測試,可設定
1266
+ `SKIP_INTEGRATION_TESTS=true`。
1267
+
1239
1268
  完整環境、測試與發布流程見 [CONTRIBUTING.md](./CONTRIBUTING.md)。
1240
1269
 
1241
1270
  ---
package/assets/SKILL.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: dbcli
3
- description: Database CLI for AI agents with permission-based access control. Use to query, inspect schemas, insert/update/delete data, export results, and manage sensitive data blacklists. Supports MySQL, PostgreSQL, MariaDB with multiple named connections per project and custom env files. Trigger when working with databases, running SQL, exploring table structures, switching between database environments, or protecting sensitive columns/tables from AI access.
3
+ description: Database CLI for AI agents with permission-based access control. Use to query, inspect schemas, insert/update/delete data, export results, and manage sensitive data blacklists. Supports MySQL, PostgreSQL, MariaDB, and MongoDB with multiple named connections per project and custom env files. Trigger when working with databases, running SQL or MongoDB JSON queries, exploring table/collection structures, switching between database environments, or protecting sensitive columns/tables from AI access.
4
4
  ---
5
5
 
6
6
  # dbcli
@@ -27,6 +27,11 @@ dbcli init --system mysql --host localhost --port 3306 --user root --name mydb
27
27
  dbcli init --use-env-refs # Store env var references
28
28
  dbcli init --no-interactive --force # Non-interactive mode
29
29
 
30
+ # MongoDB
31
+ dbcli init --system mongodb --uri "mongodb://user:pass@host:27017/mydb?authSource=admin"
32
+ dbcli init --system mongodb --host localhost --port 27017 --user admin --password secret --name mydb
33
+ dbcli init --system mongodb --host localhost --port 27017 --name mydb # No auth
34
+
30
35
  # Multi-connection (v2 format)
31
36
  dbcli init --conn-name staging --env-file .env.staging # Named connection with custom env file
32
37
  dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-test
@@ -36,6 +41,8 @@ dbcli init --rename staging:production # Rename a connection
36
41
 
37
42
  **Key options:** `--system`, `--permission`, `--use-env-refs`, `--skip-test`, `--no-interactive`, `--force`, `--conn-name <name>`, `--env-file <path>`, `--remove <name>`, `--rename <old:new>`
38
43
 
44
+ **MongoDB-specific options:** `--uri <uri>` (full connection URI), `--auth-source <db>` (auth database, default: `admin` when user/password set)
45
+
39
46
  **Multi-connection:** Using `--conn-name` or `--env-file` creates a v2 config with named connections. Each connection can have its own env file and permission level. Existing v1 configs are automatically imported as the `default` connection when upgrading.
40
47
 
41
48
  > **AI agent note on `--use-env-refs`:** If an existing `.dbcli` config contains `{"$env": "DB_HOST"}` style references, the connection values are read from environment variables at runtime. Do NOT re-run `init` to replace these references with actual values — the env-ref format is intentional for CI/CD and multi-environment setups.
@@ -61,7 +68,7 @@ dbcli list --use prod
61
68
 
62
69
  ### list
63
70
 
64
- List all tables.
71
+ List all tables (SQL) or collections (MongoDB).
65
72
 
66
73
  ```bash
67
74
  dbcli list
@@ -70,6 +77,8 @@ dbcli list --format json
70
77
 
71
78
  **Permission:** query-only+
72
79
 
80
+ > **MongoDB:** Lists collections with estimated document count instead of tables.
81
+
73
82
  ### schema
74
83
 
75
84
  Display table schema or scan entire database.
@@ -94,17 +103,30 @@ dbcli schema --use prod # Scan prod DB; saves to .dbcli/schemas/prod
94
103
 
95
104
  ### query
96
105
 
97
- Execute SQL query.
106
+ Execute SQL query (MySQL/PostgreSQL/MariaDB) or JSON filter/pipeline (MongoDB).
98
107
 
99
108
  ```bash
109
+ # SQL databases
100
110
  dbcli query "SELECT * FROM users LIMIT 10"
101
111
  dbcli query "SELECT id, email FROM users" --format json
102
112
  dbcli query "SELECT * FROM logs" --no-limit
113
+
114
+ # MongoDB: JSON filter (find)
115
+ dbcli query '{"status": "active"}' --collection users
116
+ dbcli query '{"age": {"$gt": 18}}' --collection users --format json
117
+
118
+ # MongoDB: aggregation pipeline
119
+ dbcli query '[{"$match": {"status": "active"}}, {"$group": {"_id": "$role", "count": {"$sum": 1}}}]' --collection users
103
120
  ```
104
121
 
105
- **Options:** `--format <table|json|csv>`, `--limit <number>`, `--no-limit`
122
+ **Options:** `--format <table|json|csv>`, `--limit <number>`, `--no-limit`, `--collection <name>` (MongoDB only)
106
123
  **Permission:** query-only+
107
124
 
125
+ > **MongoDB notes:**
126
+ > - SQL syntax is rejected — use JSON object (filter) or JSON array (pipeline)
127
+ > - `--collection <name>` is required
128
+ > - Auto-limit does not apply; use `$limit` in your pipeline if needed
129
+
108
130
  ### insert
109
131
 
110
132
  Insert data into a table.
@@ -226,6 +248,8 @@ dbcli doctor --format json # JSON output for AI agents
226
248
  - Configuration: config file exists/valid, permission level, blacklist completeness (detects unprotected sensitive columns)
227
249
  - Connection & Data: database connectivity, schema cache freshness (warns if > 7 days), large table warnings (> 1M rows)
228
250
 
251
+ > **MongoDB SRV diagnostics:** When the active connection uses `mongodb+srv://`, `doctor` reports whether the current runtime can resolve SRV records directly or only through the DNS-over-HTTPS fallback used by dbcli. This helps spot execution-environment DNS restrictions even when Compass can connect.
252
+
229
253
  **Exit code:** 0 if all pass or warnings only, 1 if any error
230
254
  **Options:** `--format <text|json>`
231
255
 
@@ -325,6 +349,40 @@ dbcli migrate drop-enum status --execute --force
325
349
 
326
350
  **AI agent note:** Always use dry-run first (no `--execute`) to preview generated SQL. Only add `--execute` after confirming the SQL is correct. For DROP operations, both `--execute` and `--force` are required.
327
351
 
352
+ ## MongoDB Support
353
+
354
+ MongoDB connections use a JSON-based query model instead of SQL.
355
+
356
+ Atlas-style `mongodb+srv://` URIs are supported. `list` and `query` run against the database configured for the connection, and `query` always requires `--collection <name>`.
357
+
358
+ **Supported commands:** `init`, `list`, `query`, `status`, `use`, `shell`, `doctor`, `upgrade`, `completion`
359
+
360
+ **Not supported (exit with error):** `schema`, `insert`, `update`, `delete`, `export`, `diff`, `migrate`, `check`
361
+
362
+ ### MongoDB-specific workflow
363
+
364
+ ```bash
365
+ # 1. Initialize (URI or individual params)
366
+ dbcli init --system mongodb --uri "mongodb+srv://user:pass@cluster.example.mongodb.net/mydb"
367
+
368
+ # 2. List collections
369
+ dbcli list --format json
370
+
371
+ # 3. Query with JSON filter (find) or pipeline (aggregate)
372
+ dbcli query '{}' --collection orders --format json # All documents
373
+ dbcli query '{"status": "paid"}' --collection orders # Filter
374
+ dbcli query '[{"$match": {"status":"paid"}}, {"$count":"total"}]' --collection orders # Pipeline
375
+ ```
376
+
377
+ ### Query syntax
378
+
379
+ | Intent | Syntax |
380
+ |--------|--------|
381
+ | All documents | `'{}'` |
382
+ | Field filter | `'{"field": "value"}'` |
383
+ | Comparison | `'{"age": {"$gt": 18}}'` |
384
+ | Aggregation | `'[{"$match": {...}}, {"$group": {...}}]'` |
385
+
328
386
  ## Permission Levels
329
387
 
330
388
  | Level | Allowed Operations |