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

お住まいの地域に空文字列が保存されないようにし、データベース内の空文字列や不正な値をnullへと変換するスクリプトを実行する #7628

Open
dowdiness opened this issue Apr 3, 2024 · 7 comments
Assignees
Labels

Comments

@dowdiness
Copy link
Contributor

dowdiness commented Apr 3, 2024

概要

現在のアプリでは、ユーザーの登録情報変更においてお住まいの地域を登録しないを選んだ場合に、country_codesubdivision_codeにはnullではなく空文字列が保存されるようになっています。

これは望ましい挙動ではないため、もし選ばなかった場合にはnullが保存されるように変更したあと、データベースの空文字列や不正な値をnullへと変換するスクリプトを実行してデータベースから空文字列のデータを消去したいです。
その際にvalidationも現在の空文字列も許容出来るallow_blank: trueから空文字列を許容しないallow_nil: trueへと変えてください。

最終的に本番のデータベースではcountry_codesubdivision_codeにはnullかCountriesによって定義されているcountry codeとsubdivision codeの文字列のみが保存されていて、これらの値以外が保存されなくなればこのIssueは解決です。

関連Issue

#6096

@dowdiness dowdiness changed the title お住まいの地域を登録しないを選んだ時に お住まいの地域に空文字列が保存されないようにして、保存されている空文字列や不正な値をnullへと変換するスクリプトを実行する Apr 3, 2024
@dowdiness dowdiness changed the title お住まいの地域に空文字列が保存されないようにして、保存されている空文字列や不正な値をnullへと変換するスクリプトを実行する お住まいの地域に空文字列が保存されないようにし、データベース内の空文字列や不正な値をnullへと変換するスクリプトを実行する Apr 3, 2024
Copy link

github-actions bot commented Jun 3, 2024

このissue|PRは60日間更新がないため7日後にcloseします。closeしたくない場合はstaleラベルを外してください。

@github-actions github-actions bot added the stale label Jun 3, 2024
@komagata komagata removed the stale label Jun 7, 2024
Copy link

github-actions bot commented Aug 6, 2024

このissue|PRは60日間更新がないため7日後にcloseします。closeしたくない場合はstaleラベルを外してください。

@github-actions github-actions bot added the stale label Aug 6, 2024
@komagata komagata removed the stale label Aug 7, 2024
@komagata komagata moved this to いつかやる in bootcamp Aug 21, 2024
Copy link

github-actions bot commented Oct 7, 2024

このissue|PRは60日間更新がないため7日後にcloseします。closeしたくない場合はstaleラベルを外してください。

@github-actions github-actions bot added the stale label Oct 7, 2024
@komagata komagata removed the stale label Oct 7, 2024
Copy link

github-actions bot commented Dec 7, 2024

このissue|PRは60日間更新がないため7日後にcloseします。closeしたくない場合はstaleラベルを外してください。

@github-actions github-actions bot added the stale label Dec 7, 2024
@machida machida removed the stale label Dec 11, 2024
Copy link

このissue|PRは60日間更新がないため7日後にcloseします。closeしたくない場合はstaleラベルを外してください。

@github-actions github-actions bot added the stale label Feb 10, 2025
@komagata komagata removed the stale label Feb 13, 2025
@machida machida moved this from やる to 今のイテレーション in bootcamp Mar 11, 2025
@machida
Copy link
Member

machida commented Mar 11, 2025

@SuzukiShuntarou @komagata

お住まいの地域登録機能をReactからRailsのviewに移行しました。
このIssueはReactで実装してすぐに立てられたものです。

このIssueを読む限りReactの時点では空文字列や不正な値が入っていたようです。

ReactからRailsのviewに移行後〜現在はデータベース内の空文字列や不正な値が入ってしまう問題が解決されたかは要調査が必要です。もし、現在でもその問題が残っている場合は、Issueにある通り、

validationも現在の空文字列も許容出来るallow_blank: trueから空文字列を許容しないallow_nil: trueへと変えてください。

この作業をお願いします。

現在の登録されているデータに関しても調査が必要ですが、Reactだった頃に入ってしまっていた空文字列や不正な値を修正したというコミットは見つからないので、空文字列や不正な値をnullへと変換するスクリプトを実行する必要はありそうです。

...という訳で、本番データを見たりなどが必要なので、@SuzukiShuntarou さんは @komagata さんと連携を取りながら進めていただけたらと思います。

@SuzukiShuntarou
Copy link
Contributor

SuzukiShuntarou commented Mar 12, 2025

discordの質問時間に確認した内容をメモとして記載。

データベース

  • country_code だけ選択し subdivision_code を選択しないことも可能とする
    Image
    Image

  • country_code を選択しない場合、または『登録しない』を選んだ場合は subdivision_code は選択できないようになっている。
    Image
    Image

本番環境におけるデータベースの更新

  • 空文字列 ""で登録されている country_codesubdivision_codenilへ置き換える。gemdata_migrateで実施する。

ビュー

  • ビュー側では空文字列を送信し、モデル側で空文字列をnilへ置き換える。
  • app/views/users/form/_register_address.html.slim
    • include_blankで空文字列を設定
  .form-item(class="#{'is-hidden' if user.country_code.blank?}" id="country-form" data-countries="#{all_countries_with_subdivisions}")
    = f.label :country_code, class: 'a-form-label'
    .a-button.is-md.is-secondary.is-select.is-block
      = f.country_select :country_code, { include_blank: '国を選択してください' }, { id: 'country-select' }
  .form-item(class="#{'is-hidden' if user.country_code.blank?}" id= "subdivision-form")
    = f.label :subdivision_code, class: 'a-form-label'
    .a-button.is-md.is-secondary.is-select.is-block
      = f.select :subdivision_code, user.subdivisions_of_country || [], { include_blank: '選択してください' }, { id: 'subdivision-select' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 作業中
Development

No branches or pull requests

4 participants