Navigation Menu

Skip to content

Commit

Permalink
Set config.active_record.timestamped_migrations = false to have migra…
Browse files Browse the repository at this point in the history
…tions with numeric prefix instead of UTC timestamp. [#446 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
nikz authored and lifo committed Jul 17, 2008
1 parent d8a72b3 commit bbab639
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions 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]
Expand Down
4 changes: 4 additions & 0 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -439,6 +439,10 @@ def self.reset_subclasses #: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
Expand Down
16 changes: 16 additions & 0 deletions activerecord/lib/active_record/migration.rb
Expand Up @@ -238,6 +238,22 @@ def initialize(name)
# 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
Expand Down
17 changes: 16 additions & 1 deletion railties/lib/rails_generator/commands.rb
Expand Up @@ -57,6 +57,17 @@ def readme(*args)
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
Expand All @@ -70,7 +81,11 @@ def migration_exists?(file_name)
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)
Expand Down

0 comments on commit bbab639

Please sign in to comment.