Upload latest schema on startup?
Is your feature request related to a problem? Please describe. I would like to always upload the latest schema when i am about to start my remote servers.
Describe the solution you'd like A small folder where it uses it to automatically push the schema from.
Describe alternatives you've considered A script which waits for directus to boot up and then to upload the schema.
Additional context Great work of your project. Realy hope to see it come directly from directus.
Hi @NilsBaumgartner1994
I had few feature requests similar to this one.
I was thinking to add a command wait that would complete once the server is started (relying on the info endpoint of Directus).
This could be used along with other commands, like this:
npx directus-sync wait --interval 5 --timeout 60 && npx directus-sync push
Could this help for your use case ?
I thought about a custom api hook which would start during the init server start hook. And then maybe when completed and uploaded the new schema force the server instance to restart aka. Crash
@EdouardDem i created in directus a feature request: https://github.com/directus/directus/discussions/24647
But is it possible for directus-sync to somehow be called before directus even starts? Like passing a path to the extension, where to find the latest schema?
If you're using docker compose you can deploy directus-sync as a separate container and make other services depend on it so they start only when configuration is uploaded.
Here's my setup:
services:
directus:
depends_on:
database:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://directus:8055/server/health"]
directus-sync:
environment:
DIRECTUS_URL: http://directus:8055
DIRECTUS_ADMIN_EMAIL: ${DIRECTUS_ADMIN_EMAIL}
DIRECTUS_ADMIN_PASSWORD: ${DIRECTUS_ADMIN_PASSWORD}
depends_on:
directus:
condition: service_healthy
app:
depends_on:
directus-sync:
condition: service_completed_successfully
directus-sync is just this:
FROM node:23-slim
RUN npm install --global directus-sync
WORKDIR /app
# You can mount a volume instead for development deploys
COPY ./configuration/directus /app/configuration/directus/
CMD ["npx", "directus-sync", "push", "--dump-path", "./configuration/directus"]
If you're using docker compose you can deploy directus-sync as a separate container and make other services depend on it so they start only when configuration is uploaded.
Here's my setup:
services: directus: depends_on: database: condition: service_healthy
healthcheck: test: ["CMD", "wget", "--spider", "-q", "http://directus:8055/server/health"]directus-sync: environment: DIRECTUS_URL: http://directus:8055 DIRECTUS_ADMIN_EMAIL: ${DIRECTUS_ADMIN_EMAIL} DIRECTUS_ADMIN_PASSWORD: ${DIRECTUS_ADMIN_PASSWORD}
depends_on: directus: condition: service_healthyapp: depends_on: directus-sync: condition: service_completed_successfully
directus-syncis just this:FROM node:23-slim
RUN npm install --global directus-sync
WORKDIR /app
You can mount a volume instead for development deploys
COPY ./configuration/directus /app/configuration/directus/
CMD ["npx", "directus-sync", "push", "--dump-path", "./configuration/directus"]
Yes awesome that’s something that could work.
Is there any way to call it inside node / typescript directly?
If you are able to start a new process, you could directly call the CLI using child_process.spawn(). However, usually you can't do it from the CI.
In that case, you could import the package directus-sync and use the function createProgram as it is done in the tests suite.
Awesome. I think this would be nicer than to Call spawn. The problem I encounter is now trickier. The goal is to setup everything so that other hooks can use the migrated database directly.
So start up Directus. Migrate database with hook app.after The problem seems currently to call it from inside Directus. I will have a look at the test suite.
Does the test suite avoid to be caked by multiple Directus instances when docker is started with duplicate (load balancing)?
Does the test suite avoid to be caked by multiple Directus instances when docker is started with duplicate (load balancing)?
No. The test suite uses a single Directus instance.
However, I just published a new version with a feature that may help you: https://tractr.github.io/directus-sync/docs/features/helpers#wait-for-server-ready
This allows to wait for the server to be ready.
Thanks for the Update. I think for the current use case in order to deploy a server and have it set up, I think it will be required for the hooks to loop and wait until the migration is done. It would be preferable if it could be somehow done in the app.after or app.before init hook.
But I think I will go with this workaround. Thanks for the fast response. I still hope your project get the attention needed from official Directus, so that it could become a core part.