aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/rails
diff options
context:
space:
mode:
authorKevin Glowacz <kevin@glowacz.info>2017-01-13 10:02:02 -0600
committerKevin Glowacz <kevin@glowacz.info>2017-01-16 12:24:37 -0600
commitc942361a601b9486967ab45bdc3d2d0ce926977f (patch)
tree5250930991d397633490c8bc3c2cc38bcc3661d5 /activerecord/lib/rails
parentc8e92f174d9190fe4cb38199bc2e59d62ace0003 (diff)
downloadrails-c942361a601b9486967ab45bdc3d2d0ce926977f.tar.gz
rails-c942361a601b9486967ab45bdc3d2d0ce926977f.tar.bz2
rails-c942361a601b9486967ab45bdc3d2d0ce926977f.zip
Generate migrations at path set by `config.paths["db/migrate"]`
Diffstat (limited to 'activerecord/lib/rails')
-rw-r--r--activerecord/lib/rails/generators/active_record/migration/migration_generator.rb10
-rw-r--r--activerecord/lib/rails/generators/active_record/model/model_generator.rb10
2 files changed, 18 insertions, 2 deletions
diff --git a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
index 8511531af7..c2ae21b4b2 100644
--- a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
+++ b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
@@ -10,7 +10,7 @@ module ActiveRecord
def create_migration_file
set_local_assigns!
validate_file_name!
- migration_template @migration_template, "db/migrate/#{file_name}.rb"
+ migration_template @migration_template, File.join(db_migrate_path, "#{file_name}.rb")
end
# TODO Change this to private once we've dropped Ruby 2.2 support.
@@ -71,6 +71,14 @@ module ActiveRecord
def normalize_table_name(_table_name)
pluralize_table_names? ? _table_name.pluralize : _table_name.singularize
end
+
+ def db_migrate_path
+ if defined?(Rails) && Rails.application
+ Rails.application.config.paths["db/migrate"].to_ary.first
+ else
+ "db/migrate"
+ end
+ end
end
end
end
diff --git a/activerecord/lib/rails/generators/active_record/model/model_generator.rb b/activerecord/lib/rails/generators/active_record/model/model_generator.rb
index a9df5212e3..b26ad42859 100644
--- a/activerecord/lib/rails/generators/active_record/model/model_generator.rb
+++ b/activerecord/lib/rails/generators/active_record/model/model_generator.rb
@@ -17,7 +17,7 @@ module ActiveRecord
def create_migration_file
return unless options[:migration] && options[:parent].nil?
attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false
- migration_template "../../migration/templates/create_table_migration.rb", "db/migrate/create_#{table_name}.rb"
+ migration_template "../../migration/templates/create_table_migration.rb", File.join(db_migrate_path, "create_#{table_name}.rb")
end
def create_model_file
@@ -64,6 +64,14 @@ module ActiveRecord
"app/models/application_record.rb"
end
end
+
+ def db_migrate_path
+ if defined?(Rails) && Rails.application
+ Rails.application.config.paths["db/migrate"].to_ary.first
+ else
+ "db/migrate"
+ end
+ end
end
end
end