Skip to content

Commit

Permalink
Add migrations_paths option to model generator
Browse files Browse the repository at this point in the history
  • Loading branch information
gmcgibbon committed Sep 27, 2018
1 parent 1930d22 commit 77aaece
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ModelGenerator < Base # :nodoc:
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
Expand Down
16 changes: 16 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions railties/test/generators/model_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,15 @@ def test_add_uuid_to_create_table_migration
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}"]

Expand Down
6 changes: 6 additions & 0 deletions railties/test/generators/scaffold_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ def test_scaffold_generator_belongs_to
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"]

Expand Down

0 comments on commit 77aaece

Please sign in to comment.