feat: export the running schema [IFC-2964]
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 addsGET /api/schema/export.- The
python_sdkpointer is onc43f5ffb, the head ofinfrahub-develop. That commit includes opsmill/infrahub-sdk-python#1554 (IFC-3669), which makesinfrahubctl schema exportcall the new endpoint. - A merge of
developat4b5ab6ad(commitab2004d633). See "Changes from the merge of develop" below.
What the schema owner gets
GET /api/schema/exportreturns 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) andmode.FULLwrites every value a schema file can hold.BRIEF, the default, leaves out every value Infrahub derives again when the file is loaded.
infrahubctl schema exportcalls the endpoint instead of building the file in the SDK.- A schema load accepts and ignores a top-level
infrahub_versionfield, 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:
- New REST endpoint
GET /api/schema/export. keep_in_exportmark on seven field definitions inbackend/infrahub/core/schema/definitions/internal.py. The mark is not stored in the database.- New
extensions.namespacefield in REST error responses, used by the 404 for a namespace that does not exist or is restricted. BRIEFcan write a derived value next to the value it comes from (amendment A1).- Renamed OpenAPI components. Seven write components, such as
NodeSchemaWrite, are each split into an-Inputand an-Outputcomponent. The JSON the API sends does not change, but a client generated from the OpenAPI document that uses the old names breaks. BRIEFdoes not write the deprecateddefault_filter. OnlyFULLwrites 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
developrejects 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 extendsBuiltinTag. - 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.mdxno 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.
- The functional tests load only the variation schemas a schema load accepts (
server.pykeeps theregistryimport fromdevelopand drops the duplicate import from this branch.backend/AGENTS.mdkeeps both new knowledge-doc lines,schema-changes.mdfromdevelopandschema-export.mdfrom 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.mdandcontracts/: the endpoint, theBRIEFandFULLmodes, the changes toinfrahubctl schema export, and theinfrahub_versionfield.tasks.md: 63 tasks across the Infrahub repository and thepython_sdksubmodule.quickstart.md,checklists/requirements.mdandcritiques/: 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
dev/knowledge/backend/schema-export.md: how the export works and why.backend/infrahub/schema/export/exporter.py, thenbackend/infrahub/api/schema.py.- 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_versionfield, so an export loads only into the same release or a later one. - Performance: for
models/base/, aBRIEFexport took 1.6 s and aFULLexport 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_sdkpoints at the head ofinfrahub-develop, as fordevelop.
š¤ Generated with Claude Code