# Migration Broken?

**URL:** <https://www.ruby-forum.com/t/migration-broken/158749>\
**Category:** Rails\
**Created:** [January 27, 2009, 5:11pm UTC](https://www.ruby-forum.com/t/migration-broken/158749 "2009-01-27T17:11:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [January 27, 2009, 5:11pm UTC](https://www.ruby-forum.com/t/migration-broken/158749/1 "2009-01-27T17:11:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [January 27, 2009, 5:36pm UTC](https://www.ruby-forum.com/t/migration-broken/158749/2 "2009-01-27T17:36:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [January 27, 2009, 5:51pm UTC](https://www.ruby-forum.com/t/migration-broken/158749/3 "2009-01-27T17:51:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [January 27, 2009, 6:20pm UTC](https://www.ruby-forum.com/t/migration-broken/158749/4 "2009-01-27T18:20:48Z")

</div>

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Ã³:
