Skip to content

Instantly share code, notes, and snippets.

Created July 27, 2011 21:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1110373 to your computer and use it in GitHub Desktop.
Save anonymous/1110373 to your computer and use it in GitHub Desktop.
Generating the next migration number
# This is based on the implementation in ActiveRecord (I believe). I've added the %3N (and further padded the string format) to include milliseconds since multiple migrations will often be run in an engine's installer.
def self.next_migration_number( dirname )
next_migration_number = current_migration_number(dirname) + 1
if ActiveRecord::Base.timestamped_migrations
[Time.now.utc.strftime("%Y%m%d%H%M%S%6N"), "%.20d" % next_migration_number].max
else
"%.3d" % next_migration_number
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment