MySQL column positioning option for add/modify column

289 views
Skip to first unread message

krrrr38

unread,
Jan 16, 2016, 11:21:24 PM1/16/16
to elixir-ecto
Dear Ecto developers.

I want to add column position options, `after` and `first`, into Ecto.Migration only for MySQL.

defmodule MyApp.Repo.Migrations.AddColumnsToPosts do
  use Ecto.Migration

  def change do
    alter table(:posts) do
      add :author_id, :integer, first: true # add column in front of all the columns

      add :body, :text, after: :title # add column after `title`
    end
  end
end

I just implemented sample code as follows.


If you need, I will create new pull request into elixir/ecto.

Thanks.

José Valim

unread,
Jan 17, 2016, 4:57:37 AM1/17/16
to elixi...@googlegroups.com
I am a little bit torn as MySQL is the only database that supports it. Also, because it is not a common feature, you can issue an execute command whenever you want to run it.

Finally I believe we shouldn't support those on modify. According to this answer, we can only change one position per alter table: http://stackoverflow.com/questions/3809603/mysql-arrange-existing-table-columns

Thank you for the proposal though. Btw, your patch is *perfect* code wise, great job!



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/59d4b15a-aba9-4e1e-a49e-676a027163b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages