I’m coming from a background where the DB schema is defined as completely as possible, e.g. field lengths, not null, default values, complex referential integrity, etc. With Rails, I have to do all of that in the model to get smart validations. So do I duplicate everything in the database definition as well?
For example, if email is a required field, do I add validates :email, :presence => true to the model AND :null => false to the migration?
What about strings? If I have :length => { :maximum => 50 } in the model, do I also want :limit => 50 in the migration?
Do I add foreign keys to the database to enforce referential integrity?
Or is the “Rails way” to do as much as possible in the model and leave the database as a “dumb” persistence engine?
Definately add :null => false. otherwise your DBA might hurt you. Your Rails app isn’t the only thing that touches the DB.
max length gives you a gain DB memory. definitely set the max length but be sure to add the rails validations. If not you might get wierd app errors.
foreign keys are good but less used in rails apps