diff options
author | Nik Wakelin <nik@codetocustomer.com> | 2008-07-17 02:50:29 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-07-17 02:54:45 +0100 |
commit | bbab6391366f59189e84d2b8de2a63bea91a9851 (patch) | |
tree | b7fa5e6df063451e017ee78c4a10d0c128c135e4 | |
parent | d8a72b32c5b0c32abf257f05b89bad7d21f178ec (diff) | |
download | rails-bbab6391366f59189e84d2b8de2a63bea91a9851.tar.gz rails-bbab6391366f59189e84d2b8de2a63bea91a9851.tar.bz2 rails-bbab6391366f59189e84d2b8de2a63bea91a9851.zip |
Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp. [#446 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 16 | ||||
-rw-r--r-- | railties/lib/rails_generator/commands.rb | 17 |
4 files changed, 38 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 95fdd93f65..90be9b700a 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *Edge* +* Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp. #446. [Andrew Stone, Nik Wakelin] + * change_column_default preserves the not-null constraint. #617 [Tarmo Tänav] * Fixed that create database statements would always include "DEFAULT NULL" (Nick Sieger) [#334] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index a75e1a5b24..4f5d72a0be 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 = true + # 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 diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index e095b3c766..731a350854 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -238,6 +238,22 @@ module ActiveRecord # lower than the current schema version: when migrating up, those # never-applied "interleaved" migrations will be automatically applied, and # when migrating down, never-applied "interleaved" migrations will be skipped. + # + # == Timestamped Migrations + # + # By default, Rails generates migrations that look like: + # + # 20080717013526_your_migration_name.rb + # + # The prefix is a generation timestamp (in UTC). + # + # If you'd prefer to use numeric prefixes, you can turn timestamped migrations + # off by setting: + # + # config.active_record.timestamped_migrations = false + # + # In environment.rb. + # class Migration @@verbose = true cattr_accessor :verbose diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index d258aeaa0a..59af7308fe 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) |