From 41abf7a51b3ccd1cd783141cff980d02ac0c651c Mon Sep 17 00:00:00 2001 From: Andrew Stone Date: Wed, 18 Jun 2008 12:33:09 -0400 Subject: [PATCH] made timestamped migrations optional --- railties/lib/rails_generator/commands.rb | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index 08ecbfb..df38a3f 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -57,6 +57,17 @@ module Rails end 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 migration_directory(relative_path) directory(@migration_directory = relative_path) end @@ -70,7 +81,11 @@ module Rails end def next_migration_string(padding = 3) - Time.now.utc.strftime("%Y%m%d%H%M%S") + if ActiveRecord::Base.timestamped_migrations + Time.now.utc.strftime("%Y%m%d%H%M%S") + else + "%.#{padding}d" % next_migration_number + end end def gsub_file(relative_destination, regexp, *args, &block) -- 1.5.3.4 From aee641b87664713b41d4edfab75018ef574b2930 Mon Sep 17 00:00:00 2001 From: Andrew Stone Date: Wed, 18 Jun 2008 12:56:42 -0400 Subject: [PATCH] added migration option to active_record base --- activerecord/lib/active_record/base.rb | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 8fca34e..54cb752 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -439,6 +439,10 @@ module ActiveRecord #:nodoc: cattr_accessor :schema_format , :instance_writer => false @@schema_format = :ruby + # Specify whether or not to use timestamps for migration numbers + cattr_accessor :timestamped_migrations , :instance_writer => false + @@timestamped_migrations = false + # Determine whether to store the full constant name including namespace when using STI superclass_delegating_accessor :store_full_sti_class self.store_full_sti_class = false -- 1.5.3.4