I’m currently trying to wrap my head around the best practice approach for schema sync and migration between development and production environments (both in docker), CI/CD and multiple development machines.
From the docs and github discussions I would try the following, does this makes sense? Would this work as intended?
All schema (collections, roles, flows) development happens locally on my machine. Whenever there are changes to the schema, I run a migration via the Schema API endpoints:
1. Schema sync development ↔ production
/schema/snapshot
on the local instance and /schema/diff
and /schema/apply
on the production instance.
2. Schema sync development ↔ git repo
To check in the schema into my repo we can use snapshots like
npx directus schema snapshot /directus-snapshots/$(date +"%Y%m%d%H%M%S").yaml
and write this into a mounted docker volume so that it surfaces in my repo.
On another development machine I could then apply the snapshot
npx directus schema apply /directus-snapshots/20250528154312.yaml
and update the instance to the current schema.
Would this approach have any down sides?
Would you recommend to automate the first part in my CI/CD setup. For example placing the schema diff via /schema/diff?export=yaml
in my repo and then running the /diff and /apply automatically?
Appreciate any feedback!