public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/josh/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>
Wed Jul 16 18:50:29 -0700 2008
lifo (committer)
Wed Jul 16 18:54:45 -0700 2008
commit  bbab6391366f59189e84d2b8de2a63bea91a9851
tree    b7fa5e6df063451e017ee78c4a10d0c128c135e4
parent  d8a72b32c5b0c32abf257f05b89bad7d21f178ec
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *Edge*
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
 * change_column_default preserves the not-null constraint. #617 [Tarmo Tänav]
0
 
0
 * Fixed that create database statements would always include "DEFAULT NULL" (Nick Sieger) [#334]
...
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

    No one has commented yet.