public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
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>
NZKoz (author)
Wed Jul 30 09:33:43 -0700 2008
commit  af3f2aad7ecb31a6e1d09f06775cb33b4ad64d91
tree    9639dacc4d9874a12ed425a0f459f40903cc57f8
parent  af92dc53a830a4639d38df79048f1a30a89dd38a
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.1.1 (next release)*
0
 
0
+* Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp. #446. [Andrew Stone, Nik Wakelin]
0
+
0
 * Fixed that create database statements would always include "DEFAULT NULL" (Nick Sieger) [#334]
0
 
0
 * change_column_default preserves the not-null constraint.  #617 [Tarmo Tänav]
...
439
440
441
 
 
 
 
442
443
444
...
439
440
441
442
443
444
445
446
447
448
0
@@ -439,6 +439,10 @@ module ActiveRecord #:nodoc:
0
     cattr_accessor :schema_format , :instance_writer => false
0
     @@schema_format = :ruby
0
 
0
+    # Specify whether or not to use timestamps for migration numbers
0
+    cattr_accessor :timestamped_migrations , :instance_writer => false
0
+    @@timestamped_migrations = true
0
+
0
     # Determine whether to store the full constant name including namespace when using STI
0
     superclass_delegating_accessor :store_full_sti_class
0
     self.store_full_sti_class = false
...
238
239
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
242
243
...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
0
@@ -238,6 +238,22 @@ module ActiveRecord
0
   # lower than the current schema version: when migrating up, those
0
   # never-applied "interleaved" migrations will be automatically applied, and
0
   # when migrating down, never-applied "interleaved" migrations will be skipped.
0
+  # 
0
+  # == Timestamped Migrations
0
+  #
0
+  # By default, Rails generates migrations that look like:
0
+  #
0
+  #    20080717013526_your_migration_name.rb
0
+  #
0
+  # The prefix is a generation timestamp (in UTC).
0
+  #
0
+  # If you'd prefer to use numeric prefixes, you can turn timestamped migrations
0
+  # off by setting:
0
+  #
0
+  #    config.active_record.timestamped_migrations = false
0
+  # 
0
+  # In environment.rb.
0
+  #
0
   class Migration
0
     @@verbose = true
0
     cattr_accessor :verbose
...
57
58
59
 
 
 
 
 
 
 
 
 
 
 
60
61
62
...
70
71
72
73
 
 
 
 
 
74
75
76
...
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
...
81
82
83
 
84
85
86
87
88
89
90
91
0
@@ -57,6 +57,17 @@ module Rails
0
         end
0
 
0
         protected
0
+          def current_migration_number
0
+            Dir.glob("#{RAILS_ROOT}/#{@migration_directory}/[0-9]*_*.rb").inject(0) do |max, file_path|
0
+              n = File.basename(file_path).split('_', 2).first.to_i
0
+              if n > max then n else max end
0
+            end
0
+          end
0
+             
0
+          def next_migration_number
0
+            current_migration_number + 1
0
+          end
0
+               
0
           def migration_directory(relative_path)
0
             directory(@migration_directory = relative_path)
0
           end
0
@@ -70,7 +81,11 @@ module Rails
0
           end
0
 
0
           def next_migration_string(padding = 3)
0
-            Time.now.utc.strftime("%Y%m%d%H%M%S")
0
+            if ActiveRecord::Base.timestamped_migrations
0
+              Time.now.utc.strftime("%Y%m%d%H%M%S")
0
+            else
0
+              "%.#{padding}d" % next_migration_number
0
+            end
0
           end
0
 
0
           def gsub_file(relative_destination, regexp, *args, &block)

Comments