Skip to content

Instantly share code, notes, and snippets.

@duncanbeevers
Created June 15, 2011 17:29
Show Gist options
  • Save duncanbeevers/1027606 to your computer and use it in GitHub Desktop.
Save duncanbeevers/1027606 to your computer and use it in GitHub Desktop.
Rename Rails 1 style migration names to timestamp filenames
require 'fileutils'
Dir['./db/migrate/*.rb'].each do |from|
to = File.join(File.dirname(from),
"%014d%s" % File.basename(from).match(/^(\d+)(_.*)$/)[1..-1].map.with_index do |f, i|
0 == i ? f.to_i : f
end)
FileUtils.mv(from, to) if from != to
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment