10 ms·
Regarding the article's point about managing your schema, there are only two real options IMHO: 1) "The database schema is the official definition." Programma
by keredson 9y ago
Regarding the article's point about managing your schema, there are only two real options IMHO:
1) "The database schema is the official definition."
Programmatically generate what ever ORM objects (at build time) in a 1-to-1 fashion from a schema dump. This is the approach DKOs use: https://github.com/keredson/DKO https://github.com/keredson/DKO As long as the code generation step is done as part of the build process, you'll have none of the normal code generation headaches, and your build will fail if you've made a code incompatible schema change.
2) "Your ORM objects are are the official definition."
And generate the schema definition automatically. The common process of this is that most "generate schema" functions are stupidly lazy, and drop the work of calculating the diff from an existing schema on the developer (forcing them to write migrations). This is unacceptable in my eyes, just as it would be if my version control software wanted me to write my own diffs by hand in order to make a commit. I strongly prefer automatically generated diffs, like in https://github.com/keredson/peewee-db-evolve https://github.com/keredson/peewee-db-evolve. So you can do non-destructive schema changes. It's a model I've re-implemented for any new ORM I wind up using.
- cwbrandsma 9y agoThere is a 3rd. You define your own data structure (in JSON as an example), and generate everything else off of that. I've done this a couple times (as well as the two items you listed), and this has worked the best for me.