Skip to content

Commit 5b6bec8

Browse files
Merge pull request #46 from TheDragonCode/3.x
Added support for `doctrine/dbal` and fix for Laravel 11
2 parents 6738d45 + 37b881a commit 5b6bec8

File tree

8 files changed

+40
-21
lines changed

8 files changed

+40
-21
lines changed

.github/workflows/phpunit.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@ jobs:
99
strategy:
1010
fail-fast: true
1111
matrix:
12-
php: [ "8.0", "8.1", "8.2", "8.3" ]
12+
php: [ "8.0", "8.1", "8.2", "8.3", "8.4" ]
1313
laravel: [ "8.0", "9.0", "10.0", "11.0" ]
14-
psql: [ "9", "10", "11", "12", "13", "14", "15" ]
14+
psql: [ "9", "10", "11", "12", "13", "14", "15", "16", "17" ]
1515
exclude:
1616
- laravel: "8.0"
1717
php: "8.3"
1818

19+
- laravel: "8.0"
20+
php: "8.4"
21+
1922
- laravel: "9.0"
2023
php: "8.3"
2124

25+
- laravel: "9.0"
26+
php: "8.4"
27+
2228
- laravel: "10.0"
2329
php: "8.0"
2430

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ Or manually update `require-dev` block of `composer.json` and run `composer upda
3535
| Laravel | ^8.0, ^9.0, ^10.0, ^11.0 |
3636
| Databases | MySQL 5.7+, PostgreSQL 9.5+, MSSQL |
3737

38-
| Laravel \ PostgreSQL | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
39-
|:---------------------|----|----|----|----|----|----|----|
40-
| 8 ||||||||
41-
| 9 ||||||||
42-
| 10 ||||||||
43-
| 11 | ✖️ | ✖️ | ✖️ |||||
38+
| Laravel \ PostgreSQL | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
39+
|:---------------------|----|----|----|----|----|----|----|----|----|
40+
| 8 ||||||||||
41+
| 9 ||||||||||
42+
| 10 ||||||||||
43+
| 11 | ✖️ | ✖️ | ✖️ |||||||
4444

4545

4646
## Usage

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"require": {
3838
"php": "^8.0",
3939
"ext-pdo": "*",
40-
"doctrine/dbal": "^3.0",
40+
"doctrine/dbal": "^3.0 || ^4.0",
4141
"dragon-code/contracts": "^2.15",
4242
"dragon-code/support": "^6.0",
4343
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0",

src/Console/Migrate.php

+20-7
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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)