Skip to content

Commit

Permalink
Merge pull request #43 from TheDragonCode/3.x
Browse files Browse the repository at this point in the history
Added Laravel 11 support
  • Loading branch information
andrey-helldar committed Mar 15, 2024
2 parents e96aedc + 8660517 commit 0d01f9e
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 44 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,32 @@ jobs:
fail-fast: true
matrix:
php: [ "8.0", "8.1", "8.2", "8.3" ]
laravel: [ "8.0", "9.0", "10.0" ]
laravel: [ "8.0", "9.0", "10.0", "11.0" ]
psql: [ "9", "10", "11", "12", "13", "14", "15" ]
exclude:
- laravel: "8.0"
php: "8.3"

- laravel: "9.0"
php: "8.3"

- laravel: "10.0"
php: "8.0"

- laravel: "11.0"
php: "8.0"

- laravel: "11.0"
php: "8.1"

- laravel: "11.0"
psql: "9"

- laravel: "11.0"
psql: "10"

- laravel: "11.0"
psql: "11"

name: php ${{ matrix.php }}, lr ${{ matrix.laravel }}, pg ${{ matrix.psql }}

Expand Down Expand Up @@ -50,7 +67,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, pdo_mysql, pdo_pgsql
coverage: none
coverage: xdebug

- name: Install dependencies
run: composer require --dev laravel/framework:^${{ matrix.laravel }}
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@ Or manually update `require-dev` block of `composer.json` and run `composer upda
| Service | Versions |
|:----------|:-----------------------------------|
| PHP | ^8.0 |
| Laravel | ^8.0, ^9.0, ^10.0 |
| Laravel | ^8.0, ^9.0, ^10.0, ^11.0 |
| Databases | MySQL 5.7+, PostgreSQL 9.5+, MSSQL |

| Laravel \ PostgreSQL | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|:---------------------|----|----|----|----|----|----|----|
| 8 ||||||||
| 9 ||||||||
| 10 ||||||||
| 11 | ✖️ | ✖️ | ✖️ |||||


## Usage

Create a new database and set up both connections in the `connections` section of
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@
"doctrine/dbal": "^3.0",
"dragon-code/contracts": "^2.15",
"dragon-code/support": "^6.0",
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0",
"illuminate/database": "^8.0 || ^9.0 || ^10.0",
"illuminate/support": "^8.0 || ^9.0 || ^10.0"
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0",
"illuminate/database": "^8.0 || ^9.0 || ^10.0 || ^11.0",
"illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0"
},
"require-dev": {
"ext-pdo_mysql": "*",
"ext-pdo_pgsql": "*",
"mockery/mockery": "^1.0",
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0",
"phpunit/phpunit": "^9.6"
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^9.6 || ^10.0"
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="false"
convertWarningsToExceptions="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Migrate extends Command

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

/** @var \DragonCode\Contracts\MigrateDB\Builder */
/** @var Builder */
protected $source;

/** @var \DragonCode\Contracts\MigrateDB\Builder */
/** @var Builder */
protected $target;

/** @var array */
Expand Down
16 changes: 10 additions & 6 deletions src/Database/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class Builder implements BuilderContract
{
use Makeable;

/** @var \Illuminate\Database\Connection */
/** @var Connection */
protected $connection;

abstract protected function tableNameColumn(): string;
Expand All @@ -33,7 +33,9 @@ public function schema(): SchemaBuilder

public function getAllTables(): array
{
$tables = $this->schema()->getAllTables();
$tables = method_exists($this->schema(), 'getAllTables')
? $this->schema()->getAllTables()
: $this->schema()->getTables();

$key = $this->tableNameColumn();

Expand Down Expand Up @@ -69,15 +71,17 @@ protected function columns(string $table): array

protected function filteredTables(array $tables, string $key): array
{
return array_filter($tables, static function (stdClass $table) use ($key) {
return $table->{$key} !== 'migrations';
return array_filter($tables, static function (array|stdClass $table) use ($key) {
$name = is_array($table) ? $table['name'] : $table->{$key};

return $name !== 'migrations';
});
}

protected function pluckTableNames(array $tables, string $key): array
{
return array_map(static function ($table) use ($key) {
return $table->{$key};
return array_map(static function (array|stdClass $table) use ($key) {
return is_array($table) ? $table['name'] : $table->{$key};
}, $tables);
}

Expand Down
26 changes: 17 additions & 9 deletions tests/Concerns/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Concerns;

use DragonCode\MigrateDB\Constants\Drivers;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
use Illuminate\Support\Facades\Config;
use Tests\Configurations\BaseConfiguration;
use Tests\Configurations\Manager;
Expand All @@ -16,27 +17,27 @@ trait Database
use HasUuidAndUlid;
use Seeders;

protected $connectors = [
protected array $connectors = [
Drivers::MYSQL => MySqlConnection::class,
Drivers::POSTGRES => PostgresConnection::class,
Drivers::SQL_SERVER => SqlServerConnection::class,
];

protected $table_foo = 'foo';
protected string $table_foo = 'foo';

protected $table_bar = 'bar';
protected string $table_bar = 'bar';

protected $table_baz = 'baz';
protected string $table_baz = 'baz';

protected $table_ulid = 'ulid_table';
protected string $table_ulid = 'ulid_table';

protected $table_uuid = 'uuid_table';
protected string $table_uuid = 'uuid_table';

protected $choice_target = 'target';
protected string $choice_target = 'target';

protected $choice_source = 'source';
protected string $choice_source = 'source';

protected $choices = [
protected array $choices = [
'target',
'source',
'none',
Expand Down Expand Up @@ -97,4 +98,11 @@ protected function runMigrations(): void
{
$this->artisan('migrate', ['--database' => $this->source_connection])->run();
}

protected function getTables(SchemaBuilder $builder): array
{
return method_exists($builder, 'getAllTables')
? $builder->getAllTables()
: $builder->getTables();
}
}
2 changes: 1 addition & 1 deletion tests/Connectors/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class BaseConnection
{
use Makeable;

/** @var \Tests\Configurations\BaseConfiguration */
/** @var BaseConfiguration */
protected $configuration;

protected $default_database;
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/MysqlToMysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class MysqlToMysqlTest extends TestCase
{
public function testFillable()
{
$this->assertNotEmpty($this->sourceConnection()->getAllTables());
$this->assertEmpty($this->targetConnection()->getAllTables());
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
$this->assertEmpty($this->getTables($this->targetConnection()));

$this->artisan('db:migrate', [
'--schema-from' => $this->source_connection,
Expand All @@ -26,8 +26,8 @@ public function testFillable()
->assertExitCode(0)
->run();

$this->assertNotEmpty($this->sourceConnection()->getAllTables());
$this->assertNotEmpty($this->targetConnection()->getAllTables());
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
$this->assertNotEmpty($this->getTables($this->targetConnection()));
}

public function testCount()
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/MysqlToPostgresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class MysqlToPostgresTest extends TestCase
{
public function testFillable()
{
$this->assertNotEmpty($this->sourceConnection()->getAllTables());
$this->assertEmpty($this->targetConnection()->getAllTables());
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
$this->assertEmpty($this->getTables($this->targetConnection()));

$this->artisan('db:migrate', [
'--schema-from' => $this->source_connection,
Expand All @@ -26,8 +26,8 @@ public function testFillable()
->assertExitCode(0)
->run();

$this->assertNotEmpty($this->sourceConnection()->getAllTables());
$this->assertNotEmpty($this->targetConnection()->getAllTables());
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
$this->assertNotEmpty($this->getTables($this->targetConnection()));
}

public function testCount()
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/PostgresToMysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class PostgresToMysqlTest extends TestCase
{
public function testFillable()
{
$this->assertNotEmpty($this->sourceConnection()->getAllTables());
$this->assertEmpty($this->targetConnection()->getAllTables());
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
$this->assertEmpty($this->getTables($this->targetConnection()));

$this->artisan('db:migrate', [
'--schema-from' => $this->source_connection,
Expand All @@ -26,8 +26,8 @@ public function testFillable()
->assertExitCode(0)
->run();

$this->assertNotEmpty($this->sourceConnection()->getAllTables());
$this->assertNotEmpty($this->targetConnection()->getAllTables());
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
$this->assertNotEmpty($this->getTables($this->targetConnection()));
}

public function testCount()
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/PostgresToPostgresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class PostgresToPostgresTest extends TestCase
{
public function testFillable()
{
$this->assertNotEmpty($this->sourceConnection()->getAllTables());
$this->assertEmpty($this->targetConnection()->getAllTables());
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
$this->assertEmpty($this->getTables($this->targetConnection()));

$this->artisan('db:migrate', [
'--schema-from' => $this->source_connection,
Expand All @@ -26,8 +26,8 @@ public function testFillable()
->assertExitCode(0)
->run();

$this->assertNotEmpty($this->sourceConnection()->getAllTables());
$this->assertNotEmpty($this->targetConnection()->getAllTables());
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
$this->assertNotEmpty($this->getTables($this->targetConnection()));
}

public function testCount()
Expand Down

0 comments on commit 0d01f9e

Please sign in to comment.