instance method up_only

Ruby on Rails 8.0.4

Since v5.2.8.1

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

up_only(&block)

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[8.0]
  def change
    add_column :posts, :published, :boolean, default: false
    up_only do
      execute "update posts set published = 'true'"
    end
  end
end

Parameters

block block
Source
# File activerecord/lib/active_record/migration.rb, line 927
    def up_only(&block)
      execute_block(&block) unless reverting?
    end

Defined in activerecord/lib/active_record/migration.rb line 927 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Migration

Type at least 2 characters to search.

↑↓ navigate · open · esc close