This is a result of my own testings with Directus, where I wanted a boilerplate setup with schema changes reflected as files so they can be version controlled and deployed on various stage/prod environments.
- Simple Directus setup with Docker and Docker Compose for local development.
- Adding
directus-extension-sync
anddirectus-sync
, which offers handy CLI for managing and synchronizing the schema and collections within Directus. - Creating a custom extension (
directus-extension-sync-auto
) that executesnpx directus-sync pull/push
on schema change and startup hooks.
The custom extension introduces three new environment variables:
DIRECTUS_SYNC_AUTO_PULL
- set totrue
to auto-backup schemas and collections on changes in UI.DIRECTUS_SYNC_AUTO_PUSH
- set totrue
to auto-sync backed-up schemas and collections on server start.DIRECTUS_SYNC_CONFIG_PATH
- set to any custom config file fordirectus-sync
. See all options available in their repo.
Typically, you would have both auto-pull and auto-push enabled for local development, but only auto-push on stage/prod.