@carllee1983/dbcli 1.37.0 → 1.38.1

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.
@@ -1147,8 +1147,8 @@ Output reports: writer enabled/disabled, last write result, file-lock state, rot
1147
1147
  ### verify
1148
1148
 
1149
1149
  Run a verification scenario. `verify` **runs** verification scenarios (safe-backfill,
1150
- migration) and never executes writes/DDL. `verification` **inspects and manages** the
1151
- local result artifacts those scenarios produce under `.dbcli/verification/`.
1150
+ migration, rollback) and never executes writes/DDL. `verification` **inspects and manages**
1151
+ the local result artifacts those scenarios produce under `.dbcli/verification/`.
1152
1152
 
1153
1153
  ```bash
1154
1154
  # Preflight (default): read-only guards + the exact after-write command. No artifact.
@@ -1233,6 +1233,135 @@ cannot be fully parsed under this contract (unterminated quotes, unsupported esc
1233
1233
  or more than three parts) are blocked before the after-write assertion with a
1234
1234
  "could not be parsed" reason, distinct from the `must match --table` mismatch reason.
1235
1235
 
1236
+ #### `verify rollback`
1237
+
1238
+ (v1.37.0+) Preflight or after-write verification for an **externally-applied rollback** —
1239
+ confirming that after you reverted a change the database is back to the expected prior
1240
+ state. **This command never executes the reverting statement** — it analyzes it, runs
1241
+ read-only guards, and (in after-write mode) records evidence after you apply the rollback
1242
+ externally. One scenario covers both schema and data rollbacks via a required
1243
+ `--kind <ddl|dml>` selector:
1244
+
1245
+ - `--kind ddl` — revert a schema migration. `--statement` is a single `ALTER TABLE`
1246
+ (e.g. dropping a column a forward migration added). Reuses the `migration` DDL gates.
1247
+ - `--kind dml` — revert a data change. `--statement` is a single `UPDATE` that restores
1248
+ prior values. Reuses the `safe-backfill` UPDATE plan gates.
1249
+
1250
+ ```bash
1251
+ # Schema rollback (--kind ddl) — preflight, then record evidence after applying it.
1252
+ dbcli verify rollback \
1253
+ --kind ddl \
1254
+ --table users \
1255
+ --statement "ALTER TABLE users DROP COLUMN verified_at" \
1256
+ --verify-query "SELECT count(*)::int AS n FROM information_schema.columns WHERE table_name = 'users' AND column_name = 'verified_at'" \
1257
+ --expect "value == 0"
1258
+ dbcli verify rollback --kind ddl ... --after-write
1259
+
1260
+ # Data rollback (--kind dml) — revert an UPDATE, then read back.
1261
+ dbcli verify rollback \
1262
+ --kind dml \
1263
+ --table users \
1264
+ --statement "UPDATE users SET status = NULL WHERE status = 1" \
1265
+ --verify-query "SELECT count(*)::int AS n FROM users WHERE status = 1" \
1266
+ --expect "value == 0"
1267
+ dbcli verify rollback --kind dml ... --after-write
1268
+
1269
+ # JSON for agents (both kinds).
1270
+ dbcli verify rollback --kind ddl ... --format json
1271
+ ```
1272
+
1273
+ | Option | Required | Description |
1274
+ | --- | --- | --- |
1275
+ | `--kind <ddl\|dml>` | yes | Reverting-statement grammar: `ddl` (single `ALTER TABLE`) or `dml` (single `UPDATE`). Invalid value fails closed before any DB connection. |
1276
+ | `--table <table>` | yes | Table affected by the rollback. |
1277
+ | `--statement <sql>` | yes | Proposed reverting statement, analyzed but never executed. |
1278
+ | `--verify-query <sql>` | yes | Plain `SELECT` for post-rollback read-back verification. |
1279
+ | `--expect <expr>` | yes | Assertion expression for the read-back result. |
1280
+ | `--after-write` | no | Run the post-rollback assertion and write a v1 artifact. |
1281
+ | `--format <table\|json>` | no | Output format, default `table`. |
1282
+ | `--subject-name <name>` | no | Artifact subject name. Default is the table name. |
1283
+ | `--summary <text>` | no | Optional artifact summary override. |
1284
+
1285
+ A single `--statement` flag is used for both kinds (instead of reusing `--ddl` / `--query`)
1286
+ to keep the dual-kind surface honest. The guard sequence, statuses (`ready`/`blocked` in
1287
+ preflight; `verified` / `not_verified` / `blocked` / `indeterminate` in after-write), and
1288
+ exit codes are identical to the other two scenarios. **MVP restrictions:** DML rollback is
1289
+ `UPDATE`-only (INSERT/DELETE reverts deferred); DDL rollback is single `ALTER TABLE` only,
1290
+ using the same identifier contract as `verify migration`.
1291
+
1292
+ The artifact schema is unchanged: a rollback reuses the existing subject kinds —
1293
+ `--kind ddl` → `migration`, `--kind dml` → `backfill` — and records its provenance via
1294
+ `subject.command = "verify rollback"` plus the summary, so `verification` filters and
1295
+ retention are unaffected.
1296
+
1297
+ #### `verify constraint`
1298
+
1299
+ (v1.38.0+) Preflight or after-write verification that a **data-integrity invariant holds**
1300
+ across your change — foreign-key consistency, NOT NULL coverage, uniqueness, or a custom
1301
+ violation query. **This command never executes a write** — it only runs read-only
1302
+ `COUNT(*)` violation queries against the live table and (in after-write mode) records
1303
+ evidence. Four check kinds, selected by `--check`:
1304
+
1305
+ - `--check fk` — counts orphaned rows in the child table. Requires `--column` (the child
1306
+ FK column) and `--references <table.column>` (the referenced parent column).
1307
+ - `--check not-null` — counts rows where the column value is NULL. `--column` is
1308
+ repeatable; each column is checked independently.
1309
+ - `--check unique` — counts duplicate values in one or more columns. `--column` is
1310
+ repeatable; all listed columns are combined into a single uniqueness check.
1311
+ - `--check custom` — executes the caller-supplied `--violation-query <sql>`, which must
1312
+ be a plain read-only `SELECT` returning a single integer count of violations.
1313
+
1314
+ ```bash
1315
+ # FK preflight — verify no orphaned orders before a migration.
1316
+ dbcli verify constraint \
1317
+ --table orders \
1318
+ --check fk \
1319
+ --column customer_id \
1320
+ --references customers.id
1321
+
1322
+ # NOT NULL preflight — verify the column is fully populated.
1323
+ dbcli verify constraint \
1324
+ --table users \
1325
+ --check not-null \
1326
+ --column email
1327
+
1328
+ # After the write is applied externally — record evidence.
1329
+ dbcli verify constraint --table orders --check fk --column customer_id \
1330
+ --references customers.id --after-write
1331
+
1332
+ # JSON output for agents.
1333
+ dbcli verify constraint --table users --check not-null --column email --format json
1334
+ ```
1335
+
1336
+ | Option | Required | Description |
1337
+ | --- | --- | --- |
1338
+ | `--table <table>` | yes | Table the invariant is checked on. |
1339
+ | `--check <kind>` | yes | Constraint kind: `fk` \| `not-null` \| `unique` \| `custom`. |
1340
+ | `--column <name>` | yes (fk/not-null/unique) | Column to check. Repeatable for `not-null`/`unique`; the child FK column for `fk`. |
1341
+ | `--references <table.column>` | yes (fk only) | Referenced `<table>.<column>` for the FK parent lookup. |
1342
+ | `--violation-query <sql>` | yes (custom only) | Read-only `SELECT` returning a single integer count of violations. |
1343
+ | `--allow-preexisting` | no | Tolerate pre-existing violations: verified when `count ≤ --baseline` (default: `false`). |
1344
+ | `--baseline <n>` | no | Baseline violation count measured at preflight (use with `--allow-preexisting`). |
1345
+ | `--after-write` | no | Re-run the violation count and write a v1 verification artifact. |
1346
+ | `--format <table\|json>` | no | Output format, default `table`. |
1347
+ | `--subject-name <name>` | no | Artifact subject name. Default is the table name. |
1348
+ | `--summary <text>` | no | Optional artifact summary override (after-write mode). |
1349
+
1350
+ **Verdict rules.** Preflight returns `ready` or `blocked`; **`ready` is not `verified`**.
1351
+ After-write maps the violation count to `verified` (violations ≤ threshold) or
1352
+ `not_verified` (violations > threshold), and a failed guard to `blocked`; a query error
1353
+ yields `indeterminate`. The default threshold is `0` (strict: zero violations allowed).
1354
+ With `--allow-preexisting`, the threshold is the `--baseline` count captured at preflight,
1355
+ so the no-regression rule passes as long as the after-write count does not exceed the
1356
+ preflight count.
1357
+
1358
+ **MVP restrictions.** SQL engines only (PostgreSQL / MySQL / MariaDB — requires an active
1359
+ `--config` connection). FK checks support a single child column; composite FK constraints
1360
+ are not yet supported. The command never executes any write or DDL statement.
1361
+
1362
+ The artifact uses `subject.kind = 'table'` and `subject.command = 'verify constraint'`,
1363
+ so `verification` filters and retention are unaffected by the new scenario.
1364
+
1236
1365
  ### verification
1237
1366
 
1238
1367
  (v1.33.0+) Local **VerificationArtifact** inspection and lifecycle surface over
package/CHANGELOG.md CHANGED
@@ -5,6 +5,28 @@ 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.38.1] - 2026-06-23 - Redis delete 能力對齊 & SKILL.md 任務路由重構
9
+
10
+ ### Fixed
11
+
12
+ - **Redis `delete` 能力宣告由 `unsupported` 修正為 `limited` / `db-write`。** `delete.ts` 早已具備完整的 Redis 刪除分支(`DEL` / `HDEL` / `LREM` / `SREM` / `ZREM`、data-admin 權限閘、`--dry-run`、黑名單、稽核),但 `capabilities.ts` 仍宣告為 `unsupported`,與實作矛盾,導致能力表低報 Redis 刪除支援。改宣告為 `limited`(`db-write`,標註「基本刪除,需 data-admin、支援 `--dry-run`」)以對齊實作。於 SKILL.md 的 src 驗證期間發現。
13
+
14
+ ### Changed
15
+
16
+ - **`assets/SKILL.md` 重構為任務路由決策樹。** 由原先結構改寫為以任務為導向的決策樹(task-routing decision tree),讓安裝 skill 的 agent 能依任務類型快速定位對應的指令工作流。純文件結構調整,無程式行為更動。
17
+
18
+ ## [1.38.0] - 2026-06-22 - verify constraint Scenario
19
+
20
+ ### Added
21
+
22
+ - **`dbcli verify constraint` 情境執行器(第四個內建 verify 情境)。** 以 preflight / after-write 兩種模式驗證「資料完整性不變式是否成立」,且**永遠不執行寫入或 DDL** — 只執行唯讀 `COUNT(*)` 違規查詢。以 `--check <kind>` 選擇四種限制類型:`fk`(孤兒列,需 `--column` + `--references <table.column>`)、`not-null`(NULL 值統計,`--column` 可重複)、`unique`(重複值統計,`--column` 可重複)、`custom`(呼叫端自訂的唯讀 `--violation-query <sql>`)。預設 threshold 為 `0`(嚴格:零違規即通過);啟用 `--allow-preexisting` + `--baseline <n>` 可改為無回退模式(after-write 筆數 ≤ preflight baseline 即通過)。文物沿用 `subject.kind = 'table'`、`subject.command = 'verify constraint'`,artifact schema 與版本不變。MVP 僅限 SQL 引擎,FK 僅支援單一子欄位。
23
+
24
+ ## [1.37.1] - 2026-06-22 - Skill Documentation Parity for verify rollback
25
+
26
+ ### Fixed
27
+
28
+ - **Skill 文件補上 `verify rollback`。** v1.37.0 出貨的 `dbcli verify rollback` 先前未寫進可安裝的 skill 文件,導致安裝 skill 的 agent 不知道此指令存在。於 `assets/SKILL.md` / `assets/SKILL.zh-TW.md` 加入工作流速覽行,並於 `assets/reference.md` 新增完整 `#### verify rollback` 區段(`--kind ddl|dml`、`--statement`、preflight / after-write 雙範例、MVP 限制與 artifact subject 對應)。透過 `plugin:sync` 將內容傳播到所有受管理的平台副本(`skills/`、`.github/skills/`、`.cursor/`、`.windsurf/`、`plugins/`)。純文件變更,無程式行為更動。
29
+
8
30
  ## [1.37.0] - 2026-06-22 - Rollback Scenario & Nested Shell Completions
9
31
 
10
32
  ### Added