Skip to content
This repository was archived by the owner on Feb 16, 2022. It is now read-only.

Commit 912fb04

Browse files
committed
Fix MySQL / PostgreSQL json column compatibility
1 parent f8178b0 commit 912fb04

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

database/migrations/2017_06_27_143745_create_bookable_bookings_table.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ public function down(): void
5353
*/
5454
protected function jsonable(): string
5555
{
56-
return DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME) === 'mysql'
57-
&& version_compare(DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), '5.7.8', 'ge')
58-
? 'json' : 'text';
56+
$driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
57+
$dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
58+
$isOldVersion = version_compare($dbVersion, '5.7.8', 'lt');
59+
60+
return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json';
5961
}
6062
}

database/migrations/2018_04_04_154842_create_ticketable_tickets_table.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ public function down()
4949
*/
5050
protected function jsonable(): string
5151
{
52-
return DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME) === 'mysql'
53-
&& version_compare(DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), '5.7.8', 'ge')
54-
? 'json' : 'text';
52+
$driverName = DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
53+
$dbVersion = DB::connection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
54+
$isOldVersion = version_compare($dbVersion, '5.7.8', 'lt');
55+
56+
return $driverName === 'mysql' && $isOldVersion ? 'text' : 'json';
5557
}
5658
}

0 commit comments

Comments
 (0)