You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9e7cff5
Browse filesBrowse the repository at this point in the historyBrowse files
feat(cli): add janitor --target and inspection-only --as preview (#898)
janitor --target NAME cleans up a configured target with that target's
connection, namespace and state, like build --target. janitor --as NAME
previews the janitor plan for another target's namespace through the
active target's connection without dropping, archiving, writing state or
prompting, reusing the plan --as target validation.
|`--target <name>`| Clean up a configured target instead of the active/default target, using that target's connection, schemas and state |
38
+
|`--as <name>`| Preview the janitor plan for another configured target's schemas through the active target's connection. Inspection only: nothing is archived, dropped or pruned, and there is no prompt. Cannot be combined with `--auto-approve`|
36
39
|`--auto-approve`| Skip the confirmation prompt and run the planned actions immediately |
37
40
|`--retention-days`| Override the configured retention period (days) before a stale relation is archived |
38
41
|`--direct-state-history-versions`| Override how many state-history versions are kept per identity |
39
42
|`--drop-old-name-view <name>`| Drop the [compatibility view](../concepts/models/migrations.md#old-names) at a renamed model's old name before it expires. Repeat for several views. Fails with `C503` if no compatibility view is recorded at the name |
40
43
44
+
## Targets
45
+
46
+
By default the janitor cleans up the active target. `--target <name>` selects another configured target, exactly like `sqb build --target`: the janitor connects with that target's connection and inspects and cleans that target's schemas and state tables. Other targets are never touched.
47
+
48
+
`--as <name>` previews what the janitor would do in another target without changing anything, like [`sqb plan --as`](plan.md). The project compiles for that target, and its schemas are inspected through the active target's connection, which can be the default target or the one given with `--target`. The janitor lists every relation it would archive, every archive it would delete, every compatibility view it would drop and every state table it would prune, then exits. It drops nothing, writes no audit or state rows, prunes nothing and does not prompt. `--drop-old-name-view` is allowed with `--as` and only previews the drop.
49
+
50
+
```
51
+
Previewing janitor as target 'prod' through the connection of target 'dev' (inspection only).
52
+
...
53
+
Relations to archive
54
+
prod.customers -> prod._sqb_archive__20261001t101500z__customers age unknown, delete after 2026-10-15 10:15:00 UTC
55
+
56
+
Archives to delete
57
+
prod._sqb_archive__20200101t000000z__old_products archived 2020-01-01 00:00:00 UTC, age 2465d, expired 2020-01-15 00:00:00 UTC
58
+
59
+
Previewed janitor as target 'prod' through the connection of target 'dev'. Nothing was changed.
60
+
Rerun with `--target prod` instead of `--as prod` to apply it.
61
+
```
62
+
63
+
An unknown target name fails before anything connects. A preview exits with `0`, or with `1` when a schema is blocked, as a normal run would.
64
+
41
65
## Lifecycle
42
66
43
67
The janitor never drops a live relation directly. Each stale relation goes through two stages:
@@ -134,6 +158,12 @@ sqb janitor --auto-approve
134
158
135
159
# Override retention to 7 days
136
160
sqb janitor --retention-days 7
161
+
162
+
# Preview the prod cleanup through the current connection, changing nothing
0 commit comments