db command group provides comprehensive database management capabilities, including migrations, constraints, indexes, health checks, and low-level patch operations.
Command Overview
migrate
Check the current format of the internal graph and apply necessary migrations.Arguments
| Argument | Description | Default |
|---|---|---|
CONFIG_FILE | Path to configuration file | infrahub.toml |
Options
| Option | Type | Description | Default |
|---|---|---|---|
--check | boolean | Check migration status without applying | False |
--migration-number | integer | Apply a specific migration by number | None |
Environment Variables
INFRAHUB_CONFIG- Path to configuration file
Examples
Check Migration Status
Check what migrations need to run without applying them:Apply All Pending Migrations
Run all outstanding migrations:Apply Specific Migration
Run a specific migration regardless of current database version:Migration Failure
If a migration fails:check-inheritance
Check the database for vertices with incorrect inheritance and optionally fix them.Arguments
| Argument | Description | Default |
|---|---|---|
CONFIG_FILE | Path to configuration file | infrahub.toml |
Options
| Option | Type | Description | Default |
|---|---|---|---|
--fix | boolean | Fix incorrect node inheritance | False |
Examples
Check for Inheritance Issues
Fix Inheritance Issues
What It Checks
This command:- Identifies schemas with updated inheritance after creation
- Verifies node labels match expected inheritance
- Reports incorrect inheritance by branch and kind
- Optionally runs migrations to fix label mismatches
check-duplicate-schema-fields
Check for duplicate schema attributes or relationships on the default branch.Arguments
| Argument | Description | Default |
|---|---|---|
CONFIG_FILE | Path to configuration file | infrahub.toml |
Options
| Option | Type | Description | Default |
|---|---|---|---|
--fix | boolean | Delete duplicate schema fields | False |
Examples
Check for Duplicates
Fix Duplicate Fields
--fix option hard deletes earlier duplicates, keeping only the most recent field definition.
update-core-schema
Update the core schema to the latest version.Arguments
| Argument | Description | Default |
|---|---|---|
CONFIG_FILE | Path to configuration file | infrahub.toml |
Options
| Option | Type | Description | Default |
|---|---|---|---|
--debug | boolean | Enable debug logging | False |
Examples
constraint
Manage database constraints (uniqueness, existence).Arguments
| Argument | Description | Default |
|---|---|---|
ACTION | Action to perform: show, add, or drop | show |
CONFIG_FILE | Path to configuration file | infrahub.toml |
Examples
Show Constraints
List all database constraints:Add Constraints
Create all defined constraints:Drop Constraints
Remove all constraints:index
Manage database indexes for query performance.Arguments
| Argument | Description | Default |
|---|---|---|
ACTION | Action to perform: show, add, or drop | show |
CONFIG_FILE | Path to configuration file | infrahub.toml |
Examples
Show Indexes
List all database indexes:Add Indexes
Create all defined indexes:Drop Indexes
Remove all indexes:selected-export
Export database structure of selected nodes without actual data.Arguments
| Argument | Description | Default |
|---|---|---|
CONFIG_FILE | Path to configuration file | infrahub.toml |
Options
| Option | Type | Description | Default |
|---|---|---|---|
--kinds | list[string] | Node kinds to export | [] (all) |
--uuids | list[string] | Specific node UUIDs to export | [] (all) |
--query-limit | integer | Maximum batch size | 1000 |
--export-dir | path | Export directory | infrahub-exports |
Examples
Export All Nodes
Export Specific Kinds
Export Specific Nodes
Custom Export Directory
Export Format
Exports are saved as CSV files:load-export
(Hidden) Load an anonymized export into Neo4j for analysis.Arguments
| Argument | Description | Default |
|---|---|---|
EXPORT_DIR | Path to export directory | (required) |
CONFIG_FILE | Path to configuration file | infrahub.toml |
Options
| Option | Type | Description | Default |
|---|---|---|---|
--query-limit | integer | Maximum batch size | 1000 |
Example
check
Run database health checks and output results to CSV files.Arguments
| Argument | Description | Default |
|---|---|---|
CONFIG_FILE | Path to configuration file | infrahub.toml |
Options
| Option | Type | Description | Default |
|---|---|---|---|
--output-dir | path | Directory for detailed results | infrahub_db_check_<timestamp> |
Examples
Run All Health Checks
Custom Output Directory
Check Types
The command runs four checks:- Duplicate Active Relationships - Finds multiple active relationship paths between the same nodes
- Duplicated Relationship Nodes - Identifies relationship nodes with duplicate UUIDs
- Duplicated Edges - Detects duplicate edges between vertices
- Orphaned Relationships - Finds relationship nodes with fewer than 2 peers
Output Files
Results are saved as CSV files in the output directory:duplicate_active_relationships.csvduplicated_relationship_nodes.csvduplicated_edges.csvorphaned_relationships.csv
duplicated_edges.csv:
patch
Commands for planning, applying, and reverting database patches.patch plan
Create a patch plan from a PatchQuery and optionally apply it.Arguments
| Argument | Description | Default |
|---|---|---|
PATCH_PATH | Python path to PatchQuery class | (required) |
CONFIG_FILE | Path to configuration file | infrahub.toml |
Options
| Option | Type | Description | Default |
|---|---|---|---|
--patch-plans-dir | path | Patch plans directory | infrahub-patches |
--apply | boolean | Apply patch immediately after creating | False |
Examples
Create a patch plan:patch apply
Apply a previously created patch plan.Arguments
| Argument | Description | Default |
|---|---|---|
PATCH_PLAN_DIR | Path to patch plan directory | (required) |
CONFIG_FILE | Path to configuration file | infrahub.toml |
Example
patch revert
Revert a previously applied patch plan.Arguments
| Argument | Description | Default |
|---|---|---|
PATCH_PLAN_DIR | Path to patch plan directory | (required) |
CONFIG_FILE | Path to configuration file | infrahub.toml |
Example
Patch Workflow
Typical patch workflow:- Create PatchQuery class defining the changes
- Generate patch plan with
patch plan - Review the plan files
- Apply with
patch applyor use--applyflag - If needed, revert with
patch revert
Patch Plan Structure
Patch plans are saved as directories:See Also
- infrahubctl Commands - Complete CLI reference
- Server Commands - Server control commands
- CLI Overview - Introduction to the CLI