Generating Ruby on Rails UTC-based migrations with TextMate
TextMate is a great tool for all Mac-based Ruby on Rails developers, but even if you’re using the Cutting-Edge updates you’re most likely still stuck with the old migrations generator.
Here’s a quick fix if you want to use UTC-based migrations (introduced in Rails 2.1). From your favourite Terminal application launch:
mate /Applications/TextMate.app/Contents/SharedSupport/Bundles/Ruby\ on\ Rails.tmbundle/Support/bin/generate_quick_migration.rb
Then just comment (or delete) the following code:
files = Dir.glob(File.join(migration_dir, "[0-9][0-9][0-9]_*"))
if files.empty?
number = "001"
else
number = File.basename(files[-1])[0..2].succ
end
And replace it with:
number = Time.now.utc.strftime("%Y%m%d%H%M%S")
There’s just one glitch with this solution - it’ll probably be overwritten whenever you update your Textmate application. However, this doesn’t happen very often, does it? If you have a better solution - let me know in the comments, I’m a TextMate beginner, so bear with me!