Skip to content

Commit 87aecd8

Browse files
committed
add support mariadb 10.1
1 parent 6aa2cff commit 87aecd8

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

database/migrations_v1/2018_11_06_222923_create_transactions_table.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
use Bavix\Wallet\Models\Transaction;
44
use Illuminate\Database\Migrations\Migration;
5+
use Illuminate\Database\MySqlConnection;
56
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\DB;
68
use Illuminate\Support\Facades\Schema;
9+
use Illuminate\Database\Schema\ColumnDefinition;
710

811
class CreateTransactionsTable extends Migration
912
{
@@ -19,7 +22,7 @@ public function up(): void
1922
$table->enum('type', ['deposit', 'withdraw'])->index();
2023
$table->bigInteger('amount');
2124
$table->boolean('confirmed');
22-
$table->json('meta')->nullable();
25+
$this->json($table, 'meta')->nullable();
2326
$table->uuid('uuid')->unique();
2427
$table->timestamps();
2528

@@ -29,6 +32,27 @@ public function up(): void
2932
});
3033
}
3134

35+
/**
36+
* @param Blueprint $table
37+
* @param string $column
38+
* @return ColumnDefinition
39+
*/
40+
public function json(Blueprint $table, string $column): ColumnDefinition
41+
{
42+
$conn = DB::connection();
43+
if ($conn instanceof MySqlConnection) {
44+
$pdo = $conn->getPdo();
45+
try {
46+
$sql = 'SELECT JSON_EXTRACT(\'[10, 20, [30, 40]]\', \'$[1]\');';
47+
$pdo->exec($sql);
48+
} catch (\Throwable $throwable) {
49+
return $table->text($column);
50+
}
51+
}
52+
53+
return $table->json($column);
54+
}
55+
3256
/**
3357
* @return string
3458
*/

0 commit comments

Comments
 (0)