What is a database migration?

image

The three dots next to the database allows you to select which database will be used for development (e.g. when running the app in the IDE). My production branch uses the Default Database, and I have a second copy of the database for development so I can make breaking changes without affecting production. (And a third copy for the testing environment)

As part of my migration flow, I temporarily make the production database the one used for development, so Anvil will then resolve the database changes for me.

The flow I listed will work for anything where data migration isn’t an issue, e.g. adding new columns, deleting columns, adding new tables, etc.

No, the environment says which database will be used.

When existing data has to be migrated to a new format, I do the database migration from dev to prod, and then run some code in prod to migrate the data (that code’s been tested in dev, first, of course).

If there are then some database elements that need removed, I’d do that in dev, make sure everything still worked with them gone, and then migrate those changes to the production database.

Having two separate databases allows me to fill the dev database with junk data as needed for testing new features, without affecting anything the real users would see. There are certainly other ways of partitioning the data in a single database to get the same effect, but it makes me jumpy to develop on the production database.

1 Like