Skip to content

Commit 0360537

Browse files
Added support for doctrine/dbal and fix for Laravel 11
1 parent 8660517 commit 0360537

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"require": {
4242
"php": "^8.0",
4343
"ext-pdo": "*",
44-
"doctrine/dbal": "^3.0",
44+
"doctrine/dbal": "^3.0 || ^4.0",
4545
"dragon-code/contracts": "^2.15",
4646
"dragon-code/support": "^6.0",
4747
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0",

src/Console/Migrate.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DragonCode\MigrateDB\Facades\BuilderManager;
88
use DragonCode\Support\Facades\Helpers\Arr;
99
use Illuminate\Console\Command;
10+
use Illuminate\Database\Connection;
1011
use Illuminate\Database\Query\Builder as QueryBuilder;
1112
use Illuminate\Support\Collection;
1213
use Illuminate\Support\Facades\DB;
@@ -16,10 +17,10 @@
1617
class Migrate extends Command
1718
{
1819
protected $signature = 'db:migrate'
19-
. ' {--schema-from= : Source connection name}'
20-
. ' {--schema-to= : Target connection name}'
21-
. ' {--exclude=* : Comma separated table names to exclude}'
22-
. ' {--tables=* : Comma separated table names to migrate only}';
20+
. ' {--schema-from= : Source connection name}'
21+
. ' {--schema-to= : Target connection name}'
22+
. ' {--exclude=* : Comma separated table names to exclude}'
23+
. ' {--tables=* : Comma separated table names to migrate only}';
2324

2425
protected $description = 'Data transfer from one database to another';
2526

@@ -252,7 +253,10 @@ protected function getMigrationOption(): string
252253

253254
protected function confirmTableListOption(): bool
254255
{
255-
return $this->confirm('Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)', false);
256+
return $this->confirm(
257+
'Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)',
258+
false
259+
);
256260
}
257261

258262
protected function confirmTruncateTableOption(): bool
@@ -311,7 +315,7 @@ protected function resolveOptions(): void
311315

312316
protected function builder(string $connection, string $table): QueryBuilder
313317
{
314-
return DB::connection($connection)->table($table);
318+
return $this->connection($connection)->table($table);
315319
}
316320

317321
protected function doesntHasTable(string $connection, string $table): bool
@@ -321,6 +325,15 @@ protected function doesntHasTable(string $connection, string $table): bool
321325

322326
protected function getPrimaryKeyType(string $connection, string $table, string $column): string
323327
{
324-
return DB::connection($connection)->getDoctrineColumn($table, $column)->getType()->getName();
328+
if (method_exists($this->connection($connection), 'getDoctrineColumn')) {
329+
return $this->connection($connection)->getDoctrineColumn($table, $column)->getType()->getName();
330+
}
331+
332+
return $this->connection($connection)->getSchemaBuilder()->getColumnType($table, $column);
333+
}
334+
335+
protected function connection(string $name): Connection
336+
{
337+
return DB::connection($name);
325338
}
326339
}

src/Database/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(Connection $connection)
2424
}
2525

2626
/**
27-
* @return \Illuminate\Database\Schema\Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
27+
* @return SchemaBuilder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
2828
*/
2929
public function schema(): SchemaBuilder
3030
{

src/Database/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function get(): BuilderContract
3636
}
3737

3838
/**
39-
* @return \DragonCode\MigrateDB\Database\Builder|string
39+
* @return Builder|string
4040
*/
4141
protected function getBuilder(): string
4242
{

tests/Concerns/Connections.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ abstract protected function defaultSourceConnectionName(): string;
1818
abstract protected function defaultTargetConnectionName(): string;
1919

2020
/**
21-
* @return \Illuminate\Database\Schema\Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
21+
* @return Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
2222
*/
2323
protected function sourceConnection(): Builder
2424
{
2525
return Schema::connection($this->source_connection);
2626
}
2727

2828
/**
29-
* @return \Illuminate\Database\Schema\Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
29+
* @return Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
3030
*/
3131
protected function targetConnection(): Builder
3232
{

tests/Configurations/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function get(string $driver): BaseConfiguration
2323
}
2424

2525
/**
26-
* @param string|\Tests\Configurations\BaseConfiguration $instance
26+
* @param string|BaseConfiguration $instance
2727
*/
2828
protected function resolve(string $instance): BaseConfiguration
2929
{

0 commit comments

Comments
 (0)