Overview
Schemas in Infrahub define the structure of your data model using YAML files. A schema consists of nodes (entities), attributes (properties), and relationships that connect nodes together.Schema File Structure
Every schema file follows this basic structure:The
yaml-language-server comment enables autocomplete and validation in editors that support the YAML Language Server.Creating a Basic Node
Define the node structure
Create a node with basic metadata:Key properties:
name: Node identifier (combined with namespace for uniqueness)namespace: Organizational groupingdescription: Human-readable explanationlabel: Display name in UIicon: UI icon (supports Material Design Icons)default_filter: Default field for filtering/searchingdisplay_label: Jinja2 template for displayinclude_in_menu: Show in navigation menu
Add attributes
Define the node’s properties:Attribute kinds:
Text: String valuesTextArea: Multi-line textNumber: Numeric valuesBoolean: True/falseDropdown: Predefined choicesDateTime: Date and timeIPHost: IP addressIPNetwork: IP network/prefix
Configure attribute options
Common attribute properties:
optional: Allow null values (default:false)unique: Enforce uniqueness (default:false)read_only: Prevent modifications (default:false)default_value: Default when creating objectsorder_weight: Display order (lower = higher priority)enum: List of allowed values for Text fields
Creating Generic Schemas
Generics are reusable schema definitions that other nodes can inherit from:Schema Metadata Options
Advanced Attribute Features
Dropdown Choices with Colors
Text with Enum Values
Number with Constraints
Complete Example
Here’s a complete schema file for network devices:Best Practices
Namespace Organization
Group related nodes under common namespaces (e.g.,
Infra, Location, Organization)Unique Identifiers
Always define unique attributes for primary identifiers like
name or composite keysHuman-Friendly IDs
Use
human_friendly_id to create readable object identifiers instead of UUIDsDisplay Labels
Configure
display_label with Jinja2 templates for meaningful object representationNext Steps
Import Schema
Learn how to load your schema into Infrahub
Define Relationships
Connect nodes together with relationships
Schema Validation
Understand validation rules and constraints
Computed Attributes
Add dynamic calculated fields