Hacker News new | ask | show | jobs
by drwiggly 2093 days ago
Most databases have introspection capability, via sql. These tools should be using that. We shouldn't be making delta files, just check in schema defs along with normal code. The "migration" will consume the schema defs and generate a script that checks it against the db, and only execute schema commands that are needed. Most dbs can support drop/create of procs/triggers/other things quickly, some have alter support to just re-set them. Just never drop columns or tables, those require a human anyway, unless they're tiny. I wrote a tool that did this for mysql, and can be adapted for others as needed. Every branch could generate a database boot script easily, no crazy up down things all over the place and guessing on order.
1 comments

"Just never drop columns or tables, those require a human anyway, unless they're tiny."

In a lot of common multi-tenant designs you could have thousands of schemas. You can't have a human doing this. Additionally, the hard part of schema versioning is really the data migration and rollback steps which you failed to mention.