2008-03-12

Forcing Row Version Migrations to add the fields

A quick note... The Red Hill on Rails plug-ins are invaluable if you're using a non-dinky-toy database with Ruby on Rails. One of the plug-ins that I use is the Row Version Migrations one. It adds these fields to all tables by default:
 :created_at,   :datetime,  :null
:updated_at, :datetime, :null
:lock_version, :integer, :null
However, one thing had changed somewhere on the way. I had a many-to-many table declaration like such;
create_table(:manufacturers_suppliers, :id => false) do |t|
t.column :manufacturer_id, :integer, :null => false
t.column :supplier_id, :integer, :null => false
end

What I didn't know was a) if you don't have an id (:id => false), the plug-in doesn't create the fields, but b) just as you can disable the fields with :row_version => false, you can also "force" enable them with :row_version => true. Hence, changing to:
create_table(:manufacturers_suppliers, :id => false, :row_version => true) do |t|
t.column :manufacturer_id, :integer, :null => false
t.column :supplier_id, :integer, :null => false
end

Made the fields appear and it solved my problem. Sweet!

No comments: