instance method
up_only
Ruby on Rails 5.2.8.1
Since v5.2.8.1Signature
up_only()
Used to specify an operation that is only run when migrating up (for example, populating a new column with its initial values).
In the following example, the new column published will be given the value true for all existing records.
class AddPublishedToPosts < ActiveRecord::Migration[5.2] def change add_column :posts, :published, :boolean, default: false up_only do execute "update posts set published = 'true'" end end end
Source
# File activerecord/lib/active_record/migration.rb, line 752
def up_only
execute_block { yield } unless reverting?
end
Defined in activerecord/lib/active_record/migration.rb line 752
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Migration