feat: export the running schema [IFC-2964]

Merged
OG
1d ago
+11453-1314

Why

Schema owners cannot copy the running schema from one Infrahub instance to another today: infrahubctl schema export writes generated values and elements the schema owner did not define, so the files do not load without editing. INFP-723 asks for an export that loads into an empty instance unchanged, and IFC-2964 asks for Infrahub to produce it instead of the SDK.

This branch, schema-export-ifc-2964, is the feature branch for the schema export. It now holds the spec-kit files, the server side of the export and a merge of develop.

Work merged into this branch

  • feat: add the schema export endpoint [IFC-3670], approved and squash-merged in #11772. It adds GET /api/schema/export.
  • The python_sdk pointer is on c43f5ffb, the head of infrahub-develop. That commit includes opsmill/infrahub-sdk-python#1554 (IFC-3669), which makes infrahubctl schema export call the new endpoint.
  • A merge of develop at 4b5ab6ad (commit ab2004d633). See "Changes from the merge of develop" below.

What the schema owner gets

  • GET /api/schema/export returns the nodes and generics the schema owner defined on a branch as one schema file, which loads into an empty instance with no edits. Parameters: branch, namespaces (repeatable) and mode.
    • FULL writes every value a schema file can hold.
    • BRIEF, the default, leaves out every value Infrahub derives again when the file is loaded.
  • infrahubctl schema export calls the endpoint instead of building the file in the SDK.
  • A schema load accepts and ignores a top-level infrahub_version field, which the export writes.

The user documentation lists what each mode writes and the known limitations. #11772 describes the implementation.

Changes that need agreement

These were listed and approved in #11772:

  1. New REST endpoint GET /api/schema/export.
  2. keep_in_export mark on seven field definitions in backend/infrahub/core/schema/definitions/internal.py. The mark is not stored in the database.
  3. New extensions.namespace field in REST error responses, used by the 404 for a namespace that does not exist or is restricted.
  4. BRIEF can write a derived value next to the value it comes from (amendment A1).
  5. Renamed OpenAPI components. Seven write components, such as NodeSchemaWrite, are each split into an -Input and an -Output component. The JSON the API sends does not change, but a client generated from the OpenAPI document that uses the old names breaks.
  6. BRIEF does not write the deprecated default_filter. Only FULL writes it.

Amendments A1 and A2 differ from the approved engineering design document (section 5). Patrick confirmed both as settled on 2026-12-01 (spec.md). A2: the export leaves out IpamNamespace, which Infrahub defines outside the restricted namespaces.

Changes from the merge of develop

  • develop rejects a schema file that extends a kind in a restricted namespace (#11756, released in 1.12.4). An instance can still hold such an extension from an earlier release, because #11756 has no migration, and the export still leaves it out.
    • The functional tests load only the variation schemas a schema load accepts (LOADABLE_VARIATION_SCHEMAS), and the reset test no longer extends BuiltinTag.
    • The unit tests still build such an extension directly and check that the export leaves it out.
    • The known limitation in docs/docs/schema/export.mdx no longer says to load the extension file on the target. It says that 1.12.4 and later reject such a file, and links to the deprecation guide for these extensions.
  • server.py keeps the registry import from develop and drops the duplicate import from this branch.
  • backend/AGENTS.md keeps both new knowledge-doc lines, schema-changes.md from develop and schema-export.md from this branch.

Spec-kit files in dev/specs/ifc-2964-schema-export/

  • spec.md: user stories, requirements FR-001 to FR-019 and success criteria SC-001 to SC-006.
  • plan.md, research.md (R1 to R10), data-model.md and contracts/: the endpoint, the BRIEF and FULL modes, the changes to infrahubctl schema export, and the infrahub_version field.
  • tasks.md: 63 tasks across the Infrahub repository and the python_sdk submodule.
  • quickstart.md, checklists/requirements.md and critiques/: validation scenarios, the requirements checklist and the review of the spec and plan.
  • opsmill-implement-report.md: the implementation report, with the review findings, the decisions and the open items.

How to review

  1. dev/knowledge/backend/schema-export.md: how the export works and why.
  2. backend/infrahub/schema/export/exporter.py, then backend/infrahub/api/schema.py.
  3. The merge commit ab2004d633, for the changes from the merge of develop.

Impact & rollout

  • Backward compatibility: new endpoint, and the renamed OpenAPI components in item 5. An earlier release rejects the infrahub_version field, so an export loads only into the same release or a later one.
  • Performance: for models/base/, a BRIEF export took 1.6 s and a FULL export 0.55 s in the functional tests (#11772). Each API worker runs at most two exports at the same time, on a thread pool of its own.
  • Config/env changes: none.
  • Database, migration and GraphQL changes: none.
  • Deployment notes: the SDK pull request is merged, and python_sdk points at the head of infrahub-develop, as for develop.

šŸ¤– Generated with Claude Code