The current "sexy" syntax for creating and changing tables in
migrations look very different from the way indexes are added and
removed:
class CreateArticles < ActiveRecord::Migration
def self.up
create_table :articles do |t|
t.string :title, :null => false
t.text :body
t.date :published_at
t.references :author, :null => false
end
add_index :articles, :published_at # not very DRY
end
end
A more concise syntax can be achieved:
class CreateArticles < ActiveRecord::Migration
def self.up
create_table :articles do |t|
t.string :title, :null => false
t.text :body
t.date :published_at
t.references :author, :null => false
t.index :published_at # <-- pretty dry!
end
end
end
A complementary option would be t.date :published_at,
:index => true. This, however, ties the definition of the
column with the addition of the index, which wouldn't be nice in
change_table.