In a Rails Migration (MySQL), can you specify what position a new column should be?
This is now possible in Rails 2.3.6+ by passing the :after parameter
https://rails.lighthouseapp.com/projects/8994/tickets/3286-patch-add-support-for-mysql-column-positioning-to-migrations
To everyone that doesn't see the advantage in having this feature: do you never look at your database outside of the ORM? If I'm viewing in any sort of UI, I like having things like foreign keys, status columns, flags, etc, all grouped together. This doesn't impact the application, but definitely speeds up my ability to review data.
Sure you can.
-
Short answer:
add_column :users, :gender, :string, :after => :column_name
Long answer:
Here is an example, let's say you want to add a column called "gender" after column "username" to "users" table.
- Type
rails g migration AddGenderToUser gender:string
-
Add "after => :username" in migration that was created so it looks like this:
class AddSlugToDictionary < ActiveRecord::Migration def change add_column :users, :gender, :string, :after => :username end end