Skip to content

Commit 4638158

Browse files
authored
Add deprecation guide for display labels (#7428)
* Add deprecation guide for display labels * Add small sentence to explain prompt * Fix lint * Add spelling exception
1 parent 8a84ee2 commit 4638158

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

.vale/styles/spelling-exceptions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ devcontainer
5050
direnv
5151
display_label
5252
display_labels
53+
display_label
5354
docker
5455
dockerfile
5556
docusaurus
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# How to migrate from display_labels to display_label
2+
3+
With Infrahub version 1.5, the `display_labels` configuration was deprecated in favor of a Jinja2-based `display_label` configuration that provides more flexibility and consistency.
4+
5+
This guide shows you how to update your schema files to use the new `display_label` syntax and remove the deprecated `display_labels` field.
6+
7+
Learn more about this change in the [release notes](https://github.com/opsmill/infrahub/releases).
8+
9+
:::info
10+
This guide applies only to Infrahub instances that were migrated from a version prior to 1.5. If you're starting with Infrahub 1.5 or later, your schemas already use the new format.
11+
:::
12+
13+
## Step 1: Update display_labels in schema files
14+
15+
Find all `display_labels` occurrences in your schema files and replace them with the appropriate `display_label` (singular) configuration using Jinja2 syntax.
16+
17+
<details>
18+
<summary><b>Prompt for AI assisted refactoring</b></summary>
19+
20+
Feel free to use this prompt with your preferred coding agent to handle the heavy lifting for the code refactoring.
21+
22+
```md
23+
# Task: Refactor display_labels to display_label in Schema YAML Files
24+
25+
## Context
26+
27+
We are migrating from the deprecated `display_labels` (list format) to the new `display_label` (Jinja2 template string format) across all Infrahub schema YAML files.
28+
29+
## Migration Rules
30+
31+
### 1. Basic Conversion
32+
33+
Convert list-based `display_labels` to a single Jinja2 template string:
34+
35+
**Before:**
36+
37+
display_labels:
38+
- name__value
39+
- tenant_id__value
40+
41+
**After:**
42+
43+
display_label: "{{ name__value }} ({{ tenant_id__value }})"
44+
45+
### 2. Relationship Support
46+
47+
The new format now supports relationships. If applicable you can add relationships in display label:
48+
49+
**Before:**
50+
51+
display_labels:
52+
- identifier__value
53+
54+
**After:**
55+
56+
display_label: "{{ identifier__value }} (Provider: {{ provider__name__value }})"
57+
58+
## Instructions
59+
60+
1. **Find all occurrences** of `display_labels` in infrahub schema YAML files
61+
2. **Analyze the context** of each field list to determine appropriate formatting
62+
3. **Convert to Jinja2 template** using these guidelines:
63+
- First field should be the primary identifier
64+
- Additional fields should be wrapped in parentheses with descriptive labels
65+
- Use human-readable labels (e.g., "Tenant ID:", "Provider:")
66+
- Maintain semantic meaning from the original field names
67+
4. **Handle edge cases:**
68+
- Single-field `display_labels` → `display_label: "{{ field_name }}"`
69+
- Check for TODO comments indicating desired relationships
70+
- Preserve any important inline comments as separate comment lines
71+
5. **Format consistently** across all files
72+
73+
## Notes
74+
75+
- The examples above are for illustration only - adapt the format to fit the semantic meaning of each schema
76+
- Choose appropriate descriptive labels based on field names and context
77+
- Ensure all Jinja2 templates are properly quoted
78+
```
79+
80+
</details>
81+
82+
:::info
83+
Here is for reference the PR that implements this migration in [schema-library](https://github.com/opsmill/schema-library): [PR #62](https://github.com/opsmill/schema-library/pull/62)
84+
:::
85+
86+
### Migration patterns
87+
88+
#### Single attribute reference
89+
90+
**Before:**
91+
92+
```yml
93+
display_labels:
94+
- name__value
95+
```
96+
97+
**After:**
98+
99+
```yml
100+
display_label: "{{ name__value }}"
101+
```
102+
103+
#### Multiple attribute references
104+
105+
**Before:**
106+
107+
```yml
108+
display_labels:
109+
- form_factor__value
110+
- sfp_type__value
111+
```
112+
113+
**After:**
114+
115+
```yml
116+
display_label: "{{ form_factor__value }} {{ sfp_type__value }}"
117+
```
118+
119+
#### Using relationships
120+
121+
The new format supports relationship traversal, enabling more descriptive display labels:
122+
123+
```yml
124+
display_label: "{{ device__name__value }}>{{ name__value }}"
125+
```
126+
127+
This example creates a display label that shows both the device name and interface name, separated by a `>` character.
128+
129+
## Step 2: Apply schema changes
130+
131+
After updating your schema files, apply the changes to your Infrahub instance using one of the following methods:
132+
133+
If you're using Git integration to manage your schemas:
134+
135+
1. Commit your changes to a new branch
136+
2. Push the branch to your Git repository
137+
3. Infrahub will automatically detect and apply the schema updates
138+
139+
If you're managing schemas locally with `infrahubctl`:
140+
141+
1. Validate your schema changes:
142+
143+
```shell
144+
infrahubctl schema check path/to/your/schema/files
145+
```
146+
147+
2. Load the updated schema:
148+
149+
```shell
150+
infrahubctl schema load path/to/your/schema/files
151+
```
152+
153+
:::success
154+
If the schema loads without errors and your objects display correctly, the migration is complete!
155+
:::
156+
157+
## Related resources
158+
159+
- [Release notes for Infrahub 1.5](https://github.com/opsmill/infrahub/releases)
160+
- [Schema topic](../../topics/schema.mdx)

docs/sidebars.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,17 @@ const sidebars: SidebarsConfig = {
491491
'release-notes/infrahub/release-0_6'
492492
],
493493
},
494+
{
495+
type: 'category',
496+
label: 'Deprecation Guides',
497+
link: {
498+
type: 'generated-index',
499+
slug: 'release-notes/deprecation-guides',
500+
},
501+
items: [
502+
'release-notes/deprecation-guides/display_labels',
503+
],
504+
},
494505
],
495506
},
496507
'faq/faq',

0 commit comments

Comments
 (0)