-
Notifications
You must be signed in to change notification settings - Fork 73
メンター用プロフィール公開設定のON/OFFスイッチの反転と属性名変更 #8553
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
Conversation
81a78f8
to
0748586
Compare
0748586
to
c5d6ae6
Compare
@kushimegu |
@sekito1107 |
動作は確認できたのですが、コードで気になったことがあったのでコメントしました! |
@kushimegu |
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.
すみません、pendingになっていることに気づかず…。Submit reviewしたので見えるかなと思います。確認をお願いします。
def down | ||
execute "UPDATE users SET show_mentor_profile = NOT show_mentor_profile" | ||
end | ||
end |
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.
マイグレーションファイルを書き換えるわけにはいかないと思うのでただの意見なんですが、
execute
でSQLを書くよりupdate_all
した方がコードが短くなるのでは- Rails Guideでは
reversible
メソッドとchange
を使う代わりにup/down
も使えると書かれているのでreversible
を使えるならそちらで良いのかも
と思ったのですが、どうでしょうか?
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.
ご指摘ありがとうございます!
マイグレーションファイルについては、本番環境で既に運用されている場合は書き換えずに新しいマイグレーションを追加するほうが良いと思いますが、今回は開発ブランチでの作業なので、書き換えでも問題ないと判断しました👍
また、update_all を使う方がより Rails っぽくて読みやすいと感じたので、そちらを取り入れさせていただきました!
reversible についても確かにその書き方は可能だと思いますが、「reversible を優先すべき」というよりは、処理の意図が伝わりやすい書き方を選ぶべきだと考えています。
今回のようにシンプルな反転処理であれば、up/down を使って明示的に書いたほうが分かりやすいかなと思ったのですが、いかがでしょうか?🙏
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.
@sekito1107 dataの変更はdata-migrateを使って下さい。
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.
@kushimegu
レビューありがとうございます、修正に伴いコメントしましたのでご確認お願いしますー🙏
def down | ||
execute "UPDATE users SET show_mentor_profile = NOT show_mentor_profile" | ||
end | ||
end |
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.
ご指摘ありがとうございます!
マイグレーションファイルについては、本番環境で既に運用されている場合は書き換えずに新しいマイグレーションを追加するほうが良いと思いますが、今回は開発ブランチでの作業なので、書き換えでも問題ないと判断しました👍
また、update_all を使う方がより Rails っぽくて読みやすいと感じたので、そちらを取り入れさせていただきました!
reversible についても確かにその書き方は可能だと思いますが、「reversible を優先すべき」というよりは、処理の意図が伝わりやすい書き方を選ぶべきだと考えています。
今回のようにシンプルな反転処理であれば、up/down を使って明示的に書いたほうが分かりやすいかなと思ったのですが、いかがでしょうか?🙏
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.
マイグレーションファイルについては、本番環境で既に運用されている場合は書き換えずに新しいマイグレーションを追加するほうが良いと思いますが、今回は開発ブランチでの作業なので、書き換えでも問題ないと判断しました👍
捕捉と修正ありがとうございます!
reversible
を使うかup/down
を使うかでどっちが読みやすいかは正直判断できないのですが、特にどちらでも問題ないと思うのでこれでApproveとさせていただきます。
@kushimegu @komagata |
da88d11
to
2966581
Compare
7ac6f87
to
2e1de97
Compare
data-migrateを使用するように修正しましたので、ご確認お願いしますー。 |
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.
rubocopによりupdate_all
はバリデーションをスキップするので使用に注意するようにとの旨の警告がでますが、今回のケースでは使用に問題はないと考え無効化しています
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.
migrate, data-migrateは実際にローカルなどで実行して問題なかったでしょうか。
また、migrate, data-migrateがどちらが先に実行されるかなどは確認済みでしょうか。
2e1de97
to
86e9412
Compare
@komagata ローカルでの実行では問題ありませんでした。(デモ時の失敗は、更新ボタンを押していないからでした) 実行順についてですが、 また併せて動作確認方法も修正させて頂きましたー。 |
@sekito1107 data-migrateを入れると基本的に |
@komagata
bonnmasa@DESKTOP-NLLF6L7:~/fjord/bootcamp$ rails db:migrate:with_data
DEPRECATION WARNING: Support for Ruby versions < 3.2.0 is deprecated and will be removed from ViewComponent 4.0.0 (ViewComponent v4 will remove support for Ruby versions < 3.2.0 no earlier than April 1, 2025) (called from <main> at /home/bonnmasa/fjord/bootcamp/config/environment.rb:5)
DEPRECATION WARNING: Support for Rails versions < 7.1 is deprecated and will be removed from ViewComponent 4.0.0 (ViewComponent v4 will remove support for Rails versions < 7.1 no earlier than April 1, 2025) (called from <main> at /home/bonnmasa/fjord/bootcamp/config/environment.rb:5)
== Data =======================================================================
== 20201122113956 ChangeKomagata: migrating ===================================
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `show_mentor_profile' for #<User id: 459775584, login_name: "komagata", email: "[email protected]", crypted_password: "$2a$10$n/xv4/1luueN6plzm2OyDezWlZFyGHjQEf4hwAW1r3k...", salt: "zW3kQ9ubsxQQtzzzs4ap", created_at: "2014-01-01 09:00:01.000000000 +0900", updated_at: "2025-05-09 18:16:51.430521000 +0900", remember_me_token: nil, remember_me_token_expires_at: nil, twitter_account: "komagata", facebook_url: "https://www.facebook.com/fjordllc/komagata1111", blog_url: "http://komagata.org", company_id: 636488896, description: "平日10〜19時勤務です。", accessed_at: nil, github_account: "komagata", adviser: false, nda: true, reset_password_token: nil, reset_password_token_expires_at: nil, reset_password_email_sent_at: nil, mentor: true, graduated_on: nil, course_id: 829913840, retired_on: nil, admin: true, job: "office_worker", organization: "株式会社ロッカ", os: "mac", experience: nil, trainee: false, retire_reason: nil, job_seeking: false, customer_id: nil, subscription_id: nil, mail_notification: true, job_seeker: false, github_collaborator: true, github_id: "github-komagata", satisfaction: nil, opinion: nil, retire_reasons: 0, name: "Komagata Masakitest", name_kana: "コマガタ マサキ", unsubscribe_email_token: "037i-ef5n7V4EnPv74mtyQ", mentor_memo: nil, after_graduation_hope: nil, training_ends_on: nil, sad_streak: false, last_sad_report_id: nil, last_activity_at: "2014-01-01 09:00:01.000000000 +0900", hibernated_at: nil, profile_name: "駒形 真幸", profile_job: "エンジニア", profile_text: "株式会社ロッカの代表兼エンジニア。Rubyが大好きで怖話、フィヨルドブートキャンプなどを開発している...", feed_url: nil, sent_student_followup_message: true, country_code: "JP", subdivision_code: "13", auto_retire: true, invoice_payment: false, editor: nil, other_editor: nil, hide_mentor_profile: false, experiences: 38, referral_source: nil, other_referral_source: nil, career_path: "unset", career_memo: nil, tag_list: nil>
/home/bonnmasa/fjord/bootcamp/db/data/20201122113956_change_komagata.rb:6:in `up'
/home/bonnmasa/fjord/bootcamp/bin/rails:5:in `<top (required)>'
/home/bonnmasa/fjord/bootcamp/bin/spring:10:in `block in <top (required)>'
/home/bonnmasa/fjord/bootcamp/bin/spring:7:in `<top (required)>'
Caused by:
NoMethodError: undefined method `show_mentor_profile' for #<User id: 459775584, login_name: "komagata", email: "[email protected]", crypted_password: "$2a$10$n/xv4/1luueN6plzm2OyDezWlZFyGHjQEf4hwAW1r3k...", salt: "zW3kQ9ubsxQQtzzzs4ap", created_at: "2014-01-01 09:00:01.000000000 +0900", updated_at: "2025-05-09 18:16:51.430521000 +0900", remember_me_token: nil, remember_me_token_expires_at: nil, twitter_account: "komagata", facebook_url: "https://www.facebook.com/fjordllc/komagata1111", blog_url: "http://komagata.org", company_id: 636488896, description: "平日10〜19時勤務です。", accessed_at: nil, github_account: "komagata", adviser: false, nda: true, reset_password_token: nil, reset_password_token_expires_at: nil, reset_password_email_sent_at: nil, mentor: true, graduated_on: nil, course_id: 829913840, retired_on: nil, admin: true, job: "office_worker", organization: "株式会社ロッカ", os: "mac", experience: nil, trainee: false, retire_reason: nil, job_seeking: false, customer_id: nil, subscription_id: nil, mail_notification: true, job_seeker: false, github_collaborator: true, github_id: "github-komagata", satisfaction: nil, opinion: nil, retire_reasons: 0, name: "Komagata Masakitest", name_kana: "コマガタ マサキ", unsubscribe_email_token: "037i-ef5n7V4EnPv74mtyQ", mentor_memo: nil, after_graduation_hope: nil, training_ends_on: nil, sad_streak: false, last_sad_report_id: nil, last_activity_at: "2014-01-01 09:00:01.000000000 +0900", hibernated_at: nil, profile_name: "駒形 真幸", profile_job: "エンジニア", profile_text: "株式会社ロッカの代表兼エンジニア。Rubyが大好きで怖話、フィヨルドブートキャンプなどを開発している...", feed_url: nil, sent_student_followup_message: true, country_code: "JP", subdivision_code: "13", auto_retire: true, invoice_payment: false, editor: nil, other_editor: nil, hide_mentor_profile: false, experiences: 38, referral_source: nil, other_referral_source: nil, career_path: "unset", career_memo: nil, tag_list: nil>
/home/bonnmasa/fjord/bootcamp/db/data/20201122113956_change_komagata.rb:6:in `up'
/home/bonnmasa/fjord/bootcamp/bin/rails:5:in `<top (required)>'
/home/bonnmasa/fjord/bootcamp/bin/spring:10:in `block in <top (required)>'
/home/bonnmasa/fjord/bootcamp/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:migrate:with_data
(See full trace by running task with --trace)
ログを見る限り過去のデータマイグレーションを実行しようとして、その中で しかしそもそもの話、過去のデータマイグレーションが実行されてしまうこと自体が問題なのではないかと思っています。
今回の実装で追加した |
上記の件ですが 全て未実行になっていたのはこちらの環境の問題だと認識していますので、今回の実行結果をもって目的であった実行順の確認は完了したと考えていますー。 実行したSQL文は bootcamp_development=# INSERT INTO data_migrations (version) VALUES
('20201122113956'),
('20201124023746'),
('20201207173712'),
('20210115022107'),
('20210118060304'),
('20210616072230'),
('20210817170736'),
('20210915021559'),
('20210927124918'),
('20211014120659'),
('20211018121231'),
('20211208002045'),
('20211217030634'),
('20211228070332'),
('20220114203650'),
('20220130224201'),
('20220226162158'),
('20220625052654'),
('20230114032018'),
('20230412211754'),
('20230413102301'),
('20230421051042'),
('20230510134712'),
('20230519040511'),
('20230701031415'),
('20230726024528'),
('20230809233700'),
('20240704140358'),
('20240718110343'),
('20250314075905'),
('20250317034528'),
('20250321000000'); その後に
|
@sekito1107 確認ありがとうございます。であれば大丈夫です。 意図としては、data-migrationをローカルで一回も実行したことがない状態でリリースして本番で失敗することがよくあるため、実行して確かめておきたかった感じです。 |
class ReverseShowMentorProfileForUsers < ActiveRecord::Migration[6.1] | ||
def up | ||
# rubocop:disable Rails/SkipsModelValidations | ||
User.update_all('show_mentor_profile = NOT show_mentor_profile') |
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.
これってメンター以外の人のデータは大丈夫ですか?
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.
問題ないと考えていますー。
修正前のデータで非メンターのhide_metor_profile
を確認すると以下のようにfalse
になってることが確認できます
今回の修正ではカラム名をshow_mentor_profile
と変え、trueとfalseの役割を反転させたので、従来の形を維持するにはメンター以外のboolean値も反転させる必要があるからです。
ローカルでもメンター以外のプロフィールは表示されないことを確認しています。(表示側で一度メンターのリストを取得してからshow_mentor_profile
を確認しているからメンター以外は表示されない)
従来のhide_mentor_profile
がデフォルトでfalse
になっていたことが問題であるならば、それについては別途解決策を用意しなければいけないかもしれません。
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.
@sekito1107 もともとnullだとどうなりますか?
従来のhide_mentor_profileがデフォルトでfalseになっていたことが問題であるならば、それについては別途解決策を用意しなければいけないかもしれません。
反転したのであればデフォルト値も変えないとおかしいのでこのIssueで変えたいですね。
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.
@komagata
モデルにvalidates :hide_mentor_profile, inclusion: { in: [true, false] }
このように記述されているので、このカラムがnilのユーザーはいないと思っています。(今回の修正後のコードではvalidates :show_mentor_profile, inclusion: { in: [true, false] }
)
以下画像のようにしてもnilを入れることは出来ません。
デフォルト値のことですが、言葉足らずでしたごめんなさい🙇
新たにカラム名を変更したshow_mentor_profile
(旧hide_mentor_profile
)に関してはデフォルト値を変更しています。
僕が前のコメントで言いたかったのはデフォルトがメンターも他のユーザーも公開するになっているのが問題であれば何らかの手段で解決策を用意したほうがいいかもしれないという意味でした。
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.
元々nilのユーザーはrails db:migrate:with_data
実行後もnilであることを確認しましたー。
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.
@sekito1107 確認ありがとうございます〜!
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.
確認させて頂きました。OKです〜🙆♂️
@sekito1107 本番で確認できましたー🙆♂️ |
確認ありがとうございますー! |
Issue
#8528
概要
UIの直感性向上:
従来のUIでは「プロフィール非公開 (OFF)」という表現が、プロフィールの公開状態を示すものとして直感的ではありませんでした (画像参照)。
これを改善するため、スイッチの表示を「公開」状態を示す「ON」に変更し、UIの直感性を高めました。
文言の修正:
UIの変更に合わせて、プロフィールの公開設定に関する案内文を修正しました。
データモデルの変更:
直感的なUIを実現するため、プロフィールの公開状態を保存する属性名を変更し、既存の真偽値を反転させました。
( 元の属性名
hide_mentor_profile
をshow_mentor_profile
に変更し、真偽値を反転)変更確認方法
feature/invert-profile-visibility-switch
をローカルに取り込むgit checkout feature/invert-profile-visibility-switch
bin/rails db:migrate
でデータベースを更新するrails data:migrate:up VERSION=20250506005656
でデータを更新するforeman start -f Procfile.dev
でローカル環境を立ち上げるkomagata
pass:testtest
でログインするhttp://localhost:3000/
にアクセスし、下部へとスクロールし、メンター顧問 の欄に適切にプロフィールが表示されているのを確認するScreenshot
変更前
変更後