@carllee1983/dbcli 1.51.2 → 1.52.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/.cursor/rules/dbcli.mdc +2 -2
- package/.cursor/skills/dbcli/reference.md +170 -1
- package/.github/skills/dbcli/SKILL.md +2 -2
- package/.github/skills/dbcli/reference.md +170 -1
- package/CHANGELOG.md +17 -0
- package/README.md +1 -0
- package/README.zh-TW.md +1 -0
- package/assets/SKILL.md +2 -2
- package/assets/reference.md +170 -1
- package/assets/tasks/design-review.md +42 -0
- package/dist/cli.mjs +790 -35
- package/dist/core.d.ts +8 -0
- package/package.json +4 -1
- package/plugins/dbcli-agent/skills/dbcli/SKILL.md +2 -2
- package/plugins/dbcli-agent/skills/dbcli/reference.md +170 -1
- package/skills/dbcli/SKILL.md +2 -2
- package/skills/dbcli/reference.md +170 -1
package/dist/core.d.ts
CHANGED
|
@@ -517,6 +517,12 @@ interface AppliedLimitMetadata {
|
|
|
517
517
|
limitApplied: number;
|
|
518
518
|
}
|
|
519
519
|
type SqlStatementType = "SELECT" | "INSERT" | "UPDATE" | "DELETE" | "UNKNOWN";
|
|
520
|
+
interface PerformanceAdvisory {
|
|
521
|
+
code: "SLOW_QUERY";
|
|
522
|
+
executionTimeMs: number;
|
|
523
|
+
thresholdMs: number;
|
|
524
|
+
recommendation: string;
|
|
525
|
+
}
|
|
520
526
|
interface QueryMetadata {
|
|
521
527
|
/** SQL statement type (SELECT, INSERT, UPDATE, DELETE) */
|
|
522
528
|
statement: SqlStatementType;
|
|
@@ -526,6 +532,8 @@ interface QueryMetadata {
|
|
|
526
532
|
executionTimeMs?: number;
|
|
527
533
|
/** Security notification when columns were omitted due to blacklist */
|
|
528
534
|
securityNotification?: string;
|
|
535
|
+
/** Passive suggestion derived from already-measured execution time. */
|
|
536
|
+
performanceAdvisory?: PerformanceAdvisory;
|
|
529
537
|
}
|
|
530
538
|
/**
|
|
531
539
|
* Generic query result wrapper with rows and metadata
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carllee1983/dbcli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.52.0",
|
|
4
4
|
"description": "Database CLI for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"test": "bun test --timeout 30000",
|
|
73
73
|
"test:unit": "bun test tests/unit tests/core",
|
|
74
74
|
"test:integration": "bun test tests/integration",
|
|
75
|
+
"test:gherkin": "bun test tests/gherkin",
|
|
75
76
|
"test:docker": "docker compose -f docker-compose.test.yml up -d --wait && bun test tests/integration/adapters; docker compose -f docker-compose.test.yml down",
|
|
76
77
|
"docs:check": "bun run scripts/check-user-docs.ts",
|
|
77
78
|
"contract:check": "bun run scripts/check-cli-contract.ts",
|
|
@@ -102,6 +103,8 @@
|
|
|
102
103
|
"zod": "^3.25.76"
|
|
103
104
|
},
|
|
104
105
|
"devDependencies": {
|
|
106
|
+
"@cucumber/gherkin": "^42.0.1",
|
|
107
|
+
"@cucumber/messages": "^34.2.1",
|
|
105
108
|
"@eslint/js": "^9.39.4",
|
|
106
109
|
"@happy-dom/global-registrator": "^20.10.6",
|
|
107
110
|
"@inquirer/prompts": "^8.4.3",
|
|
@@ -381,11 +381,11 @@ Full flags and edge cases: see [reference.md](reference.md) `init` section.
|
|
|
381
381
|
| `use` | n/a | Show/switch default named connection (v2 only). |
|
|
382
382
|
| `list` | query-only+ | Tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch). |
|
|
383
383
|
| `schema` | query-only+ | SQL: per-table or full scan into `.dbcli/schemas/`. MongoDB: sampled. ES: flattened mapping. Redis: per-key only (type/TTL/size). Supports `--recovery`. |
|
|
384
|
-
| `query` | query-only+ | SQL, Mongo JSON (`--collection`), Redis command, or ES DSL/Lucene (`--collection`). `--format table\|json\|csv\|html`, `--ui` to open the interactive dashboard in a browser. `--fields` (projection), `--truncate` (cell width), `-f/--query-file` (read query from file or stdin), `--use a,b` (read-only fan-out). Supports `--recovery`. See **Query workflow flags**. |
|
|
384
|
+
| `query` | query-only+ | SQL, Mongo JSON (`--collection`), Redis command, or ES DSL/Lucene (`--collection`). `--format table\|json\|csv\|html`, `--ui` to open the interactive dashboard in a browser. `--fields` (projection), `--truncate` (cell width), `-f/--query-file` (read query from file or stdin), `--use a,b` (read-only fan-out). Supports `--recovery`. `--slow-ms <n>` sets the passive slow-query hint threshold (default 1000, `0` off): at or above it, table output gains a `Performance hint` footer and JSON gains `metadata.performanceAdvisory`; it runs no extra diagnostics and is suppressed under `--recovery`. Distinct from the `proxy` flag of the same name. See **Query workflow flags**. |
|
|
385
385
|
| `explain` | query-only+ | **(v1.23)** Read-only query plan with annotations. SQL only. Single query, `@saved-query`, `@file.sql`, or `--bulk @glob/*`. `--analyze` (EXPLAIN ANALYZE / MariaDB ANALYZE SELECT), `--format markdown\|json\|table`. |
|
|
386
386
|
| `lint` | n/a | Static SQL anti-pattern advisor (no DB connection). 9 rules incl. schema-aware implicit-cast / NOT IN-nullable checks via the layered `.dbcli/schemas/` cache; global `--use <conn>` selects a named cache. Findings carry rewrite drafts + guarded `explain` verify commands (`--analyze` only for proven read-only SQL) — report-only, never executes. `--format text\|json\|markdown`, `--min-severity`, `--no-schema`, `--bulk`. Supports `--recovery`. |
|
|
387
387
|
| `plan` | n/a | Static SQL risk analyzer (`--format text\|json`); classifies a statement without connecting to the database. |
|
|
388
|
-
| `q` | query-only+ | Run a saved snippet by `@name` with `--param k=v`. Supports `--verify` to run assertions. |
|
|
388
|
+
| `q` | query-only+ | Run a saved snippet by `@name` with `--param k=v`. Supports `--verify` to run assertions and `--slow-ms <n>` (same passive slow-query hint as `query`). |
|
|
389
389
|
| `queries` | n/a | Manage saved snippets: `list` / `show` / `search` / `suggest` / `new` / `edit` / `check` / `delete` / `rename` / `copy` / `import` / `export`. |
|
|
390
390
|
| `insert` / `update` | read-write+ | SQL or MongoDB only. JSON `--data` / `--set`; `--where` required on `update`; `--dry-run` first. Redis writes go through `query`. Supports `--recovery`. |
|
|
391
391
|
| `delete` | data-admin+ | SQL or MongoDB; Redis has a basic implementation (see Redis section). `--where` required; `--dry-run` first. Supports `--recovery`. |
|
|
@@ -220,9 +220,44 @@ dbcli query "SELECT day, dau FROM dau_daily" --ui # open in brows
|
|
|
220
220
|
dbcli query "SELECT * FROM orders" --format html > orders.html # pipe to stdout
|
|
221
221
|
```
|
|
222
222
|
|
|
223
|
-
**Options:** `--format <table|json|csv|html>`, `--ui` (open the dashboard in the system browser; implies `--format html`), `--limit <number>`, `--no-limit`, `--collection <name>` (MongoDB / Elasticsearch), `--index <name>` (Elasticsearch alias for `--collection`), `--fields <list>`, `--truncate <number>` / `--no-truncate`, `-f, --query-file <path>`, `--use <name[,name]>`, `--recovery`
|
|
223
|
+
**Options:** `--format <table|json|csv|html>`, `--ui` (open the dashboard in the system browser; implies `--format html`), `--limit <number>`, `--no-limit`, `--collection <name>` (MongoDB / Elasticsearch), `--index <name>` (Elasticsearch alias for `--collection`), `--fields <list>`, `--truncate <number>` / `--no-truncate`, `-f, --query-file <path>`, `--use <name[,name]>`, `--slow-ms <number>`, `--recovery`
|
|
224
224
|
**Permission:** query-only+ (Redis: per-command; Elasticsearch: per HTTP method/path)
|
|
225
225
|
|
|
226
|
+
#### Passive slow-query hint (`--slow-ms`)
|
|
227
|
+
|
|
228
|
+
`query` and `q` read the execution time they already measured for a finished
|
|
229
|
+
query and, at or above the threshold, add a hint. Default `1000`; `--slow-ms 0`
|
|
230
|
+
disables it for that invocation. This is **not** the `proxy` / `proxy analyze`
|
|
231
|
+
flag of the same name — that one flags events in the proxy log; this one only
|
|
232
|
+
annotates a single command's own result.
|
|
233
|
+
|
|
234
|
+
The hint performs no extra work: it never runs `EXPLAIN`, reads a schema, or
|
|
235
|
+
issues a second request. It is suppressed entirely under `--recovery`, so the
|
|
236
|
+
recovery envelope keeps its exact machine contract.
|
|
237
|
+
|
|
238
|
+
- `--format table` appends `Performance hint: <recommendation>` to the footer.
|
|
239
|
+
- `--format json` adds `metadata.performanceAdvisory`:
|
|
240
|
+
|
|
241
|
+
```json
|
|
242
|
+
{
|
|
243
|
+
"metadata": {
|
|
244
|
+
"statement": "SELECT",
|
|
245
|
+
"performanceAdvisory": {
|
|
246
|
+
"code": "SLOW_QUERY",
|
|
247
|
+
"executionTimeMs": 1250,
|
|
248
|
+
"thresholdMs": 1000,
|
|
249
|
+
"recommendation": "Review safely with: dbcli guide slow-query --format markdown. This hint runs no additional database diagnostics."
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
The recommendation is engine-aware: PostgreSQL, MySQL, MariaDB, and Redis are
|
|
256
|
+
pointed at `dbcli guide slow-query`, because that goal resolves to real
|
|
257
|
+
diagnostic snippets for them. MongoDB and Elasticsearch ship no snippet for its
|
|
258
|
+
intents, so their hint states the timing and says so instead of naming a command
|
|
259
|
+
that would come back empty. `csv` and `html` output are unchanged.
|
|
260
|
+
|
|
226
261
|
Below `admin`, SQL holding more than one statement is rejected, because only the
|
|
227
262
|
first statement would decide the permission check while a driver on the simple
|
|
228
263
|
query protocol executes them all. Semicolons inside string literals, backtick
|
|
@@ -529,6 +564,7 @@ dbcli q @analytics/revenue --param days=30 --format html > report.html
|
|
|
529
564
|
- `--no-limit` — skip the `SELECT * FROM (…) AS _dbcli_guard LIMIT 1000` wrap
|
|
530
565
|
- `--dry-run` — print the bound SQL + values without executing
|
|
531
566
|
- `--use <name>` — pick a v2 named connection
|
|
567
|
+
- `--slow-ms <number>` — passive slow-query hint threshold (default `1000`; `0` disables). Same contract as `query` — see "Passive slow-query hint" there
|
|
532
568
|
- `--recovery` — emit a `RecoveryEnvelope` on failure (see `recover`)
|
|
533
569
|
- `--verify` — run the snippet's verification assertions after execution (only if the snippet defines them)
|
|
534
570
|
|
|
@@ -1077,6 +1113,139 @@ Both parameters are required. Keep each expansion as one quoted shell argument;
|
|
|
1077
1113
|
never use `eval`, and consider `--execute` only after the plan and captured DDL
|
|
1078
1114
|
have been reviewed.
|
|
1079
1115
|
|
|
1116
|
+
### design
|
|
1117
|
+
|
|
1118
|
+
Author, validate, render, and review a version-controlled SQL database design
|
|
1119
|
+
kept beside the code as `dbcli.design.json`. Every subcommand is offline: none
|
|
1120
|
+
opens a database connection, executes DDL, or calls an LLM. `design init` is the
|
|
1121
|
+
only writer, and it writes only to the explicit `--output` path.
|
|
1122
|
+
|
|
1123
|
+
```text
|
|
1124
|
+
dbcli design init --output <path> [--dialect <dialect>]
|
|
1125
|
+
dbcli design validate [--file <path>] [--format <format>]
|
|
1126
|
+
dbcli design render [--file <path>] [--format <format>]
|
|
1127
|
+
dbcli design diff (--against-cache | --against-orm <paths>) [options]
|
|
1128
|
+
dbcli design propose (--against-cache | --against-orm <paths>) [options]
|
|
1129
|
+
```
|
|
1130
|
+
|
|
1131
|
+
```bash
|
|
1132
|
+
# Writes only to this explicit, missing path; edit the starter before validating.
|
|
1133
|
+
dbcli design init --output ./dbcli.design.json --dialect postgresql
|
|
1134
|
+
|
|
1135
|
+
dbcli design validate --format json
|
|
1136
|
+
dbcli design render --format mermaid
|
|
1137
|
+
dbcli design diff --against-cache --format markdown
|
|
1138
|
+
dbcli design diff --against-orm ./prisma/schema.prisma --format markdown
|
|
1139
|
+
dbcli design propose --against-orm ./prisma/schema.prisma --format markdown
|
|
1140
|
+
```
|
|
1141
|
+
|
|
1142
|
+
| Option | Applies to | Default | Meaning |
|
|
1143
|
+
|---|---|---|---|
|
|
1144
|
+
| `--output <path>` | `init` | required | Destination for the new artifact; refuses to overwrite an existing file. |
|
|
1145
|
+
| `--dialect <postgresql\|mysql\|mariadb>` | `init` | `postgresql` | Target SQL dialect recorded in the artifact. |
|
|
1146
|
+
| `--file <path>` | all but `init` | `dbcli.design.json` | Design artifact to read. |
|
|
1147
|
+
| `--format <format>` | all but `init` | see below | `validate`/`propose`: `json`, `markdown`. `render`: `json`, `markdown`, `mermaid` (default `markdown`). `diff`: `json` (default), `table`, `markdown`. |
|
|
1148
|
+
| `--against-cache` | `diff`, `propose` | off | Compare with the local schema cache; requires a configured PostgreSQL/MySQL/MariaDB connection whose system matches the artifact dialect, and a non-empty cache (run `dbcli schema` first). |
|
|
1149
|
+
| `--against-orm <paths>` | `diff`, `propose` | none | Compare with local ORM definition(s); repeatable or comma-separated, DDL paths support globs. Needs no config and no connection. |
|
|
1150
|
+
| `--orm-format <format>` | `diff`, `propose` | auto-detect | Force `prisma`, `ddl`, `json`, `drizzle`, `typeorm`, or `sequelize`. |
|
|
1151
|
+
| `--ignore <globs>` | `diff`, `propose` | none | Comma-separated table globs excluded from drift. |
|
|
1152
|
+
|
|
1153
|
+
`diff` and `propose` require **exactly one** comparison target; passing both or
|
|
1154
|
+
neither is an error.
|
|
1155
|
+
|
|
1156
|
+
#### Artifact shape
|
|
1157
|
+
|
|
1158
|
+
```json
|
|
1159
|
+
{
|
|
1160
|
+
"version": 1,
|
|
1161
|
+
"dialect": "postgresql",
|
|
1162
|
+
"models": [
|
|
1163
|
+
{
|
|
1164
|
+
"name": "orders",
|
|
1165
|
+
"table": "orders",
|
|
1166
|
+
"description": "Completed purchases.",
|
|
1167
|
+
"fields": [
|
|
1168
|
+
{ "name": "id", "type": "bigint", "nullable": false, "primaryKey": true, "unique": true },
|
|
1169
|
+
{ "name": "customer_id", "type": "bigint", "nullable": false, "primaryKey": false, "unique": false }
|
|
1170
|
+
],
|
|
1171
|
+
"indexes": [{ "name": "orders_customer_idx", "columns": ["customer_id"], "unique": false }]
|
|
1172
|
+
}
|
|
1173
|
+
],
|
|
1174
|
+
"relationships": [
|
|
1175
|
+
{
|
|
1176
|
+
"name": "orders_customer",
|
|
1177
|
+
"from": { "model": "orders", "field": "customer_id" },
|
|
1178
|
+
"to": { "model": "customers", "field": "id" },
|
|
1179
|
+
"cardinality": "many-to-one"
|
|
1180
|
+
}
|
|
1181
|
+
],
|
|
1182
|
+
"accessPatterns": [{ "model": "orders", "filters": ["customer_id"], "sort": ["created_at"] }],
|
|
1183
|
+
"decisions": [{ "name": "single-currency", "rationale": "Amounts are stored in minor units, USD only." }]
|
|
1184
|
+
}
|
|
1185
|
+
```
|
|
1186
|
+
|
|
1187
|
+
It holds no SQL, credentials, rows, or provider configuration. `design init`
|
|
1188
|
+
emits this envelope with empty `models`, `relationships`, `accessPatterns`, and
|
|
1189
|
+
`decisions`.
|
|
1190
|
+
|
|
1191
|
+
#### Review findings
|
|
1192
|
+
|
|
1193
|
+
`validate` is fail-closed: any `error` finding exits `1`, and `render`, `diff`,
|
|
1194
|
+
and `propose` refuse to do their work while errors remain.
|
|
1195
|
+
|
|
1196
|
+
| Severity | Codes |
|
|
1197
|
+
|---|---|
|
|
1198
|
+
| `error` | `NO_MODELS`, `DUPLICATE_MODEL`, `DUPLICATE_TABLE`, `DUPLICATE_FIELD`, `PRIMARY_KEY_COUNT`, `NULLABLE_PRIMARY_KEY`, `UNKNOWN_INDEX_FIELD`, `DUPLICATE_RELATIONSHIP`, `REVERSE_RELATIONSHIP`, `UNKNOWN_RELATIONSHIP_MODEL`, `UNKNOWN_RELATIONSHIP_FIELD`, `RELATIONSHIP_TYPE_MISMATCH`, `MANY_TO_MANY_REQUIRES_BRIDGE`, `ONE_TO_ONE_REQUIRES_UNIQUE_FK`, `UNKNOWN_ACCESS_MODEL`, `UNKNOWN_ACCESS_FIELD` |
|
|
1199
|
+
| `warn` | `DUPLICATE_INDEX`, `REDUNDANT_PRIMARY_KEY_INDEX`, `PREFIX_REDUNDANT_INDEX`, `ACCESS_PATTERN_INDEX` |
|
|
1200
|
+
|
|
1201
|
+
`REVERSE_RELATIONSHIP` fires when the same endpoints are declared again in the
|
|
1202
|
+
opposite direction; `PREFIX_REDUNDANT_INDEX` fires when a non-unique index is a
|
|
1203
|
+
leading-column prefix of a longer index. `v1` requires exactly one primary-key
|
|
1204
|
+
field per model and an explicit bridge model for `many-to-many`.
|
|
1205
|
+
|
|
1206
|
+
#### `design propose` (review-only)
|
|
1207
|
+
|
|
1208
|
+
`propose` turns drift into a plan a human reviews; it never applies a write. Each
|
|
1209
|
+
entry carries a `safety` of `dry-run` (an existing `migrate` command can represent
|
|
1210
|
+
the change losslessly) or `migration-review` (everything else), plus `preflight`,
|
|
1211
|
+
`rollback`, and `verification` steps:
|
|
1212
|
+
|
|
1213
|
+
```json
|
|
1214
|
+
{
|
|
1215
|
+
"table": "orders",
|
|
1216
|
+
"object": "total_cents",
|
|
1217
|
+
"safety": "migration-review",
|
|
1218
|
+
"commands": ["..."],
|
|
1219
|
+
"preflight": [
|
|
1220
|
+
"dbcli blacklist list",
|
|
1221
|
+
"Confirm the exact affected table with: dbcli schema <exact-table> --format json"
|
|
1222
|
+
],
|
|
1223
|
+
"rollback": "Capture the current schema and generated DDL before any approved write; define the inverse migration before execution.",
|
|
1224
|
+
"verification": [
|
|
1225
|
+
"After an approved write, run: dbcli schema <exact-table> --format json",
|
|
1226
|
+
"Re-run this same design diff command and review the remaining drift."
|
|
1227
|
+
]
|
|
1228
|
+
}
|
|
1229
|
+
```
|
|
1230
|
+
|
|
1231
|
+
**Workflows:**
|
|
1232
|
+
|
|
1233
|
+
- **New project** — `design init` → edit the artifact → `design validate` →
|
|
1234
|
+
`design render`. If application models already exist, use the offline
|
|
1235
|
+
`design diff --against-orm <path>` to reconcile the artifact and the ORM before
|
|
1236
|
+
any database exists.
|
|
1237
|
+
- **Existing database** — `blacklist list` → refresh the cache with
|
|
1238
|
+
`schema --format json` → `design diff --against-cache` →
|
|
1239
|
+
`design propose --against-cache`. Review the plan, perform any approved
|
|
1240
|
+
migration separately, then refresh the schema and rerun the same diff.
|
|
1241
|
+
|
|
1242
|
+
**Exit codes:** `0` when no errors, `1` when the artifact has review errors, an
|
|
1243
|
+
invalid target selection, an unreadable file, or reported drift errors.
|
|
1244
|
+
|
|
1245
|
+
An external coding agent may draft the artifact, but a human should review it
|
|
1246
|
+
before it is relied upon. Do not create or rewrite `dbcli.design.json` without an
|
|
1247
|
+
explicit human request.
|
|
1248
|
+
|
|
1080
1249
|
### snapshot
|
|
1081
1250
|
|
|
1082
1251
|
Capture a **result fingerprint** of a query (not schema): `rowCount` plus per-column
|
package/skills/dbcli/SKILL.md
CHANGED
|
@@ -381,11 +381,11 @@ Full flags and edge cases: see [reference.md](reference.md) `init` section.
|
|
|
381
381
|
| `use` | n/a | Show/switch default named connection (v2 only). |
|
|
382
382
|
| `list` | query-only+ | Tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch). |
|
|
383
383
|
| `schema` | query-only+ | SQL: per-table or full scan into `.dbcli/schemas/`. MongoDB: sampled. ES: flattened mapping. Redis: per-key only (type/TTL/size). Supports `--recovery`. |
|
|
384
|
-
| `query` | query-only+ | SQL, Mongo JSON (`--collection`), Redis command, or ES DSL/Lucene (`--collection`). `--format table\|json\|csv\|html`, `--ui` to open the interactive dashboard in a browser. `--fields` (projection), `--truncate` (cell width), `-f/--query-file` (read query from file or stdin), `--use a,b` (read-only fan-out). Supports `--recovery`. See **Query workflow flags**. |
|
|
384
|
+
| `query` | query-only+ | SQL, Mongo JSON (`--collection`), Redis command, or ES DSL/Lucene (`--collection`). `--format table\|json\|csv\|html`, `--ui` to open the interactive dashboard in a browser. `--fields` (projection), `--truncate` (cell width), `-f/--query-file` (read query from file or stdin), `--use a,b` (read-only fan-out). Supports `--recovery`. `--slow-ms <n>` sets the passive slow-query hint threshold (default 1000, `0` off): at or above it, table output gains a `Performance hint` footer and JSON gains `metadata.performanceAdvisory`; it runs no extra diagnostics and is suppressed under `--recovery`. Distinct from the `proxy` flag of the same name. See **Query workflow flags**. |
|
|
385
385
|
| `explain` | query-only+ | **(v1.23)** Read-only query plan with annotations. SQL only. Single query, `@saved-query`, `@file.sql`, or `--bulk @glob/*`. `--analyze` (EXPLAIN ANALYZE / MariaDB ANALYZE SELECT), `--format markdown\|json\|table`. |
|
|
386
386
|
| `lint` | n/a | Static SQL anti-pattern advisor (no DB connection). 9 rules incl. schema-aware implicit-cast / NOT IN-nullable checks via the layered `.dbcli/schemas/` cache; global `--use <conn>` selects a named cache. Findings carry rewrite drafts + guarded `explain` verify commands (`--analyze` only for proven read-only SQL) — report-only, never executes. `--format text\|json\|markdown`, `--min-severity`, `--no-schema`, `--bulk`. Supports `--recovery`. |
|
|
387
387
|
| `plan` | n/a | Static SQL risk analyzer (`--format text\|json`); classifies a statement without connecting to the database. |
|
|
388
|
-
| `q` | query-only+ | Run a saved snippet by `@name` with `--param k=v`. Supports `--verify` to run assertions. |
|
|
388
|
+
| `q` | query-only+ | Run a saved snippet by `@name` with `--param k=v`. Supports `--verify` to run assertions and `--slow-ms <n>` (same passive slow-query hint as `query`). |
|
|
389
389
|
| `queries` | n/a | Manage saved snippets: `list` / `show` / `search` / `suggest` / `new` / `edit` / `check` / `delete` / `rename` / `copy` / `import` / `export`. |
|
|
390
390
|
| `insert` / `update` | read-write+ | SQL or MongoDB only. JSON `--data` / `--set`; `--where` required on `update`; `--dry-run` first. Redis writes go through `query`. Supports `--recovery`. |
|
|
391
391
|
| `delete` | data-admin+ | SQL or MongoDB; Redis has a basic implementation (see Redis section). `--where` required; `--dry-run` first. Supports `--recovery`. |
|
|
@@ -220,9 +220,44 @@ dbcli query "SELECT day, dau FROM dau_daily" --ui # open in brows
|
|
|
220
220
|
dbcli query "SELECT * FROM orders" --format html > orders.html # pipe to stdout
|
|
221
221
|
```
|
|
222
222
|
|
|
223
|
-
**Options:** `--format <table|json|csv|html>`, `--ui` (open the dashboard in the system browser; implies `--format html`), `--limit <number>`, `--no-limit`, `--collection <name>` (MongoDB / Elasticsearch), `--index <name>` (Elasticsearch alias for `--collection`), `--fields <list>`, `--truncate <number>` / `--no-truncate`, `-f, --query-file <path>`, `--use <name[,name]>`, `--recovery`
|
|
223
|
+
**Options:** `--format <table|json|csv|html>`, `--ui` (open the dashboard in the system browser; implies `--format html`), `--limit <number>`, `--no-limit`, `--collection <name>` (MongoDB / Elasticsearch), `--index <name>` (Elasticsearch alias for `--collection`), `--fields <list>`, `--truncate <number>` / `--no-truncate`, `-f, --query-file <path>`, `--use <name[,name]>`, `--slow-ms <number>`, `--recovery`
|
|
224
224
|
**Permission:** query-only+ (Redis: per-command; Elasticsearch: per HTTP method/path)
|
|
225
225
|
|
|
226
|
+
#### Passive slow-query hint (`--slow-ms`)
|
|
227
|
+
|
|
228
|
+
`query` and `q` read the execution time they already measured for a finished
|
|
229
|
+
query and, at or above the threshold, add a hint. Default `1000`; `--slow-ms 0`
|
|
230
|
+
disables it for that invocation. This is **not** the `proxy` / `proxy analyze`
|
|
231
|
+
flag of the same name — that one flags events in the proxy log; this one only
|
|
232
|
+
annotates a single command's own result.
|
|
233
|
+
|
|
234
|
+
The hint performs no extra work: it never runs `EXPLAIN`, reads a schema, or
|
|
235
|
+
issues a second request. It is suppressed entirely under `--recovery`, so the
|
|
236
|
+
recovery envelope keeps its exact machine contract.
|
|
237
|
+
|
|
238
|
+
- `--format table` appends `Performance hint: <recommendation>` to the footer.
|
|
239
|
+
- `--format json` adds `metadata.performanceAdvisory`:
|
|
240
|
+
|
|
241
|
+
```json
|
|
242
|
+
{
|
|
243
|
+
"metadata": {
|
|
244
|
+
"statement": "SELECT",
|
|
245
|
+
"performanceAdvisory": {
|
|
246
|
+
"code": "SLOW_QUERY",
|
|
247
|
+
"executionTimeMs": 1250,
|
|
248
|
+
"thresholdMs": 1000,
|
|
249
|
+
"recommendation": "Review safely with: dbcli guide slow-query --format markdown. This hint runs no additional database diagnostics."
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
The recommendation is engine-aware: PostgreSQL, MySQL, MariaDB, and Redis are
|
|
256
|
+
pointed at `dbcli guide slow-query`, because that goal resolves to real
|
|
257
|
+
diagnostic snippets for them. MongoDB and Elasticsearch ship no snippet for its
|
|
258
|
+
intents, so their hint states the timing and says so instead of naming a command
|
|
259
|
+
that would come back empty. `csv` and `html` output are unchanged.
|
|
260
|
+
|
|
226
261
|
Below `admin`, SQL holding more than one statement is rejected, because only the
|
|
227
262
|
first statement would decide the permission check while a driver on the simple
|
|
228
263
|
query protocol executes them all. Semicolons inside string literals, backtick
|
|
@@ -529,6 +564,7 @@ dbcli q @analytics/revenue --param days=30 --format html > report.html
|
|
|
529
564
|
- `--no-limit` — skip the `SELECT * FROM (…) AS _dbcli_guard LIMIT 1000` wrap
|
|
530
565
|
- `--dry-run` — print the bound SQL + values without executing
|
|
531
566
|
- `--use <name>` — pick a v2 named connection
|
|
567
|
+
- `--slow-ms <number>` — passive slow-query hint threshold (default `1000`; `0` disables). Same contract as `query` — see "Passive slow-query hint" there
|
|
532
568
|
- `--recovery` — emit a `RecoveryEnvelope` on failure (see `recover`)
|
|
533
569
|
- `--verify` — run the snippet's verification assertions after execution (only if the snippet defines them)
|
|
534
570
|
|
|
@@ -1077,6 +1113,139 @@ Both parameters are required. Keep each expansion as one quoted shell argument;
|
|
|
1077
1113
|
never use `eval`, and consider `--execute` only after the plan and captured DDL
|
|
1078
1114
|
have been reviewed.
|
|
1079
1115
|
|
|
1116
|
+
### design
|
|
1117
|
+
|
|
1118
|
+
Author, validate, render, and review a version-controlled SQL database design
|
|
1119
|
+
kept beside the code as `dbcli.design.json`. Every subcommand is offline: none
|
|
1120
|
+
opens a database connection, executes DDL, or calls an LLM. `design init` is the
|
|
1121
|
+
only writer, and it writes only to the explicit `--output` path.
|
|
1122
|
+
|
|
1123
|
+
```text
|
|
1124
|
+
dbcli design init --output <path> [--dialect <dialect>]
|
|
1125
|
+
dbcli design validate [--file <path>] [--format <format>]
|
|
1126
|
+
dbcli design render [--file <path>] [--format <format>]
|
|
1127
|
+
dbcli design diff (--against-cache | --against-orm <paths>) [options]
|
|
1128
|
+
dbcli design propose (--against-cache | --against-orm <paths>) [options]
|
|
1129
|
+
```
|
|
1130
|
+
|
|
1131
|
+
```bash
|
|
1132
|
+
# Writes only to this explicit, missing path; edit the starter before validating.
|
|
1133
|
+
dbcli design init --output ./dbcli.design.json --dialect postgresql
|
|
1134
|
+
|
|
1135
|
+
dbcli design validate --format json
|
|
1136
|
+
dbcli design render --format mermaid
|
|
1137
|
+
dbcli design diff --against-cache --format markdown
|
|
1138
|
+
dbcli design diff --against-orm ./prisma/schema.prisma --format markdown
|
|
1139
|
+
dbcli design propose --against-orm ./prisma/schema.prisma --format markdown
|
|
1140
|
+
```
|
|
1141
|
+
|
|
1142
|
+
| Option | Applies to | Default | Meaning |
|
|
1143
|
+
|---|---|---|---|
|
|
1144
|
+
| `--output <path>` | `init` | required | Destination for the new artifact; refuses to overwrite an existing file. |
|
|
1145
|
+
| `--dialect <postgresql\|mysql\|mariadb>` | `init` | `postgresql` | Target SQL dialect recorded in the artifact. |
|
|
1146
|
+
| `--file <path>` | all but `init` | `dbcli.design.json` | Design artifact to read. |
|
|
1147
|
+
| `--format <format>` | all but `init` | see below | `validate`/`propose`: `json`, `markdown`. `render`: `json`, `markdown`, `mermaid` (default `markdown`). `diff`: `json` (default), `table`, `markdown`. |
|
|
1148
|
+
| `--against-cache` | `diff`, `propose` | off | Compare with the local schema cache; requires a configured PostgreSQL/MySQL/MariaDB connection whose system matches the artifact dialect, and a non-empty cache (run `dbcli schema` first). |
|
|
1149
|
+
| `--against-orm <paths>` | `diff`, `propose` | none | Compare with local ORM definition(s); repeatable or comma-separated, DDL paths support globs. Needs no config and no connection. |
|
|
1150
|
+
| `--orm-format <format>` | `diff`, `propose` | auto-detect | Force `prisma`, `ddl`, `json`, `drizzle`, `typeorm`, or `sequelize`. |
|
|
1151
|
+
| `--ignore <globs>` | `diff`, `propose` | none | Comma-separated table globs excluded from drift. |
|
|
1152
|
+
|
|
1153
|
+
`diff` and `propose` require **exactly one** comparison target; passing both or
|
|
1154
|
+
neither is an error.
|
|
1155
|
+
|
|
1156
|
+
#### Artifact shape
|
|
1157
|
+
|
|
1158
|
+
```json
|
|
1159
|
+
{
|
|
1160
|
+
"version": 1,
|
|
1161
|
+
"dialect": "postgresql",
|
|
1162
|
+
"models": [
|
|
1163
|
+
{
|
|
1164
|
+
"name": "orders",
|
|
1165
|
+
"table": "orders",
|
|
1166
|
+
"description": "Completed purchases.",
|
|
1167
|
+
"fields": [
|
|
1168
|
+
{ "name": "id", "type": "bigint", "nullable": false, "primaryKey": true, "unique": true },
|
|
1169
|
+
{ "name": "customer_id", "type": "bigint", "nullable": false, "primaryKey": false, "unique": false }
|
|
1170
|
+
],
|
|
1171
|
+
"indexes": [{ "name": "orders_customer_idx", "columns": ["customer_id"], "unique": false }]
|
|
1172
|
+
}
|
|
1173
|
+
],
|
|
1174
|
+
"relationships": [
|
|
1175
|
+
{
|
|
1176
|
+
"name": "orders_customer",
|
|
1177
|
+
"from": { "model": "orders", "field": "customer_id" },
|
|
1178
|
+
"to": { "model": "customers", "field": "id" },
|
|
1179
|
+
"cardinality": "many-to-one"
|
|
1180
|
+
}
|
|
1181
|
+
],
|
|
1182
|
+
"accessPatterns": [{ "model": "orders", "filters": ["customer_id"], "sort": ["created_at"] }],
|
|
1183
|
+
"decisions": [{ "name": "single-currency", "rationale": "Amounts are stored in minor units, USD only." }]
|
|
1184
|
+
}
|
|
1185
|
+
```
|
|
1186
|
+
|
|
1187
|
+
It holds no SQL, credentials, rows, or provider configuration. `design init`
|
|
1188
|
+
emits this envelope with empty `models`, `relationships`, `accessPatterns`, and
|
|
1189
|
+
`decisions`.
|
|
1190
|
+
|
|
1191
|
+
#### Review findings
|
|
1192
|
+
|
|
1193
|
+
`validate` is fail-closed: any `error` finding exits `1`, and `render`, `diff`,
|
|
1194
|
+
and `propose` refuse to do their work while errors remain.
|
|
1195
|
+
|
|
1196
|
+
| Severity | Codes |
|
|
1197
|
+
|---|---|
|
|
1198
|
+
| `error` | `NO_MODELS`, `DUPLICATE_MODEL`, `DUPLICATE_TABLE`, `DUPLICATE_FIELD`, `PRIMARY_KEY_COUNT`, `NULLABLE_PRIMARY_KEY`, `UNKNOWN_INDEX_FIELD`, `DUPLICATE_RELATIONSHIP`, `REVERSE_RELATIONSHIP`, `UNKNOWN_RELATIONSHIP_MODEL`, `UNKNOWN_RELATIONSHIP_FIELD`, `RELATIONSHIP_TYPE_MISMATCH`, `MANY_TO_MANY_REQUIRES_BRIDGE`, `ONE_TO_ONE_REQUIRES_UNIQUE_FK`, `UNKNOWN_ACCESS_MODEL`, `UNKNOWN_ACCESS_FIELD` |
|
|
1199
|
+
| `warn` | `DUPLICATE_INDEX`, `REDUNDANT_PRIMARY_KEY_INDEX`, `PREFIX_REDUNDANT_INDEX`, `ACCESS_PATTERN_INDEX` |
|
|
1200
|
+
|
|
1201
|
+
`REVERSE_RELATIONSHIP` fires when the same endpoints are declared again in the
|
|
1202
|
+
opposite direction; `PREFIX_REDUNDANT_INDEX` fires when a non-unique index is a
|
|
1203
|
+
leading-column prefix of a longer index. `v1` requires exactly one primary-key
|
|
1204
|
+
field per model and an explicit bridge model for `many-to-many`.
|
|
1205
|
+
|
|
1206
|
+
#### `design propose` (review-only)
|
|
1207
|
+
|
|
1208
|
+
`propose` turns drift into a plan a human reviews; it never applies a write. Each
|
|
1209
|
+
entry carries a `safety` of `dry-run` (an existing `migrate` command can represent
|
|
1210
|
+
the change losslessly) or `migration-review` (everything else), plus `preflight`,
|
|
1211
|
+
`rollback`, and `verification` steps:
|
|
1212
|
+
|
|
1213
|
+
```json
|
|
1214
|
+
{
|
|
1215
|
+
"table": "orders",
|
|
1216
|
+
"object": "total_cents",
|
|
1217
|
+
"safety": "migration-review",
|
|
1218
|
+
"commands": ["..."],
|
|
1219
|
+
"preflight": [
|
|
1220
|
+
"dbcli blacklist list",
|
|
1221
|
+
"Confirm the exact affected table with: dbcli schema <exact-table> --format json"
|
|
1222
|
+
],
|
|
1223
|
+
"rollback": "Capture the current schema and generated DDL before any approved write; define the inverse migration before execution.",
|
|
1224
|
+
"verification": [
|
|
1225
|
+
"After an approved write, run: dbcli schema <exact-table> --format json",
|
|
1226
|
+
"Re-run this same design diff command and review the remaining drift."
|
|
1227
|
+
]
|
|
1228
|
+
}
|
|
1229
|
+
```
|
|
1230
|
+
|
|
1231
|
+
**Workflows:**
|
|
1232
|
+
|
|
1233
|
+
- **New project** — `design init` → edit the artifact → `design validate` →
|
|
1234
|
+
`design render`. If application models already exist, use the offline
|
|
1235
|
+
`design diff --against-orm <path>` to reconcile the artifact and the ORM before
|
|
1236
|
+
any database exists.
|
|
1237
|
+
- **Existing database** — `blacklist list` → refresh the cache with
|
|
1238
|
+
`schema --format json` → `design diff --against-cache` →
|
|
1239
|
+
`design propose --against-cache`. Review the plan, perform any approved
|
|
1240
|
+
migration separately, then refresh the schema and rerun the same diff.
|
|
1241
|
+
|
|
1242
|
+
**Exit codes:** `0` when no errors, `1` when the artifact has review errors, an
|
|
1243
|
+
invalid target selection, an unreadable file, or reported drift errors.
|
|
1244
|
+
|
|
1245
|
+
An external coding agent may draft the artifact, but a human should review it
|
|
1246
|
+
before it is relied upon. Do not create or rewrite `dbcli.design.json` without an
|
|
1247
|
+
explicit human request.
|
|
1248
|
+
|
|
1080
1249
|
### snapshot
|
|
1081
1250
|
|
|
1082
1251
|
Capture a **result fingerprint** of a query (not schema): `rowCount` plus per-column
|