Add migrations_paths option to model generator

This commit is contained in:
Gannon McGibbon 2018-09-26 17:16:54 -04:00
parent 1930d22936
commit 77aaeced89
4 changed files with 32 additions and 0 deletions

View File

@ -14,6 +14,7 @@ module ActiveRecord
class_option :parent, type: :string, desc: "The parent class for the generated model"
class_option :indexes, type: :boolean, default: true, desc: "Add indexes for references and belongs_to columns"
class_option :primary_key_type, type: :string, desc: "The type for primary key"
class_option :migrations_paths, type: :string, desc: "The migration path for your generated migrations. If this is not set it will default to db/migrate"
# creates the migration file for the model.
def create_migration_file

View File

@ -1,3 +1,19 @@
* Adds an option to the model generator to allow setting the
migrations paths for that migration. This is useful for
applications that use multiple databases and put migrations
per database in their own directories.
```
bin/rails g model Room capacity:integer --migrations-paths=db/kingston_migrate
invoke active_record
create db/kingston_migrate/20180830151055_create_rooms.rb
```
Because rails scaffolding uses the model generator, you can
also specify migrations paths with the scaffold generator.
*Gannon McGibbon*
* Raise an error when "recyclable cache keys" are being used by a cache store
that does not explicitly support it. Custom cache keys that do support this feature
can bypass this error by implementing the `supports_cache_versioning?` method on their

View File

@ -392,6 +392,15 @@ class ModelGeneratorTest < Rails::Generators::TestCase
end
end
def test_migrations_paths_puts_migrations_in_that_folder
run_generator ["account", "--migrations_paths=db/test_migrate"]
assert_migration "db/test_migrate/create_accounts.rb" do |content|
assert_method :change, content do |change|
assert_match(/create_table :accounts/, change)
end
end
end
def test_required_belongs_to_adds_required_association
run_generator ["account", "supplier:references{required}"]

View File

@ -476,6 +476,12 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
end
end
def test_scaffold_generator_migrations_paths
run_generator ["posts", "--migrations-paths=db/kingston_migrate"]
assert_migration "db/kingston_migrate/create_posts.rb"
end
def test_scaffold_generator_password_digest
run_generator ["user", "name", "password:digest"]