title: Rails Migration, how to add multiple columns to a table in batch mode
body: <p>When I want to add multiple columns to an existing table I can do this:</p>
  
  <pre><code>rails g migration AddColumnsToUser col1:integer col2:integer .. etc.
  </code></pre>
  
  <p>This will generate a migration with several lines:</p>
  
  <pre><code>def change
    add_column :users, :col1, :integer
    add_column :users, :col2, :integer
  end
  </code></pre>
  
  <p>Which will be translated in several <code>alter table</code> commands to the backend DB:</p>
  
  <pre><code>ALTER TABLE users ADD COLUMN col1 SMALLINT(6) NOT NULL;
  ALTER TABLE users ADD COLUMN col2 SMALLINT(6) NOT NULL;
  </code></pre>
  
  <p>The problem is that if you are dealing with a big table, each of these <code>alter table</code> will take a lot of time, at less in MySQL, because the backend engine will generate a duplication of the table and will do a lot of expensive processes. And all this work has to be done for each column I want to add.</p>
  
  <p>So, my question, is how can I aggregate all these <code>add_column</code> sentences in only one so the result will be an <code>alter table</code> in batch mode, like this:</p>
  
  <pre><code>ALTER TABLE users
      ADD COLUMN col1 SMALLINT(6) NOT NULL,
      ADD COLUMN col2 SMALLINT(6) NOT NULL;
  </code></pre>