Skip to content

Commit 0d01f9e

Browse files
Merge pull request #43 from TheDragonCode/3.x
Added Laravel 11 support
2 parents e96aedc + 8660517 commit 0d01f9e

File tree

12 files changed

+81
-44
lines changed

12 files changed

+81
-44
lines changed

.github/workflows/phpunit.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,32 @@ jobs:
1010
fail-fast: true
1111
matrix:
1212
php: [ "8.0", "8.1", "8.2", "8.3" ]
13-
laravel: [ "8.0", "9.0", "10.0" ]
13+
laravel: [ "8.0", "9.0", "10.0", "11.0" ]
1414
psql: [ "9", "10", "11", "12", "13", "14", "15" ]
1515
exclude:
1616
- laravel: "8.0"
1717
php: "8.3"
18+
1819
- laravel: "9.0"
1920
php: "8.3"
21+
2022
- laravel: "10.0"
2123
php: "8.0"
24+
25+
- laravel: "11.0"
26+
php: "8.0"
27+
28+
- laravel: "11.0"
29+
php: "8.1"
30+
31+
- laravel: "11.0"
32+
psql: "9"
33+
34+
- laravel: "11.0"
35+
psql: "10"
36+
37+
- laravel: "11.0"
38+
psql: "11"
2239

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

@@ -50,7 +67,7 @@ jobs:
5067
with:
5168
php-version: ${{ matrix.php }}
5269
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, pdo_mysql, pdo_pgsql
53-
coverage: none
70+
coverage: xdebug
5471

