Skip to content

メンター用プロフィール公開設定の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

Merged
merged 12 commits into from
May 19, 2025

Conversation

sekito1107
Copy link
Contributor

@sekito1107 sekito1107 commented Apr 11, 2025

Issue

#8528

概要

430437290-efb49f01-1cb2-4c1c-9765-c1b7b8050f36
  1. UIの直感性向上:
    従来のUIでは「プロフィール非公開 (OFF)」という表現が、プロフィールの公開状態を示すものとして直感的ではありませんでした (画像参照)。
    これを改善するため、スイッチの表示を「公開」状態を示す「ON」に変更し、UIの直感性を高めました。

  2. 文言の修正:
    UIの変更に合わせて、プロフィールの公開設定に関する案内文を修正しました。

  3. データモデルの変更:
    直感的なUIを実現するため、プロフィールの公開状態を保存する属性名を変更し、既存の真偽値を反転させました。
    ( 元の属性名 hide_mentor_profileshow_mentor_profile に変更し、真偽値を反転)

変更確認方法

  1. feature/invert-profile-visibility-switchをローカルに取り込む
    • git checkout feature/invert-profile-visibility-switch
  2. bin/rails db:migrate でデータベースを更新する
  3. rails data:migrate:up VERSION=20250506005656でデータを更新する
  4. foreman start -f Procfile.dev でローカル環境を立ち上げる
  5. id:komagata pass:testtest でログインする
  6. http://localhost:3000/current_user/edit にアクセスし、メンター紹介用公開プロフィールの欄が以下の画像のようになっていることを確認する
    image
  7. ログアウトする
  8. http://localhost:3000/ にアクセスし、下部へとスクロールし、メンター顧問 の欄に適切にプロフィールが表示されているのを確認する

Screenshot

変更前

image

変更後

image

@sekito1107 sekito1107 force-pushed the feature/invert-profile-visibility-switch branch from 81a78f8 to 0748586 Compare April 11, 2025 12:05
@sekito1107 sekito1107 changed the title メンタープロフィールの公開可否に利用している属性値を変更 メンタープロフィールの公開可否に利用している属性名を変更 Apr 11, 2025
@sekito1107 sekito1107 force-pushed the feature/invert-profile-visibility-switch branch from 0748586 to c5d6ae6 Compare April 11, 2025 23:53
@sekito1107 sekito1107 changed the title メンタープロフィールの公開可否に利用している属性名を変更 メンター用プロフィール公開設定のON/OFFスイッチの反転と属性名変更 Apr 12, 2025
@sekito1107 sekito1107 requested a review from kushimegu April 12, 2025 03:06
@sekito1107 sekito1107 marked this pull request as ready for review April 12, 2025 03:08
@sekito1107
Copy link
Contributor Author

@kushimegu
良ければこちらレビューお願いできないでしょうかー?
急ぎではありませんのでご都合のつく時で大丈夫です
ご検討お願いしますー🙏

@kushimegu
Copy link
Contributor

@sekito1107
大丈夫です!
近日中にレビューさせていただきます。

@kushimegu
Copy link
Contributor

動作は確認できたのですが、コードで気になったことがあったのでコメントしました!

@sekito1107
Copy link
Contributor Author

@kushimegu
レビューありがとうございます!
恐らくですが、レビューして頂いたコメントがpendingになっていてこちらから見ることができませんー。

参考:https://qiita.com/Ryo-0131/items/29080f242256ab3f1375

Copy link
Contributor

@kushimegu kushimegu left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

マイグレーションファイルを書き換えるわけにはいかないと思うのでただの意見なんですが、

  1. executeでSQLを書くよりupdate_allした方がコードが短くなるのでは
  2. Rails Guideではreversibleメソッドとchangeを使う代わりにup/downも使えると書かれているのでreversibleを使えるならそちらで良いのかも

と思ったのですが、どうでしょうか?

