• Home
  • About

stonean

Feeds:
Posts
Comments

Timestamped Migrations

June 17, 2008 by stonean

<update>
As soon as I figure out how, I will be submitting a patch to Rails to make this an option. I would like to use something like:

config.active_record.timestamped_migrations = true

This was suggested in a comment by hardbap referencing the announcement of this post. I agree with idea, but think the default should be false and users can set to true (as in my example) if they want this change. We’ll see how that goes… :)

Even though I botched the process, I have submitted a ticket.
</update>

Alright, so I really don’t like this feature, the anti-collision benefit is outweighed by the annoyance factor.

So, here’s where open source code rocks and why Ruby is my language of choice.

require "rails_generator"

class Rails::Generator::Commands::Base
  protected
  def current_migration_number
    Dir.glob("#{RAILS_ROOT}/#{@migration_directory}/[0-9]*_*.rb").inject(0) do |max, file_path|
      n = File.basename(file_path).split('_', 2).first.to_i
      if n > max then n else max end
    end
  end

  def next_migration_number
    current_migration_number + 1
  end

  def next_migration_string(padding = 3)
    "%.#{padding}d" % next_migration_number
  end
end

I just created a file called classic_migrations.rb in config/initializers and added the above code. I haven’t run it through all the various scenarios yet, but for a simple migration setup, it works fine.

It should work for everything else, after all, there is nothing inherently different between the timestamped version number and the “old” version number. They are both just numbers representing a sequence.

For the collision issue, here’s a simple idea.

Posted in RubyOnRails | No Comments Yet

  • Open Source


    Lockdown (GitHub)
    RuHL (GitHub)

  • Recommend Me

  • twitter: stonean

    • So I submitted my RailsConf proposal, called it Beyond MVC. We shall see. I do such a bad job talking about myself, the bio sucked. 7 hours ago
    • @ubermuda that's good to know, thank you! 1 day ago
    • @chanmix51 cool, thanks! 1 day ago
    • In vi, :set list to show hidden characters, to revert, :set nolist Very handy. 1 day ago
    • Team just did their first PechaKucha [ http://vurl.me/EEP ] session. I love this format and am very impressed with results! 2 days ago
  • Categories

    classy-inheritance Code Style DataMapper Fusion git Haml Interview Questions jQuery lockdown Merb MysqlUtils Process Quick Tips REST RSpec Ruby RubyOnRails rubytrends Stage thoughts Uncategorized


  • Archives

    • November 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007

Blog at WordPress.com.

Theme: Mistylook by Sadish.