What is a database migration?

Good question. I know what I use it for (pulling the db schema out of the anvil.yaml file to run database backups through uplink), and I know that the open source server uses it to generate the database when you first run the app, but I don’t know what it was originally for.

You don’t, unless you need the app itself to be up-to-date for another reason (or if you want to get rid of the message about it being out of sync).

Let’s say you have two branches, one for dev and one for production. You have an environment setup for each, and each runs its own copy of the database.

You make changes to your development database, and eventually want to migrate those changes to your production database.

  1. Make sure your app is up-to-date with your development database (e.g. you aren’t being notified that the app is out of sync)
  2. Migrate your code changes (which will include the app’s view of the database) to production
  3. Mark your production database as the one used for development
  4. When prompted to resolve the database migration, choose the button that says the app is correct. The changes you made in the development database will be made in the production database (columns added/removed, tables added/removed)
  5. Mark your development database as the one used for development

I’m sure there are other workflows, but that’s the one I’ve come to use. It beats having to keep track of the database changes made in dev and manually replicating those in production.