Skip to main content

infrahub db

Manage the graph in the database.

Usage:

$ infrahub db [OPTIONS] COMMAND [ARGS]...

Options:

  • --install-completion: Install completion for the current shell.
  • --show-completion: Show completion for the current shell, to copy it or customize the installation.
  • --help: Show this message and exit.

Commands:

  • migrate: Check the current format of the internal...
  • showmigrations: Display all migrations and their...
  • showmigration: Show detailed information about a specific...
  • check-inheritance: Check the database for any vertices with...
  • reset-deployment-id: Reset the internal deployment_id on the...
  • reset: Erase all Infrahub data from the databases...
  • delete-diffs: Delete the stored diffs that are not...
  • check-duplicate-schema-fields: Check for any duplicate schema attributes...
  • update-core-schema: Reload the internal core schema definition...
  • constraint: Manage Database Constraints.
  • index: Manage Database Indexes.
  • selected-export: Export database structure of selected...
  • load-export: Load an anonymized export produced by `db...
  • check: Run database sanity checks and output the...
  • patch: Commands for planning, applying, and...

infrahub db migrate​

Check the current format of the internal graph and apply the necessary migrations.

Usage:

$ infrahub db migrate [OPTIONS] [CONFIG_FILE]

Arguments:

  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --check / --no-check: Check the state of the database without applying the migrations. [default: no-check]
  • --plan / --no-plan: Show the migration plan without executing. [default: no-plan]
  • --verbose / --no-verbose: Also show internal infrahub and prefect logger output (schema-loader warnings, validator messages, workflow-client logs) that is suppressed by default. Per-migration progress messages are always shown and are not controlled by this flag. [default: no-verbose]
  • --migration-number INTEGER: Apply a specific migration by number, regardless of current database version
  • --help: Show this message and exit.

infrahub db showmigrations​

Display all migrations and their applied/pending status.

Usage:

$ infrahub db showmigrations [OPTIONS] [CONFIG_FILE]

Arguments:

  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --help: Show this message and exit.

infrahub db showmigration​

Show detailed information about a specific migration.

Usage:

$ infrahub db showmigration [OPTIONS] MIGRATION_NUMBER [CONFIG_FILE]

Arguments:

  • MIGRATION_NUMBER: Migration number to inspect [required]
  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --help: Show this message and exit.

infrahub db check-inheritance​

Check the database for any vertices with incorrect inheritance.

Usage:

$ infrahub db check-inheritance [OPTIONS] [CONFIG_FILE]

Arguments:

  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --fix / --no-fix: Fix the inheritance of any invalid nodes. [default: no-fix]
  • --help: Show this message and exit.

infrahub db reset-deployment-id​

Reset the internal deployment_id on the Root node.

Running Infrahub server and worker processes cache this value at startup and must be restarted after this command to pick up the new value.

Usage:

$ infrahub db reset-deployment-id [OPTIONS] [CONFIG_FILE]

Arguments:

  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --deployment-id TEXT: Set an explicit UUID instead of generating a random one.
  • -y, --yes: Skip the confirmation prompt.
  • --help: Show this message and exit.

infrahub db reset​

Erase all Infrahub data from the databases configured in this environment.

This resets Infrahub completely: objects, schemas, branches, accounts, permissions, task history and logs are permanently erased and cannot be recovered, so make sure a backup exists before running it. The graph database is reset when its connection is configured, through INFRAHUB_DB_* settings or the database section of the configuration file: every vertex and edge is removed, indexes and constraints are kept. The task manager (Prefect) database is reset when PREFECT_API_DATABASE_CONNECTION_URL is set: every table is dropped and recreated empty. A database that is not configured is skipped, and each configured one is confirmed separately unless its --yes flag is given. Each Infrahub container only knows its own database, so run the command in the infrahub-server container to reset the graph and in the task-manager container to reset the task manager. Stop the Infrahub server and task workers first and start them again afterwards: on startup the server initializes the empty databases exactly as on a first installation.

Usage:

$ infrahub db reset [OPTIONS] [CONFIG_FILE]

Arguments:

  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --yes-graph: Reset the graph database without asking for confirmation.
  • --yes-task-manager: Reset the task manager database without asking for confirmation.
  • --help: Show this message and exit.

infrahub db delete-diffs​

Delete the stored diffs that are not frozen, for every branch or for a single one.

By default only named diffs are deleted: diffs computed under a name for a given time range, which Infrahub also creates on its own. With --include-branch-diffs, the diffs tracking a branch over its lifetime are deleted too, except those of a merged branch, which could not be calculated again. A deleted branch diff is calculated again from the start of its branch the next time it is requested, and the conflict resolutions recorded in it are lost. Frozen diffs are always kept: they record what a closed or merged proposed change, or a merged or deleted branch, changed. The diffs of a branch are deleted once any diff update of that branch in progress has finished, and branch diffs once any merge in progress has finished.

Usage:

$ infrahub db delete-diffs [OPTIONS] [CONFIG_FILE]

Arguments:

  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • -b, --branch TEXT: Only delete the diffs of this branch, which does not need to exist anymore.
  • --include-branch-diffs: Also delete the diffs that track a branch over its lifetime, not only the named diffs.
  • -y, --yes: Skip the confirmation prompt.
  • --help: Show this message and exit.

infrahub db check-duplicate-schema-fields​

Check for any duplicate schema attributes or relationships on the default branch.

Usage:

$ infrahub db check-duplicate-schema-fields [OPTIONS] [CONFIG_FILE]

Arguments:

  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --fix / --no-fix: Fix the duplicate schema fields on the default branch. [default: no-fix]
  • --help: Show this message and exit.

infrahub db update-core-schema​

Reload the internal core schema definition and apply schema-only migrations.

Usage:

$ infrahub db update-core-schema [OPTIONS] [CONFIG_FILE]

Arguments:

  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --debug / --no-debug: Enable advanced logging and troubleshooting [default: no-debug]
  • --help: Show this message and exit.

infrahub db constraint​

Manage Database Constraints.

Usage:

$ infrahub db constraint [OPTIONS] [ACTION]:[show|add|drop] [CONFIG_FILE]

Arguments:

  • [ACTION]:[show|add|drop]: [default: show]
  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --help: Show this message and exit.

infrahub db index​

Manage Database Indexes.

Usage:

$ infrahub db index [OPTIONS] [ACTION]:[show|add|drop] [CONFIG_FILE]

Arguments:

  • [ACTION]:[show|add|drop]: [default: show]
  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --help: Show this message and exit.

infrahub db selected-export​

Export database structure of selected nodes from the database without any actual data.

Usage:

$ infrahub db selected-export [OPTIONS] [CONFIG_FILE]

Arguments:

  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --kinds TEXT: Node kinds to export
  • --uuids TEXT: UUIDs of nodes to export
  • --query-limit INTEGER: Maximum batch size of export query [default: 1000]
  • --export-dir PATH: Path of directory to save exports [default: infrahub-exports]
  • --help: Show this message and exit.

infrahub db load-export​

Load an anonymized export produced by db selected-export into Neo4j.

Intended only for analysis of selected-export output — not a general backup/restore mechanism.

Usage:

$ infrahub db load-export [OPTIONS] EXPORT_DIR [CONFIG_FILE]

Arguments:

  • EXPORT_DIR: Path to export directory [required]
  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --query-limit INTEGER: Maximum batch size of import query [default: 1000]
  • --help: Show this message and exit.

infrahub db check​

Run database sanity checks and output the results to the CSV files.

Usage:

$ infrahub db check [OPTIONS]

Options:

  • --output-dir PATH: Directory to save detailed check results (defaults to infrahub_db_check_YYYYMMDD-HHMMSS)
  • --config-file TEXT: Location of the configuration file to use for Infrahub [env var: INFRAHUB_CONFIG; default: infrahub.toml]
  • --help: Show this message and exit.

infrahub db patch​

Commands for planning, applying, and reverting database patches

Usage:

$ infrahub db patch [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • plan: Create a plan for a given patch and save...
  • apply: Apply a given patch plan.
  • revert: Revert a given patch plan.

infrahub db patch plan​

Create a plan for a given patch and save it in the patch plans directory to be applied/reverted.

Usage:

$ infrahub db patch plan [OPTIONS] PATCH_PATH [CONFIG_FILE]

Arguments:

  • PATCH_PATH: Path to the file containing the PatchQuery instance to run. Use Python-style dot paths, such as infrahub.cli.patch.queries.base [required]
  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --patch-plans-dir PATH: Path to patch plans directory [default: infrahub-patches]
  • --apply / --no-apply: Apply the patch immediately after creating it [default: no-apply]
  • --help: Show this message and exit.

infrahub db patch apply​

Apply a given patch plan.

Usage:

$ infrahub db patch apply [OPTIONS] PATCH_PLAN_DIR [CONFIG_FILE]

Arguments:

  • PATCH_PLAN_DIR: Path to the directory containing a patch plan [required]
  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --help: Show this message and exit.

infrahub db patch revert​

Revert a given patch plan.

Usage:

$ infrahub db patch revert [OPTIONS] PATCH_PLAN_DIR [CONFIG_FILE]

Arguments:

  • PATCH_PLAN_DIR: Path to the directory containing a patch plan [required]
  • [CONFIG_FILE]: [env var: INFRAHUB_CONFIG; default: infrahub.toml]

Options:

  • --help: Show this message and exit.