diff --git a/framework/core/migrations/2024_05_05_000001_convert_preferences_to_json_in_users.php b/framework/core/migrations/2024_05_05_000001_convert_preferences_to_json_in_users.php index 6079b0e9de..4712306f95 100644 --- a/framework/core/migrations/2024_05_05_000001_convert_preferences_to_json_in_users.php +++ b/framework/core/migrations/2024_05_05_000001_convert_preferences_to_json_in_users.php @@ -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)"), ]); diff --git a/framework/core/migrations/2024_05_07_000001_convert_data_to_json_in_notifications.php b/framework/core/migrations/2024_05_07_000001_convert_data_to_json_in_notifications.php index 82ca9e76e8..be1519730f 100644 --- a/framework/core/migrations/2024_05_07_000001_convert_data_to_json_in_notifications.php +++ b/framework/core/migrations/2024_05_07_000001_convert_data_to_json_in_notifications.php @@ -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)'), ]);