Skip to content

Commit

Permalink
Added support for doctrine/dbal and fix for Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Jan 28, 2025
1 parent 8660517 commit 0360537
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"require": {
"php": "^8.0",
"ext-pdo": "*",
"doctrine/dbal": "^3.0",
"doctrine/dbal": "^3.0 || ^4.0",
"dragon-code/contracts": "^2.15",
"dragon-code/support": "^6.0",
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0",
Expand Down
27 changes: 20 additions & 7 deletions src/Console/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DragonCode\MigrateDB\Facades\BuilderManager;
use DragonCode\Support\Facades\Helpers\Arr;
use Illuminate\Console\Command;
use Illuminate\Database\Connection;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
Expand All @@ -16,10 +17,10 @@
class Migrate extends Command
{
protected $signature = 'db:migrate'
. ' {--schema-from= : Source connection name}'
. ' {--schema-to= : Target connection name}'
. ' {--exclude=* : Comma separated table names to exclude}'
. ' {--tables=* : Comma separated table names to migrate only}';
. ' {--schema-from= : Source connection name}'
. ' {--schema-to= : Target connection name}'
. ' {--exclude=* : Comma separated table names to exclude}'
. ' {--tables=* : Comma separated table names to migrate only}';

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

Expand Down Expand Up @@ -252,7 +253,10 @@ protected function getMigrationOption(): string

protected function confirmTableListOption(): bool
{
return $this->confirm('Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)', false);
return $this->confirm(
'Please confirm table list should be retrieved from target connection? (incase if source connection does not support it)',
false
);
}

protected function confirmTruncateTableOption(): bool
Expand Down Expand Up @@ -311,7 +315,7 @@ protected function resolveOptions(): void

protected function builder(string $connection, string $table): QueryBuilder
{
return DB::connection($connection)->table($table);
return $this->connection($connection)->table($table);
}

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

protected function getPrimaryKeyType(string $connection, string $table, string $column): string
{
return DB::connection($connection)->getDoctrineColumn($table, $column)->getType()->getName();
if (method_exists($this->connection($connection), 'getDoctrineColumn')) {
return $this->connection($connection)->getDoctrineColumn($table, $column)->getType()->getName();
}

return $this->connection($connection)->getSchemaBuilder()->getColumnType($table, $column);
}

protected function connection(string $name): Connection
{
return DB::connection($name);
}
}
2 changes: 1 addition & 1 deletion src/Database/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(Connection $connection)
}

/**
* @return \Illuminate\Database\Schema\Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
* @return SchemaBuilder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
*/
public function schema(): SchemaBuilder
{
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function get(): BuilderContract
}

/**
* @return \DragonCode\MigrateDB\Database\Builder|string
* @return Builder|string
*/
protected function getBuilder(): string
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Concerns/Connections.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ abstract protected function defaultSourceConnectionName(): string;
abstract protected function defaultTargetConnectionName(): string;

/**
* @return \Illuminate\Database\Schema\Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
* @return Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
*/
protected function sourceConnection(): Builder
{
return Schema::connection($this->source_connection);
}

/**
* @return \Illuminate\Database\Schema\Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
* @return Builder|\Illuminate\Database\Schema\MySqlBuilder|\Illuminate\Database\Schema\PostgresBuilder
*/
protected function targetConnection(): Builder
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Configurations/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function get(string $driver): BaseConfiguration
}

/**
* @param string|\Tests\Configurations\BaseConfiguration $instance
* @param string|BaseConfiguration $instance
*/
protected function resolve(string $instance): BaseConfiguration
{
Expand Down

0 comments on commit 0360537

Please sign in to comment.