Copy link
Contributor Author

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 を使って明示的に書いたほうが分かりやすいかなと思ったのですが、いかがでしょうか?🙏

Copy link
Member

Choose a reason for hiding this comment

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

@sekito1107 dataの変更はdata-migrateを使って下さい。

Copy link
Contributor Author

@sekito1107 sekito1107 left a 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
Copy link
Contributor Author

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 を使って明示的に書いたほうが分かりやすいかなと思ったのですが、いかがでしょうか?🙏

@sekito1107 sekito1107 requested a review from kushimegu April 19, 2025 05:32
Copy link
Contributor

@kushimegu kushimegu left a 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とさせていただきます。

@sekito1107
Copy link
Contributor Author

@kushimegu
レビューありがとうございました🙇‍♂️

@komagata
こちらレビューお願いしますー。

@sekito1107 sekito1107 requested a review from komagata April 22, 2025 14:35
@sekito1107 sekito1107 force-pushed the feature/invert-profile-visibility-switch branch from da88d11 to 2966581 Compare April 22, 2025 14:41
@sekito1107 sekito1107 force-pushed the feature/invert-profile-visibility-switch branch 2 times, most recently from 7ac6f87 to 2e1de97 Compare May 6, 2025 01:09
@sekito1107
Copy link
Contributor Author

@komagata

data-migrateを使用するように修正しましたので、ご確認お願いしますー。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rubocopによりupdate_allはバリデーションをスキップするので使用に注意するようにとの旨の警告がでますが、今回のケースでは使用に問題はないと考え無効化しています

Copy link
Member

@komagata komagata left a 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がどちらが先に実行されるかなどは確認済みでしょうか。

@sekito1107 sekito1107 force-pushed the feature/invert-profile-visibility-switch branch from 2e1de97 to 86e9412 Compare May 8, 2025 07:50
@sekito1107
Copy link
Contributor Author

sekito1107 commented May 8, 2025

@komagata
data-migrateを使用するようにしたにも関わらず、動作確認方法を更新しなかったためお手間をかけさせることになってしまいました。

ローカルでの実行では問題ありませんでした。(デモ時の失敗は、更新ボタンを押していないからでした)

実行順についてですが、rails db:migrateを実行するとdb/migrate配下のマイグレーションを実行しますが、db/data配下のマイグレーションは実行されないため、別途rails data:migrateを実行する必要があります。
今回の実装ではdata-migrateが行われる際にカラムにshow_mentor_profileが存在することが期待されているので、先にrails db:migrateを行ってからrails data:migrate:up VERSION=20250506005656を実行することで、migrateが行われてからdata-migrateが行われるという期待通りの動作をさせることが出来ます。

また併せて動作確認方法も修正させて頂きましたー。

@komagata
Copy link
Member

komagata commented May 9, 2025

@sekito1107 data-migrateを入れると基本的にrails db:migrate:with_dataを実行する形になります。
これ実行して、実行順序などを確認していただければありがたいです〜。

@sekito1107
Copy link
Contributor Author

@komagata
1点質問させてくださいー。
ローカルでrails db:migrate:with_dataを実行した場合うまく実行することが出来ません。
恐らく下記に示す通り古いデータマイグレーションファイルが実行されてないと判断されているからだと予想していますが、どのように修正すればいいでしょうか?

rails db:migrate:with_dataを実行するとエラーが発生します、エラーログの詳細は下記に格納します

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)

ログを見る限り過去のデータマイグレーションを実行しようとして、その中でshow_mentor_profileがないことでエラーが起きています。

しかしそもそもの話、過去のデータマイグレーションが実行されてしまうこと自体が問題なのではないかと思っています。

data:migrate:statusを実行すると下記の画像のようにログが出力されるので、全てのデータマイグレーションが未実行として扱われています。

image

