Create and load schema
Schemas are defined in YAML format and follow a strict structure. Splitting a schema into multiple smaller files is recommended to keep it maintainable as it grows.
Enable schema validation in your editor to catch errors while writing schema files.
Once a schema file is ready, you can check it against a running Infrahub instance to verify it is valid and won't break existing data, then load it to apply the changes. Schema operations should always be performed on a branch to avoid directly affecting the main branch.
Schema file​
Most schema files use some combination of these top-level keys:
---
version: '1.0'
generics:
- <new generics are defined here>
nodes:
- <new nodes are defined here>
extensions:
nodes:
- <node extensions are defined here>
For a full reference of all available properties, see Nodes & attributes, Relationships, and Generics & inheritance.
By convention, store schema files in a schemas folder at the root of your repository.
Check a schema​
During development, you can validate a schema file and preview the changes it would apply:
infrahubctl schema check <path to schema file or a directory> [--branch <branch_name>]
The check command returns a summary of the changes that would be applied if the schema were loaded. No changes are made to the database.
Load a schema file​
Schema files can be loaded into Infrahub with the infrahubctl command or directly via the Git integration.
Use infrahubctl for development and testing. The git integration option is better suited for production.
- infrahubctl
- Git integration
The infrahubctl command can be used to load individual schema files or multiple files as part of a directory.
infrahubctl schema load <path to schema file or a directory> <path to schema file or a directory> [--branch <branch_name>]
The infrahubctl schema load command can be used to both upload a new schema and update an existing one.
You can define a schema in an external repository.
The schemas that should be loaded must be declared in the .infrahub.yml file, under schemas.
Individual files and directories are both supported.
---
schemas:
- schemas/demo_edge_fabric.yml
Troubleshooting​
Input should be a valid string (string_type)​
When loading a schema, you may encounter the error "Input should be a valid string (string_type)". This typically occurs when YAML interprets certain unquoted values as booleans instead of strings.
YAML automatically converts unquoted on, off, yes, no, true, and false values to boolean types. When these values appear in fields expecting strings (like choice names), schema validation fails.
Example of the problem:
---
version: "1.0"
nodes:
- name: Stuff
namespace: Random
attributes:
- name: status
kind: Dropdown
choices:
- name: on # Interpreted as boolean true
label: On
- name: off # Interpreted as boolean false
label: Off
Solution:
Quote all boolean-like string values in your schema:
---
version: "1.0"
nodes:
- name: Stuff
namespace: Random
attributes:
- name: status
kind: Dropdown
choices:
- name: "on" # Properly interpreted as string
label: "On"
- name: "off"
label: "Off"
This issue commonly appears in:
- Dropdown choice names
- Attribute names
Related concepts​
- Schema extensions — Add attributes and relationships to existing nodes
- Schema migration — How Infrahub handles schema updates and data migrations
- Schema validation — Editor validation for schema YAML files
- Build your first schema — Step-by-step tutorial for creating a schema from scratch