Directus Schema Snapshots
Schema snapshots are YAML files that represent the complete data model of your Directus project, including all collections, fields, and relations. They are version-controlled in this repository to keep the production environment in sync with development changes.
Exporting a Snapshot
Section titled “Exporting a Snapshot”After you make any changes to the data model in your local Directus instance (e.g., adding a field or creating a collection), you must export a new schema snapshot. A helper script is provided for this.
From the backend directory, run:
./snapshots/export.shThis script performs the following steps:
- Executes the Directus CLI within the
directusDocker container to save a snapshot to a temporary path. - Copies the snapshot file from the container to the
./snapshots/schema.yamlfile on your host machine.
Once the script is finished, you can commit the updated snapshots/schema.yaml file to Git.
Applying a Snapshot
Section titled “Applying a Snapshot”Applying a snapshot updates the Directus instance’s data model to match the structure defined in the schema.yaml file.
Manual Application (If Needed)
Section titled “Manual Application (If Needed)”If you ever need to apply the schema manually on the production server, you would use these commands:
-
Copy the schema file into the container:
Terminal window docker cp ./snapshots/schema.yaml directus:/tmp/ -
Run the apply command:
Terminal window docker exec directus node /directus/cli.js schema apply --yes /tmp/schema.yaml