提交 1d9de9d7 编写于 作者: P Piotr Sarnacki

Run also migrations in subdirectories.

With this commit, ActiveRecord will also look for migrations
in db/migrate subdirectories.
上级 b164ab75
......@@ -610,10 +610,11 @@ def migrations_path
migrations_paths.first
end
def migrations(paths)
def migrations(paths, subdirectories = true)
paths = Array.wrap(paths)
files = Dir[*paths.map { |p| "#{p}/[0-9]*_*.rb" }]
glob = subdirectories ? "**/" : ""
files = Dir[*paths.map { |p| "#{p}/#{glob}[0-9]*_*.rb" }]
seen = Hash.new false
......
......@@ -1346,6 +1346,15 @@ def test_finds_migrations
end
end
def test_finds_migrations_in_subdirectories
migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid_with_subdirectories").migrations
[[1, 'ValidPeopleHaveLastNames'], [2, 'WeNeedReminders'], [3, 'InnocentJointable']].each_with_index do |pair, i|
assert_equal migrations[i].version, pair.first
assert_equal migrations[i].name, pair.last
end
end
def test_finds_migrations_from_two_directories
directories = [MIGRATIONS_ROOT + '/valid_with_timestamps', MIGRATIONS_ROOT + '/to_copy_with_timestamps']
migrations = ActiveRecord::Migrator.new(:up, directories).migrations
......
class ValidPeopleHaveLastNames < ActiveRecord::Migration
def self.up
add_column "people", "last_name", :string
end
def self.down
remove_column "people", "last_name"
end
end
class WeNeedReminders < ActiveRecord::Migration
def self.up
create_table("reminders") do |t|
t.column :content, :text
t.column :remind_at, :datetime
end
end
def self.down
drop_table "reminders"
end
end
\ No newline at end of file
class InnocentJointable < ActiveRecord::Migration
def self.up
create_table("people_reminders", :id => false) do |t|
t.column :reminder_id, :integer
t.column :person_id, :integer
end
end
def self.down
drop_table "people_reminders"
end
end
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册