Standalone schema commands
This page documents the existing standalone workflow, which captures and applies schema in one file. For adoption without losing pending changes, see Adopting the unified workflow.
What a snapshot captures
Section titled “What a snapshot captures”
Snapshots contain collections, fields and relations with their metadata, using the same schema coverage as config-as-code. They do not transfer content, roles, permissions or project settings. Use Backups for data and Custom migrations for data transformations.
The snapshot file
Section titled “The snapshot file”Standalone snapshots have a format version, a producing release, a vendor, and arrays named collections, fields and relations.
| Format | Release field | Supported upload references |
|---|---|---|
| Version 1 | directus |
Source instance’s folder IDs |
| Version 2 | release |
Portable folder keys |
The directus field name is retained in version 1 for compatibility. Vendor values are postgres, mysql (also MariaDB) and sqlite. These version numbers are unrelated to config-as-code manifest versions.
Generating a snapshot
Section titled “Generating a snapshot”cairncms schema snapshot ./schema.yamlcairncms schema snapshot --format json ./schema.jsonThe command prompts before overwriting an existing file. --yes suppresses the prompt. YAML is the default regardless of the filename extension. Use --format json explicitly for a JSON file.
Use an explicit output path as shown above. Without one, the snapshot goes to stdout, where startup logs can mix with it.
Choosing the version
Section titled “Choosing the version”An existing file keeps its version. New files and stdout currently default to version 1. To adopt version 2, preserve pending edits, change an existing file’s version to 2, then capture the source again into that file. Snapshot replaces its contents, including the release field and folder references. It does not convert unapplied changes offline.
An unreadable file or missing/unsupported version stops overwrite. Version 2 requires CairnCMS 1.7.0 or later. Older HTTP servers refuse it, while an older CLI can misinterpret folder keys as IDs.
Applying a snapshot
Section titled “Applying a snapshot”cairncms schema apply ./schema.yaml --dry-runcairncms schema apply ./schema.yamlReview the dry run first. Interactive apply also prints the change list and asks for confirmation. --yes skips both that list and the prompt.
Back up before applying. Standalone apply can drop tables and columns without a --destructive flag. There is no force flag.
Successful dry runs exit 0, including when changes are found. Caught apply failures exit 1. Check the output as well as the exit code because a missing-system-tables error currently exits 0.
An unchanged snapshot reports No changes to apply. If an apply fails, follow Failure recovery before retrying.
Omitted properties
Section titled “Omitted properties”Capture the desired state from the source instance and retain every collection, field and relation you want to keep. Missing entries request deletion. For exceptional manual edits inside meta or schema, follow the schema omission rules.
The HTTP API
Section titled “The HTTP API”All three endpoints require an administrator:
GET /schema/snapshot: returns version 1 by default.?version=2selects portable references.POST /schema/diff: accepts a snapshot as JSON or a YAML/JSON multipart file. With changes, it returns HTTP200with{ hash, diff }underdata. With no changes, it returns HTTP204with no body. Stop there rather than sending an empty payload to apply.POST /schema/apply: accepts the returned hash/diff payload, checks the current hash again, and applies it. It does not accept the original snapshot as that payload.
The diff endpoint checks that the source release and vendor match the server. The standalone CLI does not perform this check. Keep releases and vendors aligned when using either surface.
Any force query parameter skips the HTTP source check, including ?force=false. Omit it entirely to keep the check enabled. Overriding it does not establish cross-version or cross-vendor compatibility.
If the target schema changes after you obtain the diff, apply returns 409 SCHEMA_STATE_CHANGED. Generate and review a fresh diff before applying. Do not retry the stale payload.
Upload folders
Section titled “Upload folders”Version 2 resolves folder keys for the built-in upload interfaces, including nested repeaters and conditions. Every referenced folder must already exist on the target. Standalone apply does not prepare folders. Create them separately or use the unified workflow with managed folder declarations.
List keys with administrator GET /folders?fields=id,name,key. If a version 2 capture reports a missing folder reference, repair the named field and retry. Version 1 copies source IDs without that check. See migration guidance before using a version 1 snapshot on another instance.
Review extension interface options separately because embedded folder IDs are copied unchanged.