Best place to initialize a database column value

I have a database column named 'status' in my 'orders' table. When an order placed, I'd like to initialize this column value to be 'in progress'. Is it best to do this in:

A) the database migration B) the database itself C) in before_create

My personal preference is to do it in the before_create. This way it is very evident to me when I look at the model as to what the value is going to be initialized to. Are there performance issues with doing this?

Jody Baty Lead Developer my Curriculum Analysis Tools (www.mycatshq.com)

Hi Jody,

i am using Oracle for back-end storage, so all my default values for columns are in sql scripts, which is separate folder, and i don't think introduction of default value in any of the 3 places you mentioned will lead to performance problem.

(Worst case: if it affects also it should be very very negligible, but i don't have benchmark results, personally i feel, it will not)

I'm using DEFAULT attribute (set to 'pending') on a column inside mysql.

To give you yet another option, there's a dead simple little plugin called default_values here:

  Rubaidh.com is for sale | HugeDomains

You then just declare default values in your model:

   class Order < ActiveRecord::Base      default_values :status => 'in progress'    end

Thanks, I'm certainly going to give this plugin a try. It's exactly what I'm looking for: expressive and easy to implement.

Jody