Forum: Ruby on Rails Migration Broken??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9e6d05909dc733af570faadce1392e67?d=identicon&s=25 Michael Satterwhite (msatterwhite)
on 2009-01-27 17:11
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_<text>" ... now the
form is <yymmdd><some digits>_<text>.

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_<text>, 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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-27 17:36
(Received via mailing list)
On 27 Jan 2009, at 16:11, Michael Satterwhite 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_<text>" ... now
> the
> form is <yymmdd><some digits>_<text>.
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_<text>, 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
9e6d05909dc733af570faadce1392e67?d=identicon&s=25 Michael Satterwhite (msatterwhite)
on 2009-01-27 17:51
Frederick Cheung 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.
8c639c73cd3f657683b05bc2da9fc7ea?d=identicon&s=25 Juan José Vidal (Guest)
on 2009-01-27 18:20
(Received via mailing list)
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 << " <path>"
  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 Satterwhite escribió:
This topic is locked and can not be replied to.