@happyvertical/smrt-cli 0.47.0 → 0.47.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/AGENTS.md CHANGED
@@ -10,6 +10,7 @@ smrt doctor # Umbrella diagnostics; can verify a generation sna
10
10
  smrt doctor --db # Add the live-schema parity section (see below)
11
11
  smrt db:status # Pending schema changes + failed migration classification
12
12
  smrt db:status --parity # Same, plus live-schema parity (see below)
13
+ smrt db:orphans # agents/db-orphans.md
13
14
  smrt db:migrate # Apply migrations
14
15
  smrt db:migrate --postgres-safe # PostgreSQL concurrent-index mode (see below)
15
16
  smrt db:migrate --force-migration <exact-id> [--force-migration <exact-id>...] # Force exact generated migrations in one atomic batch
@@ -19,7 +20,7 @@ smrt db:drop-framework-base-tables # One-time drop of the five #2644-orphaned fr
19
20
  smrt db:drop-framework-base-tables --dry-run # Print the drop plan without executing
20
21
  smrt db:diff # Show schema differences without generating migration files
21
22
  smrt db:rollback # Roll back migrations by executing their recorded DOWN
22
- smrt db:rollback --mark-only # Record-only flip; schema deliberately untouched
23
+ smrt db:rollback --mark-only # Record-only flip; schema untouched
23
24
  smrt db:prune # Prune framework system tables to their retention windows
24
25
  smrt db:prune --dry-run # Same predicates, counted rather than deleted
25
26
  smrt docs:agents # Generate .agents/smrt-framework.md
@@ -0,0 +1,46 @@
1
+ # `db:orphans` — per-foreign-key orphan count report (#2753)
2
+
3
+ `db:migrate`'s orphan probe already gates `ADD CONSTRAINT` with a `LIMIT 1`
4
+ existence check and prints a suggested repair (see the PostgreSQL section of
5
+ `packages/cli/AGENTS.md`); it cannot say *how many* orphans exist or across
6
+ which relationships. `db:orphans` runs core's `collectForeignKeyOrphanCounts()`,
7
+ which probes every manifest-declared foreign key from
8
+ `ObjectRegistry.getAllSchemasAsDefinitions()` as a `COUNT(*)` aggregate —
9
+ reusing `renderForeignKeyOrphanDetector()`'s exact FROM/JOIN/WHERE predicate
10
+ via its `countOnly` option, never a second hand-written copy — and reports
11
+ child/parent table and column, the live orphan count, and whether the child
12
+ column is `NOT NULL` (so the two dispositions the repair-SQL builder already
13
+ distinguishes — manual repair vs. an executable null-out — are visible up
14
+ front, without hand-writing the same SQL against the database). Results print
15
+ sorted by count descending. A relationship whose child or parent table does
16
+ not exist live is skipped and listed separately rather than failing the whole
17
+ report.
18
+
19
+ Strictly read-only and diagnostic: it never repairs anything, and the orphan
20
+ counts themselves never affect the exit code — a database full of orphans
21
+ still exits 0, matching the existing "no foreign-key orphan repair, by
22
+ design" boundary. It exits non-zero only on a configuration or runtime error
23
+ (no database configured, or the report itself could not run). `--json` emits
24
+ the full report for scripting; `--verbose` also lists foreign keys with zero
25
+ orphans.
26
+
27
+ `ForeignKeyOrphanSkipped.kind` distinguishes a benign `missing_table` skip
28
+ (a manifest table not yet migrated) from `probe_failed` (the `COUNT(*)`
29
+ query itself errored — permissions, a malformed live column, a genuine SQL
30
+ failure). `smrt db:orphans` marks a `probe_failed` skip `[PROBE FAILED]` in
31
+ its Skipped section and never reports the "No orphan rows found" clean
32
+ summary while any probe has failed, since an incomplete scan is not the same
33
+ claim as a clean one.
34
+
35
+ `db:status` runs the same probe unconditionally (not gated behind `--parity`,
36
+ and independent of whether the configured adapter supports
37
+ `getTableSchema` — the probe only needs `db.query()`) and, when any manifest
38
+ foreign key has live orphans, prints one compact line per affected foreign
39
+ key plus a pointer to `smrt db:orphans` for the full report. A `probe_failed`
40
+ skip surfaces as its own distinct warning (`status.orphanProbeFailures`)
41
+ rather than being read as "no orphans found"; `missing_table` skips stay
42
+ silent in `db:status` (benign, and already visible in full via
43
+ `smrt db:orphans`). Never a new `SchemaDiff` finding kind, and never
44
+ touching `db:status`'s exit code. A total probe failure (the collector call
45
+ itself throws, e.g. it cannot list live tables at all) is reported as
46
+ "Foreign-key orphan check unavailable" rather than failing `db:status`.