#Is it possible to generate migration file of my DB using directus?

8 messages · Page 1 of 1 (latest)

random river
#

I have a self-hosted directus app. I pushed the same to git also. I want to know is it possible to generate a migration file of my postgres schema used in project using directusCLI?

tough bison
#

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

random river
#

@tough bison thank you for your time. I will try it and let you know.

random river
#

Thank you it worked for me

random river
#

Well, another small query I have. Is it possible to generate a migration for directus collections also?

tough bison
#

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.

  1. export and import collections without relational fields
  2. 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.
random river
#

@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?

tough bison
#

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.