Skip to content

Instantly share code, notes, and snippets.

@n0ts
Created February 15, 2011 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0ts/827812 to your computer and use it in GitHub Desktop.
Save n0ts/827812 to your computer and use it in GitHub Desktop.
require 'date'
require 'fileutils'
require 'rubygems'
gem 'activesupport', '=2.3.11'
require 'active_support'
file_count = 0
Dir::foreach('db/migrate') do |v|
next if v == "." or v == ".." or v == ".svn"
version, name = v.split('_', 2)
begin
file_count += 1 if version.to_i > 0
rescue
end
end
offset = file_count
Dir::foreach('db/migrate') do |v|
next if v == "." or v == ".." or v == ".svn"
version, name = v.split('_', 2)
next if version.size != 3
begin
start_date = DateTime.now.ago(60 * 60 * 24 * offset)
#p start_date
# ex. '20080906120000'
version_date = start_date.new_offset(0).strftime("%Y%m%d%H%m%S")
filename = "#{version_date}_#{name}"
p "#{v} -> #{filename}"
File.rename("db/migrate/#{v}", "db/migrate/#{filename}")
offset -= 1
break if offset == 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment