Database schema changes are hard (2017)
djrobstep.com
Database schema changes are hard (2017)
1–10 of 93 posts
Re: Database schema changes are hard (2017)
#2Re: Database schema changes are hard (2017)
#3How about multiple engineers making schema changes simultaneously?
How is a diff really much different from a migration?
Re: Database schema changes are hard (2017)
#4I generally like Django migrations. A few rough spots. This seems like it could help some of them, but would take s lot of work to wire it in.
Re: Database schema changes are hard (2017)
#5So how would you deal with continuous deployment to test but less frequent deployment to production? In test you might make multiple sequential schema changes before deploying to production. Don't you just end up in the same place as with migrations? How about multiple engineers making schema changes simultaneously? How is a diff really much different from a migration?
- check schema version number, if newer version exists, apply migration files
to:
- check schema on this branch matches production schema exactly, if it doesn't, look for (one or more) pending migration files that would bring production to target state, apply those files
So you can still have multiple migration files as needed. The differences:
- no version numbers
- no long migration chain (you can clean up old pending files once they've hit prod)
- migrations are tested directly, and only get applied if a correct outcome will result
Re: Database schema changes are hard (2017)
#6Neat. I generally like Django migrations. A few rough spots. This seems like it could help some of them, but would take s lot of work to wire it in.
I don't use django, but all that is required is for django to be able to initialize an empty database based on its model definition.
Then you can just use that initialized database independently as a target from which to generate migration scripts.
Re: Database schema changes are hard (2017)
#7So how would you deal with continuous deployment to test but less frequent deployment to production? In test you might make multiple sequential schema changes before deploying to production. Don't you just end up in the same place as with migrations? How about multiple engineers making schema changes simultaneously? How is a diff really much different from a migration?
Author here. Where I've used this in a CI environment, the migration step goes from: - check schema version number, if newer version exists, apply migration files to: - check schema on this branch matches production schema exactly, if it doesn't, look for (one or more) pending migration files that would bring production to target state, apply those files So you can still have multiple migration files as needed. The d…
Re: Database schema changes are hard (2017)
#8Brilliant tool. I totally get it.
Re: Database schema changes are hard (2017)
#9Earlier quoted context omitted.
Author here. Where I've used this in a CI environment, the migration step goes from: - check schema version number, if newer version exists, apply migration files to: - check schema on this branch matches production schema exactly, if it doesn't, look for (one or more) pending migration files that would bring production to target state, apply those files So you can still have multiple migration files as needed. The d…
How would you handle a situation where the underlying data needs to be transformed? For example, converting a text column to an int column?
It's impossible to handle every case, of course, such as when renames happen or data needs to be moved/inserted.
Migration scripts always need reviewing. Tools can get you most of the way there automatically, and help you test, but not all of the way.
Re: Database schema changes are hard (2017)
#10The hardest part of the migration is migrating the data and as far as I can tell that is glossed over.
Why is throwing away the iterative migration version useful exactly?