Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] Add support for Mysql column positioning to migrations

#3286

This patch allows some extra options to be passed for #add_column and #change_column

From the mysql docs for alter table (http://dev.mysql.com/doc/refman/5.1/en/alter-table.html):
"To add a column at a specific position within a table row, use FIRST or AFTER col_name."

Here are the new options:
:first => true # Put the column in front of all the columns :after => column_name # Put the colmn after 'column_name'

Here is an example:

# Inside of a migration ...
add_column :new_col, :string, :first => true
add_column :another_col, :integer, :default => 0, :after => :new_col

Patch contains tests and applies cleanly to 2-3-stable and master. This is my first patch so any pointers would be appreciated, thanks!

Reported by Ben Marini · September 28th, 2009 @ 12:48 AM

State: committed
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Ben Marini
    Ben Marini
    • Tag changed from active_record, add_column, master, migrations, mysql, patch to 2-3-stable, active_record, add_column, master, migrations, mysql, patch

    September 28th, 2009 @ 03:09 AM

  2. Peter Wagenet
    Peter Wagenet
    • Tag changed from 2-3-stable, active_record, add_column, master, migrations, mysql, patch to 2-3-stable, active_record, add_column, master, migrations, mysql, patch, tested

    This looks good to me. Check out #rails-contrib on IRC to see if you can get some more people to review this and maybe get it into Core.

    October 4th, 2009 @ 10:21 PM

  3. luniki
    luniki

    What's the state of this ticket?

    December 3rd, 2009 @ 12:27 PM

  4. Ben Marini
    Ben Marini

    Patch should apply cleanly still. Please test it out and give it a +1 if you like it, or feedback if you don't. I'm still motivated to get this patch accepted.

    December 4th, 2009 @ 05:28 AM

  5. Jeremy Kemper
    Jeremy Kemper

    Hey Ben - curious why you added this. Aesthetics only?

    December 4th, 2009 @ 07:12 AM

  6. Repository
    Repository
    • State changed from new to committed

    (from [e55284e8256461fc2440c41548ee9b4216f96b47]) Add support for Mysql column positioning via #add_column and #change_column

    add_column and change_column in the Mysql adapter now accept some
    additional options:
    :first => true # Put the column in front of all the columns :after => column_name # Put the colmn after 'column_name'

    add_column :new_col, :string, :first => true
    add_column :another_col, :integer, :default => 0, :after => :new_col

    [#3286 [PATCH] Add support for Mysql column positioning to migrations state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
    http://github.com/rails/rails/commit/e55284e8256461fc2440c41548ee9b...

    December 4th, 2009 @ 07:12 AM

  7. Repository
    Repository

    (from [ccb197b2e6c2e773f908d3b00f5debe57c22311a]) Add support for Mysql column positioning via #add_column and #change_column

    add_column and change_column in the Mysql adapter now accept some
    additional options:
    :first => true # Put the column in front of all the columns :after => column_name # Put the colmn after 'column_name'

    add_column :new_col, :string, :first => true
    add_column :another_col, :integer, :default => 0, :after => :new_col

    [#3286 [PATCH] Add support for Mysql column positioning to migrations state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
    http://github.com/rails/rails/commit/ccb197b2e6c2e773f908d3b00f5deb...

    December 4th, 2009 @ 07:12 AM

  8. Ben Marini
    Ben Marini

    Thanks for approving the patch Jeremy!

    I find it valuable to have my columns organized, just like any other parts of my code. It's nice when I'm scanning the columns of a table in my schema.rb file for reference, to see them in some sensible order. I've always been annoyed that my updated_at and created_at columns are no longer last on the list after adding more columns to a table with a migration. If I add a new foreign key, I'd like it to be clustered with any other foreign keys for that table. It also makes accessing the database via other applications like Mysql Query Browser a little nicer, since I can just use "select * from ..." and the columns are ordered in some sensible way.

    There also are some apparent performance benefits to gain by optimizing your column ordering in MySQL, although this was not a motivator for me.
    http://stackoverflow.com/questions/894522/is-there-any-reason-to-wo...

    December 4th, 2009 @ 10:32 PM