From 4d46b20c7a28b79ef3a66250a5a82004df3109f9 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 13 Mar 2024 11:02:19 +0300 Subject: [PATCH 1/7] Added Laravel 11 support --- .github/workflows/phpunit.yml | 10 +++++++++- composer.json | 10 +++++----- phpunit.xml | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index e820f11..b85e536 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -10,15 +10,23 @@ 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" name: php ${{ matrix.php }}, lr ${{ matrix.laravel }}, pg ${{ matrix.psql }} diff --git a/composer.json b/composer.json index 0c2e590..71562f4 100644 --- a/composer.json +++ b/composer.json @@ -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, diff --git a/phpunit.xml b/phpunit.xml index b89079c..6317452 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -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" From d0599da89f2f39069112ca81594a41fbfd1d92c0 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 13 Mar 2024 11:06:06 +0300 Subject: [PATCH 2/7] Enabled xdebug --- .github/workflows/phpunit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index b85e536..0c9f33d 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -58,7 +58,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 }} From f48a95781eff07bd1d81a4d6b9bdc2625c5468f9 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 13 Mar 2024 11:08:01 +0300 Subject: [PATCH 3/7] Fixed code-style --- src/Console/Migrate.php | 4 ++-- src/Database/Builder.php | 2 +- tests/Connectors/BaseConnection.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index 9d489f5..8d8da7c 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -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 */ diff --git a/src/Database/Builder.php b/src/Database/Builder.php index 3e94c32..6b07586 100644 --- a/src/Database/Builder.php +++ b/src/Database/Builder.php @@ -13,7 +13,7 @@ abstract class Builder implements BuilderContract { use Makeable; - /** @var \Illuminate\Database\Connection */ + /** @var Connection */ protected $connection; abstract protected function tableNameColumn(): string; diff --git a/tests/Connectors/BaseConnection.php b/tests/Connectors/BaseConnection.php index 88fe862..c6862dd 100644 --- a/tests/Connectors/BaseConnection.php +++ b/tests/Connectors/BaseConnection.php @@ -13,7 +13,7 @@ abstract class BaseConnection { use Makeable; - /** @var \Tests\Configurations\BaseConfiguration */ + /** @var BaseConfiguration */ protected $configuration; protected $default_database; From f984511ff728ced4e9b0de5bd6ce03ec591c57aa Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 15 Mar 2024 02:28:15 +0300 Subject: [PATCH 4/7] Fixed deprecated methods in the Laravel 11 --- src/Database/Builder.php | 4 +++- tests/Concerns/Database.php | 26 +++++++++++++++++--------- tests/Unit/MysqlToMysqlTest.php | 8 ++++---- tests/Unit/MysqlToPostgresTest.php | 8 ++++---- tests/Unit/PostgresToMysqlTest.php | 8 ++++---- tests/Unit/PostgresToPostgresTest.php | 8 ++++---- 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/Database/Builder.php b/src/Database/Builder.php index 6b07586..19b27ff 100644 --- a/src/Database/Builder.php +++ b/src/Database/Builder.php @@ -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(); diff --git a/tests/Concerns/Database.php b/tests/Concerns/Database.php index 3966501..af49361 100644 --- a/tests/Concerns/Database.php +++ b/tests/Concerns/Database.php @@ -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; @@ -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', @@ -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(); + } } diff --git a/tests/Unit/MysqlToMysqlTest.php b/tests/Unit/MysqlToMysqlTest.php index a750779..376e03d 100644 --- a/tests/Unit/MysqlToMysqlTest.php +++ b/tests/Unit/MysqlToMysqlTest.php @@ -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, @@ -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() diff --git a/tests/Unit/MysqlToPostgresTest.php b/tests/Unit/MysqlToPostgresTest.php index 094ef7d..69db540 100644 --- a/tests/Unit/MysqlToPostgresTest.php +++ b/tests/Unit/MysqlToPostgresTest.php @@ -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, @@ -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() diff --git a/tests/Unit/PostgresToMysqlTest.php b/tests/Unit/PostgresToMysqlTest.php index e5809c9..bcb2faf 100644 --- a/tests/Unit/PostgresToMysqlTest.php +++ b/tests/Unit/PostgresToMysqlTest.php @@ -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, @@ -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() diff --git a/tests/Unit/PostgresToPostgresTest.php b/tests/Unit/PostgresToPostgresTest.php index 8ec81ba..1a659f4 100644 --- a/tests/Unit/PostgresToPostgresTest.php +++ b/tests/Unit/PostgresToPostgresTest.php @@ -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, @@ -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() From 3c67736193ef9d84e6001c96c3c9dd65c0c73bd0 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 15 Mar 2024 02:33:48 +0300 Subject: [PATCH 5/7] Fixed code-style --- tests/Concerns/Database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Concerns/Database.php b/tests/Concerns/Database.php index af49361..805dbbc 100644 --- a/tests/Concerns/Database.php +++ b/tests/Concerns/Database.php @@ -98,7 +98,7 @@ protected function runMigrations(): void { $this->artisan('migrate', ['--database' => $this->source_connection])->run(); } - + protected function getTables(SchemaBuilder $builder): array { return method_exists($builder, 'getAllTables') From a8d661a0742c981141a71501281c6f1fed897bd8 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 15 Mar 2024 02:38:04 +0300 Subject: [PATCH 6/7] Fixed TypeError Argument #1 ($table) must be of type stdClass, array given --- src/Database/Builder.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Database/Builder.php b/src/Database/Builder.php index 19b27ff..e89f0a7 100644 --- a/src/Database/Builder.php +++ b/src/Database/Builder.php @@ -71,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); } From 86605179bf8892d5f61772965f0a326ff17e2032 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 15 Mar 2024 02:55:05 +0300 Subject: [PATCH 7/7] Updated compatibility --- .github/workflows/phpunit.yml | 9 +++++++++ README.md | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 0c9f33d..30bd8be 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -27,6 +27,15 @@ jobs: - 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 }} diff --git a/README.md b/README.md index 8ad83bb..2c296f9 100644 --- a/README.md +++ b/README.md @@ -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