Skip to content

Commit ca7d318

Browse files
authored
Merge pull request #219 from kitloong/feature/mariadb
Add MariaDB Driver
2 parents 1742526 + f376da2 commit ca7d318

11 files changed

+25
-17
lines changed

src/Database/Models/MySQL/MySQLColumnType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class MySQLColumnType extends DatabaseColumnType
4747
'varchar' => ColumnType::STRING,
4848
'year' => ColumnType::YEAR,
4949

50+
// For MariaDB
51+
'uuid' => ColumnType::UUID,
52+
5053
// Removed from Laravel v11
5154
'geomcollection' => ColumnType::GEOMETRY_COLLECTION,
5255
'linestring' => ColumnType::LINE_STRING,

src/Enum/Driver.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
*/
88
enum Driver: string
99
{
10-
case MYSQL = 'mysql';
11-
case PGSQL = 'pgsql';
12-
case SQLITE = 'sqlite';
13-
case SQLSRV = 'sqlsrv';
10+
case MARIADB = 'mariadb';
11+
case MYSQL = 'mysql';
12+
case PGSQL = 'pgsql';
13+
case SQLITE = 'sqlite';
14+
case SQLSRV = 'sqlsrv';
1415
}

src/MigrateGenerateCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,10 @@ protected function makeSchema(): Schema
627627
}
628628

629629
return match ($driver) {
630-
Driver::MYSQL->value => $this->schema = app(MySQLSchema::class),
631-
Driver::PGSQL->value => $this->schema = app(PgSQLSchema::class),
632-
Driver::SQLITE->value => $this->schema = app(SQLiteSchema::class),
633-
Driver::SQLSRV->value => $this->schema = app(SQLSrvSchema::class),
630+
Driver::MARIADB->value, Driver::MYSQL->value => $this->schema = app(MySQLSchema::class),
631+
Driver::PGSQL->value => $this->schema = app(PgSQLSchema::class),
632+
Driver::SQLITE->value => $this->schema = app(SQLiteSchema::class),
633+
Driver::SQLSRV->value => $this->schema = app(SQLSrvSchema::class),
634634
default => throw new Exception('The database driver in use is not supported.'),
635635
};
636636
}

src/Migration/TableMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private function makeMigrationPath(string $table): string
188188
*/
189189
private function shouldSetCharset(): bool
190190
{
191-
if (DB::getDriverName() !== Driver::MYSQL->value) {
191+
if (!in_array(DB::getDriverName(), [Driver::MARIADB->value, Driver::MYSQL->value])) {
192192
return false;
193193
}
194194

src/Support/AssetNameQuote.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function quoteIdentifier(string $value): string
3232
case Driver::SQLSRV->value:
3333
return $value === '*' ? $value : '[' . str_replace(']', ']]', $value) . ']';
3434

35+
case Driver::MARIADB->value:
3536
case Driver::MYSQL->value:
3637
return $value === '*' ? $value : '`' . str_replace('`', '``', $value) . '`';
3738

src/Support/CheckLaravelVersion.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ trait CheckLaravelVersion
88
{
99
public function atLeastLaravel11(): bool
1010
{
11-
if (App::version() === '11.x-dev') {
12-
return true;
13-
}
14-
1511
return $this->atLeastLaravelVersion('11.0');
1612
}
1713

tests/Feature/MariaDB/MariaDBTestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
use Illuminate\Support\Facades\DB;
66
use Illuminate\Support\Facades\Schema;
7+
use KitLoong\MigrationsGenerator\Support\CheckLaravelVersion;
78
use KitLoong\MigrationsGenerator\Tests\Feature\FeatureTestCase;
89
use PDO;
910

1011
abstract class MariaDBTestCase extends FeatureTestCase
1112
{
13+
use CheckLaravelVersion;
14+
1215
/**
1316
* @inheritDoc
1417
*/
@@ -18,7 +21,7 @@ protected function getEnvironmentSetUp($app): void
1821

1922
$app['config']->set('database.default', 'mariadb');
2023
$app['config']->set('database.connections.mariadb', [
21-
'driver' => 'mysql',
24+
'driver' => $this->atLeastLaravel11() ? 'mariadb' : 'mysql',
2225
'url' => null,
2326
'host' => env('MARIADB_HOST'),
2427
'port' => env('MARIADB_PORT'),

tests/resources/database/migrations/collation/2020_03_21_000000_expected_create_collations_table.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function up()
3030
case Driver::SQLSRV->value:
3131
$collation = 'Latin1_General_100_CI_AI_SC_UTF8';
3232
break;
33+
case Driver::MARIADB->value:
3334
case Driver::MYSQL->value:
3435
$collation = 'utf8_unicode_ci';
3536
break;
@@ -61,7 +62,7 @@ public function up()
6162
$table->text('text_charset')->charset('utf8');
6263
$table->text('text_collation')->collation($collation);
6364

64-
if (DB::getDriverName() === Driver::MYSQL->value) {
65+
if (in_array(DB::getDriverName(), [Driver::MARIADB->value, Driver::MYSQL->value])) {
6566
$table->set('set', ['strawberry', 'vanilla']);
6667
$table->set('set_default', ['strawberry', 'vanilla'])->default('strawberry');
6768
$table->set('set_charset', ['strawberry', 'vanilla'])->charset('utf8');

tests/resources/database/migrations/general/2020_03_21_000000_expected_create_all_columns_table.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function up()
8080
// https://github.com/laravel/framework/pull/49634
8181
if ($this->atLeastLaravel11()) {
8282
if (
83-
DB::getDriverName() !== Driver::MYSQL->value ||
83+
!in_array(DB::getDriverName(), [Driver::MARIADB->value, Driver::MYSQL->value]) ||
8484
version_compare(DB::getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), '5.8', '>')
8585
) {
8686
$table->geography('geography');
@@ -189,13 +189,15 @@ public function up()
189189
$table->ulid('ulid');
190190

191191
switch (DB::getDriverName()) {
192+
case Driver::MARIADB->value:
192193
case Driver::MYSQL->value:
193194
$table->set('set', ['strawberry', 'vanilla']);
194195
break;
195196
default:
196197
}
197198

198199
switch (DB::getDriverName()) {
200+
case Driver::MARIADB->value:
199201
case Driver::MYSQL->value:
200202
$table->string('virtual')->nullable()->virtualAs('CONCAT(string, " ", string_255)');
201203
$table->string('stored')->nullable()->storedAs("CONCAT(string_255, ' ', string)");

tests/resources/database/migrations/general/2020_03_21_000000_expected_create_test_index_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function up()
5555
}
5656
}
5757

58-
if (in_array(DB::getDriverName(), [Driver::MYSQL->value, Driver::PGSQL->value])) {
58+
if (in_array(DB::getDriverName(), [Driver::MARIADB->value, Driver::MYSQL->value, Driver::PGSQL->value])) {
5959
$table->string('fulltext')->fulltext();
6060
$table->string('fulltext_custom')->fulltext('fulltext_custom');
6161
$table->fullText(['col_multi1', 'col_multi2']);

tests/resources/database/migrations/general/2020_03_21_000001_expected_create_quoted_name_proc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
public function up()
1919
{
2020
switch (DB::getDriverName()) {
21+
case Driver::MARIADB->value:
2122
case Driver::MYSQL->value:
2223
DB::unprepared(
2324
"CREATE PROCEDURE findNameWithHyphen()

0 commit comments

Comments
 (0)