#4 ✓invalid
Rick DeNatale

Migration generator and schema_info

Reported by Rick DeNatale | December 10th, 2007 @ 10:06 AM | in The Rails 3 Way

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 Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

Shared Ticket Bins

People watching this ticket

Pages