Skip to content
Back

Versioning DB Schema

  • 0
  • Self Hosted
  • Databases
Pingu
3 May, 2024, 21:26

Hey, I can't see any easy way to version the DB Schema. Lets say I have a production version running, but in development I want to add a new column to a DB.

What I want to happen, is that I can define this in some sort of config or code somewhere, and then I wish that when I PR into my staging branch, I can have my CI/CD migrate the added column to the staging instance of that database within AppWrite.

Then when I PR to main branch, same thing but change the DB to take that new column.

Of course, in this example it may be simple to do it manually, but I want to remove all manual steps from deployment, and the scenario won't always be this trivial of course.

Is there a current method to do this? Is it just using the server SDK, pulilng the DB schema yourself manually, comparing to the desired schema and making the changes with the server SDK? Or is there something more concrete to help handle this already in existance?

TL;DR
Developers are looking for a way to version the DB schema while developing in AppWrite. One suggestion given is to version control the `appwrite.json` file and deploy the schema using the AppWrite CLI. Another suggestion is to use a script-based scheme and utilize the AppWrite CLI commands. It is possible to automate schema changes by comparing schemas and making updates using the server SDK.
Binyamin
3 May, 2024, 21:42

For now, the most common approach is to use a script-based scheme, as you've suggested. Also, it's good to know that Appwrite supports fetching (init collections) and deploying collection data using Appwrite CLI.

To test it, you can just run these commands after you've logged in.

TypeScript
appwrite login

appwrite init project 
appwrite init databases
appwrite init collections

Than, you can deploy them in a different instances / projects

TypeScript
appwrite deploy collections

Check more about it here: https://appwrite.io/docs/tooling/command-line/commands#examples

Pingu
3 May, 2024, 21:52

Hmm, so taking a breif look at the CLI stuff you linked to (thank you!), I could version control the appwrite.json file, and ensure that before PRing from dev to staging that the appwrite.json file has been init'ed correctly with my DB schema, then in my CI/CD, deploy said schema from the appwrite.json file to the staging instance & project?

Pingu
3 May, 2024, 21:53

Ah no, becuase it will overwrite the DB data

Binyamin
3 May, 2024, 21:53

Yes. Exactly

Just one thing, I'm not sure about updating an existing one in your production environment, as I've never tried it so it would be best to just test

Binyamin
3 May, 2024, 21:53

It shouldn't delete existing data

Pingu
3 May, 2024, 21:54

It seems to suggest that here.

Binyamin
3 May, 2024, 21:54

Good to know 👍

Binyamin
3 May, 2024, 21:54

So only for staging and testing

Binyamin
3 May, 2024, 21:54

So a good way would be a mix

Pingu
3 May, 2024, 21:55

I'm early in project, I don't have any prod environment right now so loss of data right this minute is fine, can't make any mistakes that cost me - but I am looking to build something out that won't lose my data of course - but testing stuff and playing about now is all good at least 🙂

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more