mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Run also migrations in subdirectories.
With this commit, ActiveRecord will also look for migrations in db/migrate subdirectories.
This commit is contained in:
parent
b164ab75d6
commit
1d9de9d758
5 changed files with 45 additions and 2 deletions
|
@ -610,10 +610,11 @@ module ActiveRecord
|
|||
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 @@ if ActiveRecord::Base.connection.supports_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
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class ValidPeopleHaveLastNames < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column "people", "last_name", :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column "people", "last_name"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
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
|
|
@ -0,0 +1,12 @@
|
|||
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
|
Loading…
Reference in a new issue