-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
モデル生成時にreferences/belongs_toを指定した場合に、モデルのマイグレーションでindexを別に作らせない #11
base: develop
Are you sure you want to change the base?
Conversation
* add postgres 10.21, 11.16, 12.11, 13.7, 14.3 * use versions existing on hub.docker.com (10.20, 11.15, 12.10, 13.6, 14.2) * Upgrade ci postgres version from 9.5 to 10 (drop 10.20, 11.15, 12.10, 13.6, 14.2) Co-authored-by: Ko Nagase <[email protected]>
* Add VSCode devcontainer用の設定を追加 * Add docker-compose.yml * Move Dockerfile-for-redmine-dev-mirror to .devcontainer/Dockerfile * Fix Rubyのバージョン変更の手順 * Update README.md * Update DockerfileでADDしなくなったことによって機能しなくなっていたコードを削除
* Adjust docker-compose.yml MySQL settings and expose PostgreSQL/MySQL ports * Adjust SQLTools MySQL driver and connections
@@ -24,7 +24,6 @@ class RedminePluginModelGenerator < Rails::Generators::NamedBase | |||
class_option :migration, :type => :boolean, :default => true | |||
class_option :timestamps, :type => :boolean | |||
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これを残す方向での修正も検討したのですが、下記の想定を行った結果消すことにしました。
foreign_key: true
を指定せずにマイグレーションを生成しないといけない- 別途
add_index
を書きたいのはカスタマイズしたindexを貼りたいからというのが大きいと思う、であればgeneratorは何もせず、自分で書いてもらう方が良い
end | ||
|
||
private | ||
|
||
def attributes_with_index | ||
attributes.select {|a| a.has_index? || (a.reference? && options[:indexes])} | ||
attributes.select {|a| a.has_index?} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attributes.select {|a| a.has_index?} | |
attributes.select(&:has_index?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
良いと思いました! 🎉 ご対応おつかれさまでした.
気づいた点は細かいことですのでApproveします.
|
||
assert_match %r{t\.references :issue, foreign_key: true}, migration | ||
assert_match %r{t\.belongs_to :project, foreign_key: true}, migration | ||
assert_no_match %r{add_index}, path_names.first.read |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かいですが,以下で良さそうです.
assert_no_match %r{add_index}, path_names.first.read | |
assert_no_match %r{add_index}, migration |
lib/generators/redmine_plugin_model/templates/migration.rb
については、修正とは直接関係ないですが、明らかにerbファイルなのでリネームしています。