5572
- name: Install dependencies
5673
run: composer require --dev laravel/framework:^${{ matrix.laravel }}

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,17 @@ Or manually update `require-dev` block of `composer.json` and run `composer upda
3333
| Service | Versions |
3434
|:----------|:-----------------------------------|
3535
| PHP | ^8.0 |
36-
| Laravel | ^8.0, ^9.0, ^10.0 |
36+
| Laravel | ^8.0, ^9.0, ^10.0, ^11.0 |
3737
| Databases | MySQL 5.7+, PostgreSQL 9.5+, MSSQL |
3838

39+
| Laravel \ PostgreSQL | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
40+
|:---------------------|----|----|----|----|----|----|----|
41+
| 8 ||||||||
42+
| 9 ||||||||
43+
| 10 ||||||||
44+
| 11 | ✖️ | ✖️ | ✖️ |||||
45+
46+
3947
## Usage
4048

4149
Create a new database and set up both connections in the `connections` section of

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@
4444
"doctrine/dbal": "^3.0",
4545
"dragon-code/contracts": "^2.15",
4646
"dragon-code/support": "^6.0",
47-
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0",
48-
"illuminate/database": "^8.0 || ^9.0 || ^10.0",
49-
"illuminate/support": "^8.0 || ^9.0 || ^10.0"
47+
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0",
48+
"illuminate/database": "^8.0 || ^9.0 || ^10.0 || ^11.0",
49+
"illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0"
5050
},
5151
"require-dev": {
5252
"ext-pdo_mysql": "*",
5353
"ext-pdo_pgsql": "*",
5454
"mockery/mockery": "^1.0",
55-
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0",
56-
"phpunit/phpunit": "^9.6"
55+
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0",
56+
"phpunit/phpunit": "^9.6 || ^10.0"
5757
},
5858
"minimum-stability": "stable",
5959
"prefer-stable": true,

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
bootstrap="vendor/autoload.php"
88
colors="true"
99
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
10+
convertNoticesToExceptions="false"
11+
convertWarningsToExceptions="false"
1212
processIsolation="false"
1313
stopOnError="false"
1414
stopOnFailure="false"

src/Console/Migrate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class Migrate extends Command
2323

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

26-
/** @var \DragonCode\Contracts\MigrateDB\Builder */
26+
/** @var Builder */
2727
protected $source;
2828

29-
/** @var \DragonCode\Contracts\MigrateDB\Builder */
29+
/** @var Builder */
3030
protected $target;
3131

3232
/** @var array */

src/Database/Builder.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class Builder implements BuilderContract
1313
{
1414
use Makeable;
1515

16-
/** @var \Illuminate\Database\Connection */
16+
/** @var Connection */
1717
protected $connection;
1818

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

3434
public function getAllTables(): array
3535
{
36-
$tables = $this->schema()->getAllTables();
36+
$tables = method_exists($this->schema(), 'getAllTables')
37+
? $this->schema()->getAllTables()
38+
: $this->schema()->getTables();
3739

3840
$key = $this->tableNameColumn();
3941

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

7072
protected function filteredTables(array $tables, string $key): array
7173
{
72-
return array_filter($tables, static function (stdClass $table) use ($key) {
73-
return $table->{$key} !== 'migrations';
74+
return array_filter($tables, static function (array|stdClass $table) use ($key) {
75+
$name = is_array($table) ? $table['name'] : $table->{$key};
76+
77+
return $name !== 'migrations';
7478
});
7579
}
7680

7781
protected function pluckTableNames(array $tables, string $key): array
7882
{
79-
return array_map(static function ($table) use ($key) {
80-
return $table->{$key};
83+
return array_map(static function (array|stdClass $table) use ($key) {
84+
return is_array($table) ? $table['name'] : $table->{$key};
8185
}, $tables);
8286
}
8387

tests/Concerns/Database.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests\Concerns;
44

55
use DragonCode\MigrateDB\Constants\Drivers;
6+
use Illuminate\Database\Schema\Builder as SchemaBuilder;
67
use Illuminate\Support\Facades\Config;
78
use Tests\Configurations\BaseConfiguration;
89
use Tests\Configurations\Manager;
@@ -16,27 +17,27 @@ trait Database
1617
use HasUuidAndUlid;
1718
use Seeders;
1819

19-
protected $connectors = [
20+
protected array $connectors = [
2021
Drivers::MYSQL => MySqlConnection::class,
2122
Drivers::POSTGRES => PostgresConnection::class,
2223
Drivers::SQL_SERVER => SqlServerConnection::class,
2324
];
2425

25-
protected $table_foo = 'foo';
26+
protected string $table_foo = 'foo';
2627

27-
protected $table_bar = 'bar';
28+
protected string $table_bar = 'bar';
2829

29-
protected $table_baz = 'baz';
30+
protected string $table_baz = 'baz';
3031

31-
protected $table_ulid = 'ulid_table';
32+
protected string $table_ulid = 'ulid_table';
3233

33-
protected $table_uuid = 'uuid_table';
34+
protected string $table_uuid = 'uuid_table';
3435

35-
protected $choice_target = 'target';
36+
protected string $choice_target = 'target';
3637

37-
protected $choice_source = 'source';
38+
protected string $choice_source = 'source';
3839

39-
protected $choices = [
40+
protected array $choices = [
4041
'target',
4142
'source',
4243
'none',
@@ -97,4 +98,11 @@ protected function runMigrations(): void
9798
{
9899
$this->artisan('migrate', ['--database' => $this->source_connection])->run();
99100
}
101+
102+
protected function getTables(SchemaBuilder $builder): array
103+
{
104+
return method_exists($builder, 'getAllTables')
105+
? $builder->getAllTables()
106+
: $builder->getTables();
107+
}
100108
}

tests/Connectors/BaseConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class BaseConnection
1313
{
1414
use Makeable;
1515

16-
/** @var \Tests\Configurations\BaseConfiguration */
16+
/** @var BaseConfiguration */
1717
protected $configuration;
1818

1919
protected $default_database;

tests/Unit/MysqlToMysqlTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class MysqlToMysqlTest extends TestCase
1212
{
1313
public function testFillable()
1414
{
15-
$this->assertNotEmpty($this->sourceConnection()->getAllTables());
16-
$this->assertEmpty($this->targetConnection()->getAllTables());
15+
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
16+
$this->assertEmpty($this->getTables($this->targetConnection()));
1717

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

29-
$this->assertNotEmpty($this->sourceConnection()->getAllTables());
30-
$this->assertNotEmpty($this->targetConnection()->getAllTables());
29+
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
30+
$this->assertNotEmpty($this->getTables($this->targetConnection()));
3131
}
3232

3333
public function testCount()

tests/Unit/MysqlToPostgresTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class MysqlToPostgresTest extends TestCase
1212
{
1313
public function testFillable()
1414
{
15-
$this->assertNotEmpty($this->sourceConnection()->getAllTables());
16-
$this->assertEmpty($this->targetConnection()->getAllTables());
15+
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
16+
$this->assertEmpty($this->getTables($this->targetConnection()));
1717

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

29-
$this->assertNotEmpty($this->sourceConnection()->getAllTables());
30-
$this->assertNotEmpty($this->targetConnection()->getAllTables());
29+
$this->assertNotEmpty($this->getTables($this->sourceConnection()));
30+
$this->assertNotEmpty($this->getTables($this->targetConnection()));
3131
}
3232

3333
public function testCount()

0 commit comments

Comments
 (0)