Skip to content

Commit

Permalink
fix: cannot cast as json on mariadb 10
Browse files Browse the repository at this point in the history
Fixes #4109
  • Loading branch information
luceos committed Nov 13, 2024
1 parent 3b69af2 commit 99e3050
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
$table->json('preferences_json')->nullable();
});

if ($schema->getConnection()->getDriverName() === 'mysql') {
if ($schema->getConnection()?->isMaria()) {
$schema->getConnection()->table('users')->update([
'preferences_json' => $schema->getConnection()->raw("IF(JSON_VALID(CONVERT($preferences USING utf8mb4)), CONVERT($preferences USING utf8mb4), NULL)"),
]);
} elseif ($schema->getConnection()->getDriverName() === 'mysql') {
$schema->getConnection()->table('users')->update([
'preferences_json' => $schema->getConnection()->raw("CAST(CONVERT($preferences USING utf8mb4) AS JSON)"),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
$table->json('data_json')->nullable();
});

if ($schema->getConnection()->getDriverName() === 'mysql') {
if ($schema->getConnection()?->isMaria()) {
$schema->getConnection()->table('notifications')->update([
'data_json' => $schema->getConnection()->raw("IF(JSON_VALID(CONVERT(data USING utf8mb4)), CONVERT(data USING utf8mb4), NULL)"),
]);
} elseif ($schema->getConnection()->getDriverName() === 'mysql') {
$schema->getConnection()->table('notifications')->update([
'data_json' => $schema->getConnection()->raw('CAST(CONVERT(data USING utf8mb4) AS JSON)'),
]);
Expand Down

0 comments on commit 99e3050

Please sign in to comment.