Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORM: Handwritten schema or auto-generated?

Tags:

orm

schema

rdbms

Should I use a hand-written schema for my projected developed in a high-level language (such as Python, Ruby) or should I let my ORM solution auto-generate it? Eventually I will need to migrate without destroying all the data. It's okay to be tied to a specific RDBMS but it would be nice if features such as constraints and procedures could be supported somehow.

like image 471
Johan Dahlin Avatar asked Sep 24 '08 13:09

Johan Dahlin


3 Answers

I never go with ORM-generated schema.

I find that the ways in which the ORM wants to generate the schema are often at total odds with how I want my database to be structured. Also, and I know this is trivial, the nomenclature scheme is usually poor.

Database structure has its own constraints, that I find that usually the ORM autogeneration tools don't consider fully. And if you're going to be wanting to run reports on your database later (and you will), then having good database structure and design is very important.

like image 151
Paul Sonier Avatar answered Nov 12 '22 00:11

Paul Sonier


See this Coding Horror article and links for discussion on that migration you'll eventually need to do. Plan for it now.

Also see Martin Fowler on database evolution; I particularly recommend the notion that test data generation is part of database set-up. The idea may be a little underdeveloped, in that there is not a clear delineation of the different problems in different environments, development versus QA versus production.

like image 30
Roger Durham Avatar answered Nov 12 '22 02:11

Roger Durham


Let the ORM generate the schema it wants. Then you can always change things that are too slow or that you want differently. But it allows you to quickly get started and have something working plus the ORM people usually know what they do when it comes to generating schemas.

like image 24
tante Avatar answered Nov 12 '22 02:11

tante