method

up_only

rails latest stable - Class: ActiveRecord::InvalidMigrationTimestampError::Migration

Method not available on this version

This method is only available on newer versions. The first available version (v7.2.3) is shown here.

up_only(&block)
public

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