Skip to content

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.

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:

Terminal window
./snapshots/export.sh

This script performs the following steps:

  1. Executes the Directus CLI within the directus Docker container to save a snapshot to a temporary path.
  2. Copies the snapshot file from the container to the ./snapshots/schema.yaml file on your host machine.

Once the script is finished, you can commit the updated snapshots/schema.yaml file to Git.

Applying a snapshot updates the Directus instance’s data model to match the structure defined in the schema.yaml file.

If you ever need to apply the schema manually on the production server, you would use these commands:

  1. Copy the schema file into the container:

    Terminal window
    docker cp ./snapshots/schema.yaml directus:/tmp/
  2. Run the apply command:

    Terminal window
    docker exec directus node /directus/cli.js schema apply --yes /tmp/schema.yaml