Expand description
Djogi CLI library — entry points for the djogi binary and for
adopter-linked binaries that inject their own DescriptorProvider.
The published standalone djogi binary links no adopter model crates,
so reading the global inventory registry directly yields zero adopter
models. Injecting a DescriptorProvider lets an adopter-linked binary
supply its own models. See run_with_provider.
Macros§
- djogi_
main - Generate a
fn main()that references model types to prevent the LTO linker from dropping inventory data, then delegates todjogi_cli::run_from_env(). Referencing a single descriptor per crate forces ALL inventory from that crate into the final binary. This macro makes that reference explicit and auditable at the adopter’s binary entry point. - link_
anchor - Emit a once-per-crate linkage anchor so an adopter binary can force
link-time retention of THIS crate’s
#[derive(Model)]registrations without listing every model type (#370, branch b).
Structs§
- Cli
- Inventory
Descriptor Provider - The link-time inventory-backed
DescriptorProvider— the only shipped implementation. - Table
Health - Snapshot of a single table’s vacuum / partition health. Field provenance (per the live-DB query plan):
Enums§
- Analyze
Error - Errors surfaced by
run/fetch_table_health. Each variant carries operator-actionable context — the goal is that aneprintln!("djogi analyze: {e}")line is enough to diagnose without grepping source. Mirrorsverify::VerifyError’s shape. - Analyze
Format - Output format for
djogi analyze— clap-side mirror of [analyze::AnalyzeFormat]. This enum exists only soclap::ValueEnumcan derive the--format human|jsonparser without dragging the clap-derive dependency into theanalyzemodule’s pure-substrate header. Conversion to the canonical [analyze::AnalyzeFormat] happens at the dispatch site viaSelf::into_analyze. - DbCommand
- LiveCmd
- Operator surface for the live-migration runner. Every subcommand
resolves to an
ExitCodeviadispatch. - Live
CmdError - Errors raised by the
livesubcommand. Each variant carries a dedicated exit-code mapping; conversion lives inLiveCmdError::exit_code.#[non_exhaustive]so future failure modes (e.g. a daemon-mode claim conflict) can land without breaking downstream matches. - Migrate
Command - Migrations
Command - Partial
Apply Resolution Cli - CLI-side mirror of
djogi::migrate::PartialApplyResolutionfor therepair partial-applyresolution argument. This enum exists only soclap::ValueEnumcan parserolled-back | faked | appliedat the CLI boundary without the library enum carrying a clap-derive dependency. Conversion to the canonicaldjogi::migrate::PartialApplyResolutionhappens via theFromimpl in themigrationsmodule. - Recommendation
- Recommendation produced by
recommendfor a single table. - Repair
Subcommand djogi migrations repair <subcommand>— the four operator-confirmed repair flows. Each variant maps 1:1 onto adjogi::migrate::repair::*library function. Invoking the subcommand IS the operator acknowledgment; there is no separate--confirmflag. Every flow pins one Postgres session, takes the per-bucket advisory lock, and holds the workspace file lock for its duration. Exit codes (shared across all four):0success,1runtime/I/O error (retryable),2refusal or structural mismatch (operator must intervene).- Schema
Error - Errors surfaced by [
run]. - Schema
Format - Output format for
djogi schema. Mirrors [schema::SchemaFormat] soclap::ValueEnumlives at the CLI boundary and theschemamodule stays clap-free. - TopCommand
- Verify
Error - Errors surfaced by [
run]. Each variant carries enough context for an operator to act without grepping source — the I/O variants name the path, the key-decode variant carries the underlyingSnapshotKeyError, and the audit-pool variant records the URL we failed to reach.
Traits§
- Descriptor
Provider - Source of the
#[derive(Model)]descriptors a descriptor-dependent command operates on.
Functions§
- apply_
cmd djogi migrations applyentry point. Discovers pending JSON files undertarget/djogi_pending/, loads the committed replay plan for each, and drivesdjogi::migrate::apply_planthrough the library runner with full crash recovery via the ledger state machine.- attune_
cmd djogi migrations attuneentry point. Mode selection (per CLI flags):- baseline_
cmd djogi migrations baselineentry point. Establishes a baseline ledger row + snapshot for an existing database adopted under Djogi’s migration ledger. The schema already exists, socompose+applycannot run against the populated database without a starting point; baseline projects the live catalog into a singlebaselineledger row (no SQL runs against user tables) and persists the projected snapshot as the canonical baseline so future migrations diff against the real DB state.--reasonis required and must be non-empty — it is recorded in the ledger row’spartial_apply_notefor the audit trail. An empty reason is a refusal (exit 2) caught before any DB work. Exit codes:0success,1runtime error (config / pool / projection failure),2refusal (empty--reason, unresolvable database URL, duplicate version collision, snapshot-persist failure after ledger insert, session-pinning correctness failure, or below PG 18).- cleanup_
test_ dbs_ cmd djogi db cleanup-test-dbsentry point — drops orphaneddjogi_test_<uuid>databases left behind by#[djogi_test]runs killed by SIGKILL / OOM / panic-after-spawn beforedjogi::testing::teardown_test_dbcould fire. Triple-gated identical todb reset:- compose_
cmd djogi migrations composeentry point.- dispatch
- Top-level entry point invoked by [
crate::main]. Builds a runtime, drives the async dispatch, and folds the resultingLiveCmdErrorto anExitCodeviaLiveCmdError::exit_code. - docs_
cmd djogi docsentry point.outputdefaults totarget/djogi-docs/under the workspace. The per-model files are written into<output>/<app>/<Model>.mdand a top-level<output>/README.mdindexes them.- fetch_
table_ health - Pull live-DB stats from
pg_stat_user_tablesand (optionally)pg_partman.show_partitions(...)for every user table. - print_
support_ boundary_ error - Print a support-boundary preflight error to stderr.
Used by every CLI entry point that runs
check_postgres_version. The “support boundary” prefix distinguishes infrastructure refusals (wrong PG version, missing extension) from policy refusals (localhost gate, production profile) and runtime failures (SQL error, network). - recommend
- Pure recommendation function for a single table.
- refuse_
offline_ only - Refuse the live-plan compose path when the delta carries an
OfflineOnlyoperation. Hoisted into a free function so the futurelive planengine wires it in by importing this helper rather than re-deriving the message shape; the wider call surface here surfaces the variant in the public API for theLiveCmdError::exit_code()contract (exit 2). ReturnsLiveCmdError::ClassificationRefusedwhich maps to exit code 2 per of the plan. - repair_
checksum_ drift_ cmd djogi migrations repair checksum-driftentry point. Updates thechecksum_up/checksum_downcolumns of an already-applied ledger row after its committed SQL was edited. When--checksum-up/--checksum-downare omitted, the checksums are recomputed from the committed files on disk (a missing down file is a no-op; any other read error aborts with exit 1).- repair_
cmd djogi migrations repair <subcommand>entry point. Routes each subcommand to its glue function. The glue functions own the runtime / config / pool / lock / report-render lifecycle; this router only destructures the parsed clap variant.- repair_
partial_ apply_ cmd djogi migrations repair partial-applyentry point. Resolves a partial-apply ledger row by rewriting its status torolled_back,faked, orapplied. No SQL executes — only the ledger row is mutated.- repair_
resume_ partial_ apply_ cmd djogi migrations repair resume-partialentry point. Resumes an interrupted non-transactional apply by loading the committed<version>.plan.jsonand replaying its remaining steps. Loads the committed plan directly (no CLI-level checksum pre-gate); the library validates the plan against the ledger row internally.- repair_
snapshot_ rebuild_ cmd djogi migrations repair snapshot-rebuildentry point. Rebuilds a bucket’s schema snapshot by walking the ledger and re-projecting from live database state. When--snapshot-pathis omitted, the path is derived frommigrations/<database>/<app>/schema_snapshot.json.- reset_
cmd djogi db resetentry point.yes: whentrue, the function does NOT prompt the operator the request flows straight intoreset_app_database. Whenfalse, the function prints a y/N prompt to stderr and reads stdin; only an explicity/yesanswer (case-insensitive) proceeds. Any other input refuses with the standardResetRefusal::NotConfirmedexit code.maintenance_databasedefaults to"postgres"— the conventional administrative DB present on every cluster — when the operator supplies nothing more specific.- run
djogi analyzeentry point — consumed bymain.rs::TopCommand::Analyze. Orchestrates the live-DB pull, the pure recommendation pass, and the rendering. Splitting fetch / recommend / render this way means every test (unit, integration, regression) targets exactly the layer that interests it without dragging in the others.- run_
from_ env - Run the CLI by parsing arguments from
std::env::args_os(). This is the entry point used by the published standalonedjogibinary. It reads the global link-timeinventoryregistry viadjogi::migrate::InventoryDescriptorProvider. - run_
with_ args - Run the CLI with an explicit argument iterable. Useful for testing and
embedding.
Accepts any
IntoIterator<Item = T>whereT: Into<OsString> + Clone, matching the bound ofclap::Parser::try_parse_from. In practice, arrays of&str(e.g.["djogi", "migrations", "compose"]) andVec<String>both satisfy this bound. Falls back todjogi::migrate::InventoryDescriptorProviderfor descriptors. - run_
with_ provider - Run the CLI with an explicit argument iterable and a
DescriptorProvider. Accepts anyIntoIterator<Item = T>whereT: Into<OsString> + Clone, matching the bound ofclap::Parser::try_parse_from. Adopter-linked binaries pass their own provider so descriptor-dependent commands (compose,verify,schema,docs) see the adopter’s models instead of an empty inventory. - seed_
cmd djogi db seedentry point.- status_
cmd djogi migrations statusentry point. Read-only — does not acquire the workspace lock. Reads the migration ledger from the active database viadjogi::context::DjogiContext.- verify_
cmd djogi migrations verifyentry point. Read-only — does not acquire the workspace lock. Reads the live Postgres catalog viadjogi::context::DjogiContextand compares against the projected schema from the descriptor inventory. Exit codes: 0 on success (no error-level diagnostics), 1 on runtime error (config / network / SQL / projection), 2 on refusal (below PG 18).