今回の実装で追加したdb/data/20250506005656_reverse_show_mentor_profile_for_users.rb以外のデータマイグレーションファイルを削除してからrails db:migrate:with_dataを実行したところmigrate → data-migrateの順番で実行され、期待通りの動作をしました。

@sekito1107
Copy link
Contributor Author

sekito1107 commented May 11, 2025

@komagata

上記の件ですがrails dbの後に以下の今回の実装で追加したデータマイグレーション以外のデータマイグレーションを実行済みとして扱うSQL文を実行してからrails db:migrate:with_dataを実行することで期待通りに動作しました。

全て未実行になっていたのはこちらの環境の問題だと認識していますので、今回の実行結果をもって目的であった実行順の確認は完了したと考えていますー。

実行した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');

その後にrails db:migrate:with_dataした際の実行順は以下のとおりです。

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)
== Schema =====================================================================
== 20250411091233 RenameHideMentorProfileToShowMentorProfileInUsers: migrating
-- rename_column(:users, :hide_mentor_profile, :show_mentor_profile)
   -> 0.0078s
== 20250411091233 RenameHideMentorProfileToShowMentorProfileInUsers: migrated (0.0080s)

== Schema =====================================================================
== 20250411102806 ChangeDefaultToShowMentorColumn: migrating ==================
-- change_column_default(:users, :show_mentor_profile, {:from=>false, :to=>true})
   -> 0.0081s
== 20250411102806 ChangeDefaultToShowMentorColumn: migrated (0.0082s) =========

== Data =======================================================================
== 20250506005656 ReverseShowMentorProfileForUsers: migrating =================
== 20250506005656 ReverseShowMentorProfileForUsers: migrated (0.2397s) ========

@komagata
Copy link
Member

@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')
Copy link
Member

Choose a reason for hiding this comment

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

これってメンター以外の人のデータは大丈夫ですか?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@komagata

問題ないと考えていますー。

修正前のデータで非メンターのhide_metor_profileを確認すると以下のようにfalseになってることが確認できます

image

今回の修正ではカラム名をshow_mentor_profileと変え、trueとfalseの役割を反転させたので、従来の形を維持するにはメンター以外のboolean値も反転させる必要があるからです。

ローカルでもメンター以外のプロフィールは表示されないことを確認しています。(表示側で一度メンターのリストを取得してからshow_mentor_profileを確認しているからメンター以外は表示されない)

従来のhide_mentor_profileがデフォルトでfalseになっていたことが問題であるならば、それについては別途解決策を用意しなければいけないかもしれません。

Copy link
Member

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で変えたいですね。

Copy link
Contributor Author

@sekito1107 sekito1107 May 15, 2025

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を入れることは出来ません。

image

デフォルト値のことですが、言葉足らずでしたごめんなさい🙇
新たにカラム名を変更したshow_mentor_profile(旧hide_mentor_profile)に関してはデフォルト値を変更しています。

僕が前のコメントで言いたかったのはデフォルトがメンターも他のユーザーも公開するになっているのが問題であれば何らかの手段で解決策を用意したほうがいいかもしれないという意味でした。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@komagata

元々nilのユーザーはrails db:migrate:with_data実行後もnilであることを確認しましたー。

Copy link
Member

Choose a reason for hiding this comment

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

@sekito1107 確認ありがとうございます〜!

Copy link
Member

@komagata komagata left a comment

Choose a reason for hiding this comment

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

確認させて頂きました。OKです〜🙆‍♂️

@komagata komagata merged commit f057aeb into main May 19, 2025
10 checks passed
@komagata komagata deleted the feature/invert-profile-visibility-switch branch May 19, 2025 16:22
@github-actions github-actions bot mentioned this pull request May 19, 2025
19 tasks
@machida
Copy link
Member

machida commented May 22, 2025

@sekito1107 本番で確認できましたー🙆‍♂️

@sekito1107
Copy link
Contributor Author

@machida

確認ありがとうございますー!

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

Successfully merging this pull request may close these issues.

4 participants