Migration Broken?


#1

I’ve created a migration to create a new table. I’m noting that the
format of the migration name created by the generator has changed. Up
until now, the migration names were of the form “00n_” … now the
form is _.

The problem that I’m having is that rake db:migrate is trying to rerun
all my migrations from “001” forward. the schema tables in the database
show the schema to be at 19. I would have expected the new migration to
be 020_, but the name format has changed as shown above.

Obviously, something has changed in this area. I’ve tried googling, but
I haven’t found the right search terms. How do I get migrations to run
again. I’d be happy to reset everything to the current state of the
database, then move forward with the new migration. I’d be happy just to
get it working again.

Can anyone offer any help


#2

On 27 Jan 2009, at 16:11, Michael S. wrote:

I’ve created a migration to create a new table. I’m noting that the
format of the migration name created by the generator has changed. Up
until now, the migration names were of the form “00n_” … now
the
form is _.
It’s a UTC timestamp

The problem that I’m having is that rake db:migrate is trying to rerun
all my migrations from “001” forward. the schema tables in the
database
show the schema to be at 19. I would have expected the new migration
to
be 020_, but the name format has changed as shown above.

Do you also have a schema migrations table ? if so I’d try dropping
it. This is the replacement for the schema_info table, and should be
automatically created so that migrations are assumed to have run up to
the right point but might have got screwed up.

Fred


#3

Frederick C. wrote:

Do you also have a schema migrations table ? if so I’d try dropping
it. This is the replacement for the schema_info table, and should be
automatically created so that migrations are assumed to have run up to
the right point but might have got screwed up.

Thanks much. That solved the problem.


#4

You could use this script to rename all your migrations with the new
format.
I’ve used this chunk of code in a project (undeployed yet) to normalize
the migrations names (01_, 02_ … format and UTC format)
Maybe could be useful for you.

#!/usr/bin/env ruby

require ‘find’
require ‘fileutils’
require ‘optparse’

Create option parser.

options = {}
ARGV.options do |opts|
opts.banner << " "
opts.on("-v", “–[no-]verbose”, “run verbosely”) do |v|
options[:verbose] = v
end

opts.on("-l", “–[no-]local”, “make local changes”) do |v|
options[:local] = v
end

opts.on("-s", “–[no-]subversion”, “remane files on subversion”) do
|v|
options[:subversion] = v
end

opts.on("-g", “–[no-]git”, “remane files on git”) do |v|
options[:git] = v
end

end.parse!

path = ARGV[0] or (STDERR.puts ARGV.options; exit 2)

printf “\033[1m\033[33mRename Ruby On Rails Migrations UTC (1 sec)
\033[0m\n”
printf “\033[1m\033[33mbinoid 09/2008- we make webapps\033[0m\n”
sleep(2)

Dir.entries(path).sort.each do |old_name|
if !File.directory?("#{path}/#{old_name}")
new_name = old_name.gsub(/\d+/, Time.now.strftime("%Y%m%d%H%M%S"))

puts ">> rename #{path + old_name} to #{path + new_name}\n" if

options[:verbose]
File.rename(path + old_name, path + new_name) if options[:local]
system( “svn mv #{path + old_name} #{path + new_name}” ) if
options[:subversion]
system( “git-rename #{path + old_name} #{path + new_name}” ) if
options[:git]
sleep(1)
end
end

(Sorry, I don’t remember from where I copied this code)

Michael S. escribió: