views:

38

answers:

1

I've always had a difficult time deciding where the best place is to manage my "master" set of data structures for my data access layer. Traditionally, I've always started with a database and used a code generation tool to get a set of code models (i.e. ActiveRecord in SubSonic). Lately, however, I've been attracted by the idea of managing my models in code and letting the database schema changes propagate out (i.e. SimpleRepository in SubSonic).

So I'm wondering, what do you traditionally find better - database to code mirror, or code to database mirror? Under what circumstances do you find one better than the other(s)? What implications are there for deployment? Are there any other approaches?

+1  A: 

There shouldn't be a difference in the end result, and it always feels easier to me to write code models instead of writing SQL by hand.

Dean J
+1: Code has richer, more sophisticated modeling techniques. The database should be persistent storage.
S.Lott
Are there certain aspects of database design that cannot be easily reflected in code?
Anton
What about production systems - is it OK for code to modify schemas on-the-fly?
Anton
If you're moving code to production, it should already be tested elsewhere, and deployed using a relatively defined process; if it's already been tested to work, it should work.
Dean J
If your database is too complex to represent in code, your database is somewhat unusual, for whatever it's worth. If you need to tweak the database design for speed, so be it, but at that point, set aside the automatic schema generation tools.
Dean J