#4 open
Rick DeNatale

Migration generator and schema_info

Reported by Rick DeNatale | December 10th, 2007 @ 05:06 AM | in Second Edition

On page 144, the book states: "The migration generator handles checking to see what the next sequence number should be, based on the value of a special table in the database that Rails maintains. It is named schema_info..."

Actually this is not true. The migration generator picks the next sequence number based solely on the file names currently existing in #{RAILS_ROOT}/db/migrations

Here's the relevant code (from vendor/rails/railties/lib/rails_generator/command.rb

def current_migration_number

Dir.glob("#{RAILS_ROOT}/#{@migration_directory}/[0-9]*_*.rb").inject(0) do |max, file_path|

n = File.basename(file_path).split('_', 2).first.to_i

if n > max then n else max end

end

end

def next_migration_number

current_migration_number + 1

end

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket