Home How do I increase column data type size by using reversible migration?
Reply: 0

How do I increase column data type size by using reversible migration?

Adrian Mann
1#
Adrian Mann Published in 2017-11-29 12:26:43Z

How can I increase the length of a column via a migration but ensure that my migration can be rolled backed?

I have read this question and answers but I have concluded that both answers, including the accepted answer do not allow for a reversible migration. Does anyone contest this?

In the link above the following code is not reversible, as far as I can tell, if a record exists with a login column who's length is longer than the original length:

class YourMigration < ActiveRecord::Migration
  def up
    change_column :users, :login, :string, :limit => 55
  end

  def down
    change_column :users, :login, :string, :limit => 40
  end
end

Doing something like the following is acceptable but I am wondering if there is more I can do?:

class YourMigration < ActiveRecord::Migration
  def up
    change_column :users, :login, :string, :limit => 55
  end

  def down
    change_column :users, :login, :string
  end
end
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298769 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO