@carllee1983/dbcli 1.4.0 → 1.5.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 CHANGED
@@ -5,6 +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.5.0] - 2026-04-21
9
+
10
+ ### Added
11
+
12
+ - **Layered Schema Cache (Wave 1)**: Integrated file-based persistence for database schemas.
13
+ - New `SchemaWriter` for saving schema snapshots to `.dbcli/schemas/`.
14
+ - Layered schema loading (Hot/Cold) integrated into `configModule`.
15
+ - Per-connection isolation: Each connection now has its own schema directory (`.dbcli/schemas/<connection>/`).
16
+ - **Improved Migration UX**: Added proactive hints during schema migration to ensure data consistency.
17
+ - **Documentation Update**: Added per-connection schema isolation details to `SKILL.md` for AI agents.
18
+ - Clarified schema storage layout in `.dbcli/schemas/`.
19
+ - Added usage examples for `--use <connection>` with schema commands.
20
+
21
+ ## [1.4.1] - 2026-04-21
22
+
8
23
  ## [1.3.0] - 2026-04-02
9
24
 
10
25
  ### Added
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
@@ -1236,6 +1236,17 @@ bun run test:docker # integration tests with docker-compose.test.yml (MySQ
1236
1236
  bun run build # bundle CLI to dist/ (used before publish)
1237
1237
  ```
1238
1238
 
1239
+ Live database integration tests use `.dbcli/config.json` by default. If your live
1240
+ config lives elsewhere, set `LIVE_DB_CONFIG_PATH=/path/to/.dbcli` before running:
1241
+
1242
+ ```bash
1243
+ LIVE_DB_CONFIG_PATH=/path/to/.dbcli bun test tests/integration/live-db.test.ts
1244
+ ```
1245
+
1246
+ If no live config is available, `tests/integration/live-db.test.ts` skips instead
1247
+ of falling back to the default PostgreSQL configuration. Set
1248
+ `SKIP_INTEGRATION_TESTS=true` to skip all integration tests.
1249
+
1239
1250
  See [CONTRIBUTING.md](./CONTRIBUTING.md) for full setup, testing, and release process.
1240
1251
 
1241
1252
  ---
package/README.zh-TW.md CHANGED
@@ -1236,6 +1236,17 @@ bun run test:docker # 搭配 docker-compose.test.yml(MySQL + PostgreSQL
1236
1236
  bun run build # 建置 CLI 至 dist/(發布前使用)
1237
1237
  ```
1238
1238
 
1239
+ live DB 整合測試預設讀取 `.dbcli/config.json`。如果你的 live 設定放在其他位置,
1240
+ 可先指定 `LIVE_DB_CONFIG_PATH=/path/to/.dbcli` 再執行:
1241
+
1242
+ ```bash
1243
+ LIVE_DB_CONFIG_PATH=/path/to/.dbcli bun test tests/integration/live-db.test.ts
1244
+ ```
1245
+
1246
+ 如果沒有可用的 live config,`tests/integration/live-db.test.ts` 會直接 skip,
1247
+ 不再回退到預設 PostgreSQL 設定。若要跳過所有整合測試,可設定
1248
+ `SKIP_INTEGRATION_TESTS=true`。
1249
+
1239
1250
  完整環境、測試與發布流程見 [CONTRIBUTING.md](./CONTRIBUTING.md)。
1240
1251
 
1241
1252
  ---
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,35 +77,56 @@ 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.
76
85
 
77
86
  ```bash
78
- dbcli schema # Scan all tables, save to .dbcli
87
+ dbcli schema # Scan all tables, save to .dbcli/schemas/
79
88
  dbcli schema users # Show single table schema
80
89
  dbcli schema users --format json
81
90
  dbcli schema --refresh # Detect and apply schema changes
82
91
  dbcli schema --reset # Clear all schema data and re-fetch
83
92
  dbcli schema --reset --force # Skip confirmation
93
+
94
+ # Per-connection schema isolation (v2 multi-connection config)
95
+ dbcli schema --use staging # Scan staging DB; saves to .dbcli/schemas/staging/
96
+ dbcli schema --use prod # Scan prod DB; saves to .dbcli/schemas/prod/
84
97
  ```
85
98
 
86
- **Options:** `--format <table|json>`, `--refresh`, `--reset`, `--force`
99
+ **Options:** `--format <table|json>`, `--refresh`, `--reset`, `--force`, `--use <connection>`
87
100
  **Permission:** query-only+
88
101
 
102
+ **Schema storage (v1.4+):** Schema is persisted as layered files under `.dbcli/schemas/`. With v2 multi-connection config each connection gets its own subdirectory (`.dbcli/schemas/<connection>/`). Run `dbcli schema --use <connection>` once per connection before querying it — otherwise `schema <table>` may return data from the wrong connection's cache.
103
+
89
104
  ### query
90
105
 
91
- Execute SQL query.
106
+ Execute SQL query (MySQL/PostgreSQL/MariaDB) or JSON filter/pipeline (MongoDB).
92
107
 
93
108
  ```bash
109
+ # SQL databases
94
110
  dbcli query "SELECT * FROM users LIMIT 10"
95
111
  dbcli query "SELECT id, email FROM users" --format json
96
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
97
120
  ```
98
121
 
99
- **Options:** `--format <table|json|csv>`, `--limit <number>`, `--no-limit`
122
+ **Options:** `--format <table|json|csv>`, `--limit <number>`, `--no-limit`, `--collection <name>` (MongoDB only)
100
123
  **Permission:** query-only+
101
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
+
102
130
  ### insert
103
131
 
104
132
  Insert data into a table.
@@ -319,6 +347,38 @@ dbcli migrate drop-enum status --execute --force
319
347
 
320
348
  **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.
321
349
 
350
+ ## MongoDB Support
351
+
352
+ MongoDB connections use a JSON-based query model instead of SQL.
353
+
354
+ **Supported commands:** `init`, `list`, `query`, `status`, `use`, `shell`, `doctor`, `upgrade`, `completion`
355
+
356
+ **Not supported (exit with error):** `schema`, `insert`, `update`, `delete`, `export`, `diff`, `migrate`, `check`
357
+
358
+ ### MongoDB-specific workflow
359
+
360
+ ```bash
361
+ # 1. Initialize (URI or individual params)
362
+ dbcli init --system mongodb --uri "mongodb://localhost:27017/mydb"
363
+
364
+ # 2. List collections
365
+ dbcli list --format json
366
+
367
+ # 3. Query with JSON filter (find) or pipeline (aggregate)
368
+ dbcli query '{}' --collection orders --format json # All documents
369
+ dbcli query '{"status": "paid"}' --collection orders # Filter
370
+ dbcli query '[{"$match": {"status":"paid"}}, {"$count":"total"}]' --collection orders # Pipeline
371
+ ```
372
+
373
+ ### Query syntax
374
+
375
+ | Intent | Syntax |
376
+ |--------|--------|
377
+ | All documents | `'{}'` |
378
+ | Field filter | `'{"field": "value"}'` |
379
+ | Comparison | `'{"age": {"$gt": 18}}'` |
380
+ | Aggregation | `'[{"$match": {...}}, {"$group": {...}}]'` |
381
+
322
382
  ## Permission Levels
323
383
 
324
384
  | Level | Allowed Operations |