4 ms·
Generate a script from the diff of _what_ exactly, the old and new schemas? How did you get to the "new" schema without some sort of migration? SQLAlchemy does
by bradstewart 7y ago
Generate a script from the diff of _what_ exactly, the old and new schemas? How did you get to the "new" schema without some sort of migration?
SQLAlchemy does something like what I think you're describing (and is tightly coupled with the application-level ORM): you update attributes on the model classes, and then it generates a migration for you. But I've always had to manually edit those migrations by hand.
The Rails "migration first, model later" method feels much cleaner to me, but maybe that's just because I learned it that way.
Migrations are one of the most dangerous things I run on prod, so I'm always interested in better/safer ways of doing them.
- djrobstep 7y agoYeah you compare your intended state for prod to what you currently have on prod, and generate the differences. It's still a "migration", the difference is it's generated from a direct comparison to production rather than a crude reconstruction of the database's history. Checking production directly is much more robust (more testable, changes made outside the context of the migration tooling are no problem) and simpler because it you don't need to maintain a historical migration chain - there's only ever one migration script to consider. And using a diff tool directly on the database means you can support database features that aren't directly supported by your ORM.