@carllee1983/dbcli 0.5.2-beta → 1.1.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 +108 -5
- package/README.md +73 -5
- package/assets/SKILL.md +72 -2
- package/dist/cli.mjs +46127 -44315
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,110 @@ 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.1.0] - 2026-03-30
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **Adapter `execute()` 回傳型別重構**: 從 `T[]` 改為 `ExecutionResult<T>`,包含 `rows`、`affectedRows`、`lastInsertId` 欄位,DML 操作(INSERT/UPDATE/DELETE)現在回傳正確的 affected rows 計數
|
|
13
|
+
- **Export 覆寫確認**: `export --output` 寫入已存在檔案時會提示確認,可用 `--force` 跳過
|
|
14
|
+
- **`ExecutionResult<T>` 介面**: 新增統一的查詢結果型別定義於 `src/adapters/types.ts`
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## [1.0.0] - 2026-03-28
|
|
19
|
+
|
|
20
|
+
### Stable Release
|
|
21
|
+
|
|
22
|
+
dbcli v1.0.0 is the first stable release. All three milestones are complete:
|
|
23
|
+
- **M1 (v0.6.0):** Smart REPL — interactive shell with SQL + dbcli commands
|
|
24
|
+
- **M2 (v0.8.0):** Schema DDL — CREATE/DROP/ALTER TABLE, INDEX, CONSTRAINT, ENUM
|
|
25
|
+
- **M3 (v1.0.0):** Stabilization — documentation, permission matrix, known limitations update
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- **`dbcli migrate` command group** (12 subcommands): Full DDL operations with cross-database support
|
|
30
|
+
- `migrate create <table>` — CREATE TABLE with `--column` spec format (`"id:serial:pk"`)
|
|
31
|
+
- `migrate drop <table>` — DROP TABLE with double confirmation (`--execute --force`)
|
|
32
|
+
- `migrate add-column` / `drop-column` / `alter-column` — Column management
|
|
33
|
+
- `migrate add-index` / `drop-index` — Index management (MySQL `--table` option for DROP)
|
|
34
|
+
- `migrate add-constraint` / `drop-constraint` — FK, UNIQUE, CHECK constraints
|
|
35
|
+
- `migrate add-enum` / `alter-enum` / `drop-enum` — PostgreSQL native ENUM support
|
|
36
|
+
- **DDLGenerator interface** with PostgreSQL and MySQL/MariaDB dialect implementations
|
|
37
|
+
- PostgreSQL: SERIAL, native ENUM types, ALTER COLUMN TYPE, double-quote identifiers
|
|
38
|
+
- MySQL: AUTO_INCREMENT, inline ENUM, MODIFY COLUMN, backtick identifiers
|
|
39
|
+
- **DDLExecutor**: Unified execution pipeline — admin permission check → blacklist protection → SQL generation → dry-run/execute → schema cache auto-refresh
|
|
40
|
+
- **Default dry-run for DDL**: All `migrate` commands preview SQL without `--execute`. Destructive operations also require `--force`
|
|
41
|
+
- **142 new tests**: column-parser (17), PG DDL (35), MySQL DDL (25), factory (5), DDL executor (22), schema cache DDL (6), CLI migrate (26), live-db migrate lifecycle (6)
|
|
42
|
+
|
|
43
|
+
### Fixed
|
|
44
|
+
|
|
45
|
+
- **Schema comment encoding**: Fixed double-encoded UTF-8 comments from MySQL/MariaDB `information_schema` (e.g., `帳號` → `帳號`)
|
|
46
|
+
- **MySQL connection charset**: Added `charset: utf8mb4` and `SET NAMES utf8mb4`
|
|
47
|
+
- **DDL multi-line SQL execution**: Fixed statement splitting to use `;\n` instead of `\n`
|
|
48
|
+
- **MySQL DROP INDEX**: Added `--table` option (MariaDB requires `ON <table>`)
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- **Permission model**: 4 levels — query-only, read-write, data-admin, admin (DDL requires admin)
|
|
53
|
+
- **Known Limitations**: Removed "Read-only schema" and "CLI-only" (both resolved). Added "No migration version tracking" as post-v1.0 item
|
|
54
|
+
- **Test infrastructure**: `docker-compose.test.yml` for MySQL 8 + PostgreSQL 16 integration testing
|
|
55
|
+
- **Package scripts**: Added `test:unit`, `test:integration`, `test:docker`
|
|
56
|
+
- **SKILL.md**: Updated with full `migrate` command reference and AI agent guidelines
|
|
57
|
+
|
|
58
|
+
### Test Results (v1.0.0)
|
|
59
|
+
|
|
60
|
+
- Unit/Core: 1082 pass, 0 fail
|
|
61
|
+
- Live DB (MariaDB 10.11): 61 pass
|
|
62
|
+
- Docker Adapter (MySQL 8 + PG 16): 18 pass
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## [0.6.1-beta] - 2026-03-28
|
|
67
|
+
|
|
68
|
+
### Encoding Fix & Test Infrastructure
|
|
69
|
+
|
|
70
|
+
### Fixed
|
|
71
|
+
|
|
72
|
+
- **Schema comment encoding**: Fixed double-encoded UTF-8 comments from MySQL/MariaDB `information_schema`. Comments stored through latin1 (cp1252) connections now correctly display CJK characters (e.g., `帳號` → `帳號`)
|
|
73
|
+
- **MySQL connection charset**: Added `charset: utf8mb4` and `SET NAMES utf8mb4` to MySQL adapter connections
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
|
|
77
|
+
- **`fixDoubleEncodedUtf8()` utility** (`src/utils/encoding.ts`): Detects and reverses cp1252-to-UTF-8 double encoding with full cp1252 reverse mapping table. Applied to schema comments in both MySQL and PostgreSQL adapters
|
|
78
|
+
- **`docker-compose.test.yml`**: MySQL 8.4 (port 3307) + PostgreSQL 16 (port 5433) for integration testing, with health checks and tmpfs for fast ephemeral storage
|
|
79
|
+
- **Environment-driven adapter tests**: `mysql.test.ts` and `postgresql.test.ts` now read connection from `MYSQL_*` / `PG_*` env vars, falling back to docker-compose defaults. Auto-skip when DB is unreachable
|
|
80
|
+
- **`live-db.test.ts`**: 55 comprehensive CLI-level integration tests covering all commands against live MariaDB — list, schema, query, blacklist CRUD, insert/update/delete lifecycle, export, check, diff, status, doctor, shell, format validation, SQL injection protection
|
|
81
|
+
- **New test scripts**: `test:unit`, `test:integration`, `test:docker` in package.json
|
|
82
|
+
|
|
83
|
+
### Test Results
|
|
84
|
+
|
|
85
|
+
- Unit/Core: 940 pass
|
|
86
|
+
- Live DB (MariaDB 10.11): 55 pass
|
|
87
|
+
- Adapter (Docker MySQL 8 + PG 16): 18 pass
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## [0.6.0-beta] - 2026-03-28
|
|
92
|
+
|
|
93
|
+
### Interactive Shell — Smart REPL
|
|
94
|
+
|
|
95
|
+
### Added
|
|
96
|
+
|
|
97
|
+
- **`dbcli shell` command:** Interactive database shell with SQL execution and dbcli command dispatch
|
|
98
|
+
- **SQL-only mode:** `--sql` flag restricts to SQL statements only
|
|
99
|
+
- **Auto-completion (Tab):** Context-aware completion for SQL keywords, table names, column names, and dbcli commands
|
|
100
|
+
- **Multi-line SQL:** Accumulates input until `;` is found, with `...>` continuation prompt
|
|
101
|
+
- **SQL syntax highlighting:** Real-time colorization of keywords, strings, and numbers in verbose mode
|
|
102
|
+
- **Meta commands:** `.help`, `.quit`/`.exit`, `.clear`, `.format`, `.history`, `.timing`
|
|
103
|
+
- **Persistent history:** Stored in `~/.dbcli_history` (max 1000 entries), with up/down navigation and Ctrl+R search
|
|
104
|
+
- **Permission & blacklist integration:** Full enforcement within REPL session — SQL goes through PermissionGuard, query results go through blacklist filtering
|
|
105
|
+
- **Auto-reconnect:** Attempts to reconnect once on connection errors, then displays error without crashing the session
|
|
106
|
+
- **Error resilience:** SQL/permission/connection errors never crash the session
|
|
107
|
+
- **i18n support:** All shell messages available in English and Traditional Chinese
|
|
108
|
+
- **102 new tests:** input-classifier (25), multiline-buffer (10), meta-commands (15), completer (17), history-manager (8), command-dispatcher (12), repl-engine (12), shell-command (3)
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
8
112
|
## [0.5.2-beta] - 2026-03-27
|
|
9
113
|
|
|
10
114
|
### Fixed
|
|
@@ -264,12 +368,11 @@ dbcli v0.1.0-beta is a complete, production-ready CLI tool enabling AI agents an
|
|
|
264
368
|
|
|
265
369
|
---
|
|
266
370
|
|
|
267
|
-
## Known Limitations
|
|
371
|
+
## Known Limitations
|
|
268
372
|
|
|
269
|
-
- **Single database per project:**
|
|
270
|
-
- **No audit logging:** WHO/WHAT/WHEN tracking deferred to
|
|
271
|
-
- **
|
|
272
|
-
- **CLI-only:** No visual schema designer, REPL, or interactive shell in V1
|
|
373
|
+
- **Single database per project:** Each directory uses one `.dbcli` config. For multi-database setups, use separate directories or `--config` flag. This is by design, not a technical limitation.
|
|
374
|
+
- **No audit logging:** WHO/WHAT/WHEN tracking deferred to post-v1.0
|
|
375
|
+
- **No migration version tracking:** `migrate` commands execute DDL directly without version history or rollback. The `migrate` namespace is reserved for future migration tracking support.
|
|
273
376
|
|
|
274
377
|
---
|
|
275
378
|
|
package/README.md
CHANGED
|
@@ -519,6 +519,72 @@ dbcli upgrade --check # Only check, do not upgrade
|
|
|
519
519
|
**Options:** `--check` — check only, don't install
|
|
520
520
|
**Background check:** dbcli silently checks npm registry once per 24 hours. If a newer version is found, a hint is shown after command output.
|
|
521
521
|
|
|
522
|
+
#### `dbcli shell`
|
|
523
|
+
|
|
524
|
+
Interactive database shell with SQL execution, auto-completion, and syntax highlighting.
|
|
525
|
+
|
|
526
|
+
**Usage:**
|
|
527
|
+
```bash
|
|
528
|
+
dbcli shell # Interactive mode (SQL + dbcli commands)
|
|
529
|
+
dbcli shell --sql # SQL-only mode
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
**Inside the shell:**
|
|
533
|
+
- Type SQL statements ending with `;` to execute queries
|
|
534
|
+
- Type dbcli commands without the `dbcli` prefix (e.g., `schema users`, `list`)
|
|
535
|
+
- Press Tab for context-aware auto-completion (SQL keywords, table/column names)
|
|
536
|
+
- Use `.help` for meta commands (`.quit`, `.clear`, `.format`, `.history`, `.timing`)
|
|
537
|
+
- Multi-line SQL: input accumulates until `;` is found
|
|
538
|
+
- History persists across sessions in `~/.dbcli_history`
|
|
539
|
+
|
|
540
|
+
**Permission:** Inherits from config. SQL and commands are fully permission/blacklist enforced.
|
|
541
|
+
|
|
542
|
+
#### `dbcli migrate`
|
|
543
|
+
|
|
544
|
+
Schema DDL operations. **All commands default to dry-run** — use `--execute` to actually run the SQL.
|
|
545
|
+
|
|
546
|
+
**Usage:**
|
|
547
|
+
```bash
|
|
548
|
+
# Create table
|
|
549
|
+
dbcli migrate create posts \
|
|
550
|
+
--column "id:serial:pk" \
|
|
551
|
+
--column "title:varchar(200):not-null" \
|
|
552
|
+
--column "body:text" \
|
|
553
|
+
--column "created_at:timestamp:default=now()"
|
|
554
|
+
|
|
555
|
+
# Execute (actually run the SQL)
|
|
556
|
+
dbcli migrate create posts --column "id:serial:pk" --execute
|
|
557
|
+
|
|
558
|
+
# Drop table (destructive — requires --execute --force)
|
|
559
|
+
dbcli migrate drop posts --execute --force
|
|
560
|
+
|
|
561
|
+
# Column operations
|
|
562
|
+
dbcli migrate add-column users bio text --nullable --execute
|
|
563
|
+
dbcli migrate alter-column users name --type "varchar(200)" --execute
|
|
564
|
+
dbcli migrate alter-column users email --rename user_email --execute
|
|
565
|
+
dbcli migrate drop-column users temp_field --execute --force
|
|
566
|
+
|
|
567
|
+
# Index operations
|
|
568
|
+
dbcli migrate add-index users --columns email --unique --execute
|
|
569
|
+
dbcli migrate drop-index idx_users_email --table users --execute --force
|
|
570
|
+
|
|
571
|
+
# Constraint operations
|
|
572
|
+
dbcli migrate add-constraint orders --fk user_id --references users.id --on-delete cascade --execute
|
|
573
|
+
dbcli migrate add-constraint users --unique email --execute
|
|
574
|
+
dbcli migrate add-constraint users --check "age >= 0" --execute
|
|
575
|
+
dbcli migrate drop-constraint orders fk_orders_user_id --execute --force
|
|
576
|
+
|
|
577
|
+
# Enum (PostgreSQL only)
|
|
578
|
+
dbcli migrate add-enum status active inactive suspended --execute
|
|
579
|
+
dbcli migrate alter-enum status --add-value archived --execute
|
|
580
|
+
dbcli migrate drop-enum status --execute --force
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
**Column spec format:** `name:type[:modifier...]` — Modifiers: `pk`, `not-null`, `unique`, `auto-increment`, `default=<value>`, `references=<table>.<column>`
|
|
584
|
+
|
|
585
|
+
**Options (all subcommands):** `--execute` (run SQL), `--force` (skip confirmation for DROP), `--config <path>`
|
|
586
|
+
**Permission:** admin only
|
|
587
|
+
|
|
522
588
|
---
|
|
523
589
|
|
|
524
590
|
## Global Options
|
|
@@ -542,9 +608,10 @@ dbcli implements a coarse-grained permission system with three levels. Permissio
|
|
|
542
608
|
|
|
543
609
|
| Level | Allowed Commands | Blocked Commands | Use Case |
|
|
544
610
|
|-------|------------------|------------------|----------|
|
|
545
|
-
| **Query-only** | `init`, `list`, `schema`, `query`, `export` (limited to 1000 rows) | `insert`, `update`, `delete` | Read-only AI agents, data analysts, reporting |
|
|
546
|
-
| **Read-Write** | + `insert`, `update` | `delete` | Application developers, content managers |
|
|
547
|
-
| **Admin** |
|
|
611
|
+
| **Query-only** | `init`, `list`, `schema`, `query`, `export` (limited to 1000 rows) | `insert`, `update`, `delete`, `migrate` | Read-only AI agents, data analysts, reporting |
|
|
612
|
+
| **Read-Write** | + `insert`, `update` | `delete`, `migrate` | Application developers, content managers |
|
|
613
|
+
| **Data-Admin** | + `delete` | `migrate` | Full DML access, no DDL |
|
|
614
|
+
| **Admin** | All commands including `migrate` (DDL) | — | Database administrators, schema modifications |
|
|
548
615
|
|
|
549
616
|
### Configuration
|
|
550
617
|
|
|
@@ -583,11 +650,12 @@ dbcli delete users --where "id=1" # ERROR: Admin only
|
|
|
583
650
|
|
|
584
651
|
#### Admin Mode (Database Administrator)
|
|
585
652
|
```bash
|
|
586
|
-
# Allowed: Everything
|
|
653
|
+
# Allowed: Everything including DDL
|
|
587
654
|
dbcli query "SELECT * FROM users"
|
|
588
655
|
dbcli insert users --data '{"name": "Eve"}'
|
|
589
656
|
dbcli update users --where "id=1" --set '{"status": "active"}'
|
|
590
|
-
dbcli delete users --where "id=1" --force #
|
|
657
|
+
dbcli delete users --where "id=1" --force # Data-Admin+ can delete
|
|
658
|
+
dbcli migrate create posts --column "id:serial:pk" --execute # Admin only
|
|
591
659
|
```
|
|
592
660
|
|
|
593
661
|
### Best Practices
|
package/assets/SKILL.md
CHANGED
|
@@ -116,10 +116,11 @@ Export query results to file or stdout.
|
|
|
116
116
|
|
|
117
117
|
```bash
|
|
118
118
|
dbcli export "SELECT * FROM users" --format csv --output users.csv
|
|
119
|
+
dbcli export "SELECT * FROM users" --format csv --output users.csv --force # Skip overwrite confirmation
|
|
119
120
|
dbcli export "SELECT * FROM users" --format json | jq '.[]'
|
|
120
121
|
```
|
|
121
122
|
|
|
122
|
-
**Options:** `--format <json|csv>` (required), `--output <path
|
|
123
|
+
**Options:** `--format <json|csv>` (required), `--output <path>`, `--force`
|
|
123
124
|
**Permission:** query-only+
|
|
124
125
|
|
|
125
126
|
### blacklist
|
|
@@ -222,6 +223,75 @@ dbcli upgrade --check # Only check, do not upgrade
|
|
|
222
223
|
|
|
223
224
|
**Background check:** Every command silently checks the npm registry for a newer version (at most once per 24 hours, cached in `.dbcli/version-check.json`). If a newer version is found, a one-line hint is printed to stderr after the command completes. Pass `-q` / `--quiet` to suppress the hint.
|
|
224
225
|
|
|
226
|
+
### `dbcli shell`
|
|
227
|
+
|
|
228
|
+
Start an interactive database shell.
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
dbcli shell # Interactive mode with SQL + dbcli commands
|
|
232
|
+
dbcli shell --sql # SQL-only mode
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Inside the shell:
|
|
236
|
+
- Type SQL statements ending with `;` to execute
|
|
237
|
+
- Type dbcli commands without the `dbcli` prefix (e.g., `schema users`)
|
|
238
|
+
- Use Tab for auto-completion (SQL keywords, table names, column names)
|
|
239
|
+
- Type `.help` for meta commands (.quit, .clear, .format, .history, .timing)
|
|
240
|
+
- Multi-line SQL: keeps accumulating until `;` is found
|
|
241
|
+
- History persists across sessions (~/.dbcli_history)
|
|
242
|
+
|
|
243
|
+
### migrate
|
|
244
|
+
|
|
245
|
+
Schema DDL operations. **All commands default to dry-run** — use `--execute` to actually run the SQL. Destructive operations (DROP) also require `--force`.
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
# Create table
|
|
249
|
+
dbcli migrate create posts \
|
|
250
|
+
--column "id:serial:pk" \
|
|
251
|
+
--column "title:varchar(200):not-null" \
|
|
252
|
+
--column "body:text" \
|
|
253
|
+
--column "created_at:timestamp:default=now()"
|
|
254
|
+
|
|
255
|
+
# Drop table (dry-run by default)
|
|
256
|
+
dbcli migrate drop posts
|
|
257
|
+
dbcli migrate drop posts --execute --force # Actually drop
|
|
258
|
+
|
|
259
|
+
# Add/drop/alter column
|
|
260
|
+
dbcli migrate add-column users bio text --nullable
|
|
261
|
+
dbcli migrate drop-column users temp_field --execute --force
|
|
262
|
+
dbcli migrate alter-column users name --type "varchar(200)"
|
|
263
|
+
dbcli migrate alter-column users email --rename user_email
|
|
264
|
+
dbcli migrate alter-column users status --set-default "'active'"
|
|
265
|
+
dbcli migrate alter-column users bio --drop-default
|
|
266
|
+
dbcli migrate alter-column users bio --set-nullable
|
|
267
|
+
dbcli migrate alter-column users email --drop-nullable
|
|
268
|
+
|
|
269
|
+
# Index management
|
|
270
|
+
dbcli migrate add-index users --columns email --unique
|
|
271
|
+
dbcli migrate add-index users --columns "last_name,first_name" --name idx_fullname
|
|
272
|
+
dbcli migrate drop-index idx_fullname --execute --force
|
|
273
|
+
|
|
274
|
+
# Constraint management
|
|
275
|
+
dbcli migrate add-constraint orders --fk user_id --references users.id --on-delete cascade
|
|
276
|
+
dbcli migrate add-constraint users --unique email
|
|
277
|
+
dbcli migrate add-constraint users --check "age >= 0"
|
|
278
|
+
dbcli migrate drop-constraint orders fk_orders_user_id --execute --force
|
|
279
|
+
|
|
280
|
+
# Enum (PostgreSQL only — MySQL uses inline ENUM in column type)
|
|
281
|
+
dbcli migrate add-enum status active inactive suspended
|
|
282
|
+
dbcli migrate alter-enum status --add-value archived
|
|
283
|
+
dbcli migrate drop-enum status --execute --force
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Column spec format:** `name:type[:modifier[:modifier...]]`
|
|
287
|
+
- Modifiers: `pk`, `not-null`, `unique`, `auto-increment`, `default=<value>`, `references=<table>.<column>`
|
|
288
|
+
- Serial types: `serial`, `bigserial`, `smallserial` (auto-expand per DB dialect)
|
|
289
|
+
|
|
290
|
+
**Options (all subcommands):** `--execute`, `--force`, `--config <path>`
|
|
291
|
+
**Permission:** admin
|
|
292
|
+
|
|
293
|
+
**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.
|
|
294
|
+
|
|
225
295
|
## Permission Levels
|
|
226
296
|
|
|
227
297
|
| Level | Allowed Operations |
|
|
@@ -229,7 +299,7 @@ dbcli upgrade --check # Only check, do not upgrade
|
|
|
229
299
|
| query-only | SELECT, list, schema, export |
|
|
230
300
|
| read-write | query-only + INSERT, UPDATE |
|
|
231
301
|
| data-admin | read-write + DELETE (full DML, no DDL) |
|
|
232
|
-
| admin | data-admin + DROP, ALTER, CREATE, TRUNCATE |
|
|
302
|
+
| admin | data-admin + DDL (migrate create/drop/alter, DROP, ALTER, CREATE, TRUNCATE) |
|
|
233
303
|
|
|
234
304
|
Set via `dbcli init --permission <level>` or in `.dbcli` config.
|
|
235
305
|
|