Today I Learned

hashrocket A Hashrocket project

Using `up_only` in ActiveRecord migrations

The change method on migrations is great so you don't have to specify up and down and if you just want to execute a simple sql update on up then you can use the up_only method:

  def change
    add_column :products, :draft, :boolean, default: true
    
    up_only do
      execute "update products set draft = false"
    end
  end
See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.