[fix] MariaDB環境でFULLTEXTインデックスが作成されないバグを修正#2391
Open
dreamer9999 wants to merge 3 commits intoopensource-workshop:masterfrom
Open
[fix] MariaDB環境でFULLTEXTインデックスが作成されないバグを修正#2391dreamer9999 wants to merge 3 commits intoopensource-workshop:masterfrom
dreamer9999 wants to merge 3 commits intoopensource-workshop:masterfrom
Conversation
fix: MariaDBバージョン文字列のパースバグ修正
masaton0216
requested changes
Mar 25, 2026
Contributor
masaton0216
left a comment
There was a problem hiding this comment.
ご対応ありがとうございます。
2点コメントしたのでご確認ください。
Comment on lines
+36
to
+41
| preg_match('/^(\d+)\.(\d+)\.(\d+)/', $version, $matches); | ||
| $major = isset($matches[1]) ? (int)$matches[1] : 0; | ||
| $minor = isset($matches[2]) ? (int)$matches[2] : 0; | ||
|
|
||
| // MariaDBは5.6以上でFULLTEXT対応 | ||
| if ($version_arr[0] >= 5 && $version_arr[1] >= 6) { | ||
| if ($major > 5 || ($major === 5 && $minor >= 6)) { |
Contributor
There was a problem hiding this comment.
1. preg_matchの失敗ケースのハンドリング
preg_matchがマッチしなかった場合、$major=0, $minor=0 となりFULLTEXTインデックスが作成されません。
strpos($version, 'Maria') !== false を通過しているにもかかわらずバージョン番号がパースできないケースは異常であるため、ログ出力やWarningを出した方がデバッグしやすいかと思います。
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| class AddFullTextSearchToDatabases extends Migration |
Contributor
There was a problem hiding this comment.
問題点
Laravelは migrations テーブルに実行済みのマイグレーションファイル名を記録し、一度実行されたマイグレーションは php artisan migrateを再実行してもスキップされます。
つまり、この2023年9月のマイグレーションファイルを修正してもケースに応じて下記の状態になります。
- 既存環境: すでに実行済みなので、修正後のコードは永遠に実行されない (500エラーは解消されない)
- 新規環境: 新規に migrate を実行する場合のみ修正が反映される
対策
新しいマイグレーションファイルを作成し「Maria、且つ、インデックスが存在しなければ作成する」という設計とするのが望ましいと思われます。
Author
|
ご指摘ありがとうございます。
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: MariaDBバージョン文字列のパースバグ修正
概要
MariaDBのバージョン文字列に
-logなどのサフィックスが付く環境(例:10.5.19-MariaDB-log)で、databases_inputsテーブルへのFULLTEXTインデックス作成がスキップされ、データベースプラグインのキーワード検索で500エラーが発生する問題を修正。
※作業中、500エラーが出たので、claude.ai に原因を調べてもらい、対応プログラムを作ってもらい、プルリクエストさせていただきました。はじめてのプルリクエストで、何かご迷惑をおかけしてまっているようでしたらお詫び申し上げます。
レビュー完了希望日
なし
関連Pull requests/Issues
なし
参考
str_replace('-MariaDB', '', $version)だけでは-logが残り、explode後の$version_arr[1]が"19-log"となり>= 6の比較が正しく動作しない。preg_matchで数字部分のみを抽出しintにキャストして比較するよう変更。DB変更の有無
なし
チェックリスト
修正内容の追記(レビュー対応)
概要
2023_09_04_153112_add_full_text_search_to_databases.phpにおいて、MariaDBのバージョン文字列に-log等のサフィックスが付く環境(例:10.5.19-MariaDB-log)では、バージョン判定が正しく動作せずdatabases_inputsテーブルへの FULLTEXTインデックス作成がスキップされていた。その結果、データベースプラグインのキーワード検索で500エラーが発生する。本PRでは既存環境にも対応するため、新規マイグレーションファイルを追加して修正する。
バグの原因
元のコードでは以下の処理でバージョン文字列を加工していた。
10.5.19-MariaDB-logに対してstr_replace('-MariaDB', '')を適用すると10.5.19-logが残る。これを
explode('.')すると$version_arr[1]が"19-log"となり、>= 6の比較が正しく動作しない。修正内容
新規マイグレーションファイル
2026_03_25_000000_fix_mariadb_fulltext_index_on_databases_inputs.phpを追加。preg_matchでバージョン文字列の数字部分のみを抽出しintにキャストして比較することでサフィックスの影響を排除preg_matchが失敗した場合(異常ケース)はLog::warningを出力してスキップ既存環境への対応について
Laravelは一度実行したマイグレーションを
migrationsテーブルに記録し、php artisan migrateを再実行してもスキップする。そのため元ファイルの修正だけでは既存環境には反映されない。本PRでは新規マイグレーションとして追加することで既存環境にも対応する。レビュー完了希望日
なし
関連Pull requests/Issues
なし
DB変更の有無
有り(
databases_inputsテーブルに FULLTEXTインデックスを追加)チェックリスト