Skip to content

Commit

Permalink
Allow AR::Schema's migrations_path to be overwritten by subclasses. D…
Browse files Browse the repository at this point in the history
…efaults to 'db/migrate'

[#3671 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
packagethief authored and jeremy committed Jan 8, 2010
1 parent d5ba7c3 commit 6e9b01f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Expand Up @@ -336,12 +336,12 @@ def initialize_schema_migrations_table
end
end

def assume_migrated_upto_version(version)
def assume_migrated_upto_version(version, migrations_path = ActiveRecord::Migrator.migrations_path)
version = version.to_i
sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)

migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i)
versions = Dir['db/migrate/[0-9]*_*.rb'].map do |filename|
versions = Dir["#{migrations_path}/[0-9]*_*.rb"].map do |filename|
filename.split('/').last.split('_').first.to_i
end

Expand Down
4 changes: 4 additions & 0 deletions activerecord/lib/active_record/migration.rb
Expand Up @@ -408,6 +408,10 @@ def run(direction, migrations_path, target_version)
self.new(direction, migrations_path, target_version).run
end

def migrations_path
'db/migrate'
end

def schema_migrations_table_name
Base.table_name_prefix + 'schema_migrations' + Base.table_name_suffix
end
Expand Down
6 changes: 5 additions & 1 deletion activerecord/lib/active_record/schema.rb
Expand Up @@ -28,6 +28,10 @@ module ActiveRecord
class Schema < Migration
private_class_method :new

def self.migrations_path
ActiveRecord::Migrator.migrations_path
end

# Eval the given block. All methods available to the current connection
# adapter are available within the block, so you can easily use the
# database definition DSL to build up your schema (+create_table+,
Expand All @@ -44,7 +48,7 @@ def self.define(info={}, &block)

unless info[:version].blank?
initialize_schema_migrations_table
assume_migrated_upto_version info[:version]
assume_migrated_upto_version(info[:version], migrations_path)
end
end
end
Expand Down

0 comments on commit 6e9b01f

Please sign in to comment.