Skip to content
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

Draft
wants to merge 24 commits into
base: develop
Choose a base branch
from

Conversation

mk2
Copy link
Contributor

@mk2 mk2 commented Jun 30, 2023

lib/generators/redmine_plugin_model/templates/migration.rbについては、修正とは直接関係ないですが、明らかにerbファイルなのでリネームしています。

kfischer-okarin and others added 24 commits June 16, 2023 07:22
* 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
@mk2 mk2 self-assigned this Jun 30, 2023
@@ -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"
Copy link
Contributor Author

@mk2 mk2 Jun 30, 2023

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は何もせず、自分で書いてもらう方が良い

@mk2 mk2 requested review from nishidayuya, kumojima and telegib June 30, 2023 04:26
end

private

def attributes_with_index
attributes.select {|a| a.has_index? || (a.reference? && options[:indexes])}
attributes.select {|a| a.has_index?}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
attributes.select {|a| a.has_index?}
attributes.select(&:has_index?)

Copy link

@nishidayuya nishidayuya left a 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

細かいですが,以下で良さそうです.

Suggested change
assert_no_match %r{add_index}, path_names.first.read
assert_no_match %r{add_index}, migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants