migrate() public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/migration.rb, line 405
    def migrate
      current = migrations.detect { |m| m.version == current_version }
      target = migrations.detect { |m| m.version == @target_version }

      if target.nil? && !@target_version.nil? && @target_version > 0
        raise UnknownMigrationVersionError.new(@target_version)
      end
      
      start = up? ? 0 : (migrations.index(current) || 0)
      finish = migrations.index(target) || migrations.size - 1
      runnable = migrations[start..finish]
      
      # skip the last migration if we're headed down, but not ALL the way down
      runnable.pop if down? && !target.nil?
      
      runnable.each do |migration|
        Base.logger.info "Migrating to #{migration} (#{migration.version})"

        # On our way up, we skip migrating the ones we've already migrated
        # On our way down, we skip reverting the ones we've never migrated
        next if up? && migrated.include?(migration.version.to_i)

        if down? && !migrated.include?(migration.version.to_i)
          migration.announce 'never migrated, skipping'; migration.write
        else
          migration.migrate(@direction)
          record_version_state_after_migrating(migration.version)
        end
      end
    end
Register or log in to add new notes.