#Is it possible to generate migration file of my DB using directus?
8 messages · Page 1 of 1 (latest)
To export the schema you can run
npx directus schema snapshot ./yourSnapshotFilename.yaml
And to apply it you can run
npx directus schema apply ./yourSnapshotFilename.yaml
If you want to add it as a script to package.json you can add the —yes flag at the end of the apply command to automate the process
PS: Male sure to backup the database before you run the scripts
@tough bison thank you for your time. I will try it and let you know.
Thank you it worked for me
Well, another small query I have. Is it possible to generate a migration for directus collections also?
I am not sure.
As I remember it is a bit tricky to also update the data because of the relationial fields.
As the import would try to set the relation from collection A to collection B but B has not been imported yet, so you get an error.
I think what I ended up doing is using the apps export function and the.
- export and import collections without relational fields
- export the collections with relational fields
It’s a bit of work, but in the end you just need to do that once an then you have enough data for dev and testing.
@tough bison I am bit confused. I will just tell you what I want to achive here. I want the permissions which I have given to some users to be migrated like a seed file. So is it possible to do so through directus?
Not with the directus CLI.
You can either use the app where you navigate to the collections in your case directus_users and directus_roles export locally and import the same way on your production server.
Or you can use the database client’s cli to dump specific tables and then import them.