Skip to content

Commit 542c416

Browse files
authored
Merge pull request #256 from kitloong/feature/laravel-12
Support Laravel 12
2 parents c0ec3ec + 8cd09d4 commit 542c416

40 files changed

+151
-298
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- name: Install dependencies
2727
run: |
28-
composer require "laravel/framework:^11.0" --no-interaction --no-update
28+
composer require "laravel/framework:^12.0" --no-interaction --no-update
2929
composer update --prefer-stable --prefer-dist --no-interaction --no-progress
3030
3131
- name: phpcs

.github/workflows/tests.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,7 @@ jobs:
7878
strategy:
7979
matrix:
8080
php: [ 8.2, 8.3, 8.4 ]
81-
laravel: [ 11.* ]
82-
sqlsrv_extension: [ pdo_sqlsrv ]
83-
include:
84-
- php: 8.1
85-
laravel: 10.43.*
86-
- php: 8.1
87-
laravel: 10.*
81+
laravel: [ 11.*, 12.* ]
8882

8983
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
9084

@@ -107,7 +101,7 @@ jobs:
107101
uses: shivammathur/setup-php@v2
108102
with:
109103
php-version: ${{ matrix.php }}
110-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, memcached, ${{matrix.sqlsrv_extension}}
104+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, memcached, pdo_sqlsrv
111105
tools: composer:v2
112106
coverage: pcov
113107

README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@ Laravel Migrations Generator supports all five Laravel first-party support datab
2121
- [x] SQL Server
2222
- [x] SQLite
2323

24-
## Version Compatibility
25-
26-
| Laravel | Version |
27-
|--------------------|-------------------------------------------------|
28-
| 11.x | 7.x |
29-
| \>= 10.43.x | 7.x |
30-
| 10.x \| <= 10.42.x | 6.x |
31-
| 9.x | 6.x |
32-
| 8.x | 6.x |
33-
| 7.x | 6.x |
34-
| 6.x | 6.x |
35-
| 5.8.x | 6.x |
36-
| 5.7.x | 6.x |
37-
| 5.6.x | 6.x |
38-
| <= 5.5.x | https://github.com/Xethron/migrations-generator |
39-
4024
## Install
4125

4226
The recommended way to install this is through composer:

composer.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://getcomposer.org/schema.json",
23
"name": "kitloong/laravel-migrations-generator",
34
"description": "Generates Laravel Migrations from an existing database",
45
"keywords": [
@@ -17,19 +18,20 @@
1718
}
1819
],
1920
"require": {
20-
"php": "^8.1",
21-
"illuminate/support": "^10.43|^11.0",
21+
"php": "^8.2",
22+
"illuminate/support": "^11.0|^12.0",
2223
"ext-pdo": "*"
2324
},
2425
"require-dev": {
25-
"orchestra/testbench": "^8.0|^9.0",
26-
"squizlabs/php_codesniffer": "^3.5",
27-
"mockery/mockery": "^1.0",
26+
"barryvdh/laravel-ide-helper": "^3.0",
2827
"friendsofphp/php-cs-fixer": "^3.1",
29-
"larastan/larastan": "^1.0|^2.0",
30-
"slevomat/coding-standard": "^8.0",
28+
"larastan/larastan": "^2.0|^3.0",
29+
"mockery/mockery": "^1.0",
30+
"orchestra/testbench": "^9.0|^10.0",
3131
"phpmd/phpmd": "^2.10",
32-
"barryvdh/laravel-ide-helper": "^2.0|^3.0"
32+
"phpstan/phpstan-mockery": "^2.0",
33+
"slevomat/coding-standard": "^8.0",
34+
"squizlabs/php_codesniffer": "^3.5"
3335
},
3436
"autoload": {
3537
"psr-4": {
@@ -65,6 +67,7 @@
6567
]
6668
},
6769
"config": {
70+
"sort-packages": true,
6871
"allow-plugins": {
6972
"dealerdirect/phpcodesniffer-composer-installer": true
7073
}

phpstan.neon

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
includes:
22
- ./vendor/larastan/larastan/extension.neon
3+
- ./vendor/phpstan/phpstan-mockery/extension.neon
34

45
parameters:
56

@@ -10,15 +11,8 @@ parameters:
1011
# The level 9 is the highest level
1112
level: 8
1213

13-
ignoreErrors:
14-
- '#Method KitLoong\\MigrationsGenerator\\Database\\(.*)Schema::getViews\(\) should return Illuminate\\Support\\Collection<int, KitLoong\\MigrationsGenerator\\Schema\\Models\\View> but returns Illuminate\\Support\\Collection<(int|\(int\|string\)), KitLoong\\MigrationsGenerator\\Database\\Models\\(.*)\\(.*)View>.#'
15-
- '#Method KitLoong\\MigrationsGenerator\\Database\\(.*)Schema::getProcedures\(\) should return Illuminate\\Support\\Collection<int, KitLoong\\MigrationsGenerator\\Schema\\Models\\Procedure> but returns Illuminate\\Support\\Collection<(int|\(int\|string\)), KitLoong\\MigrationsGenerator\\Database\\Models\\(.*)\\(.*)Procedure>.#'
16-
- '#Method KitLoong\\MigrationsGenerator\\Database\\(.*)Schema::getForeignKeys\(\) should return Illuminate\\Support\\Collection<int, KitLoong\\MigrationsGenerator\\Schema\\Models\\ForeignKey> but returns Illuminate\\Support\\Collection<(int|\(int\|string\)), KitLoong\\MigrationsGenerator\\Database\\Models\\(.*)\\(.*)ForeignKey>.#'
17-
- '#(.*)expects Illuminate\\Support\\Collection<int, KitLoong\\MigrationsGenerator\\Migration\\Blueprint\\WritableBlueprint>, Illuminate\\Support\\Collection<int, KitLoong\\MigrationsGenerator\\Migration\\Blueprint\\(.*)Blueprint> given.#'
18-
- '#Call to an undefined method Mockery\\ExpectationInterface\|Mockery\\HigherOrderMessage::(.*)#'
19-
- '#Cannot call method expectsQuestion\(\) on Illuminate\\Testing\\PendingCommand\|int\.#'
14+
# `env` calls from `tests` directory are allowed
15+
noEnvCallsOutsideOfConfig: false
2016

2117
excludePaths:
2218
- ./tests/resources/**
23-
24-
checkMissingIterableValueType: true

src/Database/DatabaseSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ abstract class DatabaseSchema implements Schema
6666
*/
6767
public function getTableNames(): Collection
6868
{
69-
return new Collection(SchemaFacade::getTableListing());
69+
return new Collection(array_column(SchemaFacade::getTables(), 'name'));
7070
}
7171

7272
/**

src/Database/Models/Blueprint.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace KitLoong\MigrationsGenerator\Database\Models;
4+
5+
use Illuminate\Database\Schema\Blueprint as BaseBlueprint;
6+
use Illuminate\Support\Facades\Schema;
7+
use KitLoong\MigrationsGenerator\Support\CheckLaravelVersion;
8+
9+
class Blueprint extends BaseBlueprint
10+
{
11+
use CheckLaravelVersion;
12+
13+
public function __construct(string $table)
14+
{
15+
if ($this->atLeastLaravel12()) {
16+
parent::__construct(Schema::getConnection(), $table);
17+
18+
return;
19+
}
20+
21+
parent::__construct($table); // @phpstan-ignore-line
22+
}
23+
24+
/**
25+
* @return string[]
26+
*/
27+
public function toSqlWithCompatible(): array
28+
{
29+
if ($this->atLeastLaravel12()) {
30+
return parent::toSql();
31+
}
32+
33+
return parent::toSql(Schema::getConnection(), Schema::getConnection()->getSchemaGrammar()); // @phpstan-ignore-line
34+
}
35+
}

src/Database/Models/DatabaseColumn.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
use KitLoong\MigrationsGenerator\Enum\Migrations\ColumnName;
66
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\ColumnType;
77
use KitLoong\MigrationsGenerator\Schema\Models\Column;
8-
use KitLoong\MigrationsGenerator\Support\CheckLaravelVersion;
98

109
/**
1110
* @phpstan-import-type SchemaColumn from \KitLoong\MigrationsGenerator\Database\DatabaseSchema
1211
*/
1312
abstract class DatabaseColumn implements Column
1413
{
15-
use CheckLaravelVersion;
16-
1714
private const REMEMBER_TOKEN_LENGTH = 100;
1815

1916
protected bool $autoincrement;

src/Database/Models/MySQL/MySQLColumn.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,6 @@ private function setStoredDefinition(): void
254254
*/
255255
private function setRealSpatialColumn(): void
256256
{
257-
if (!$this->atLeastLaravel11()) {
258-
return;
259-
}
260-
261257
switch ($this->type) {
262258
case ColumnType::GEOMETRY_COLLECTION:
263259
$this->spatialSubType = 'geometryCollection';

src/Database/Models/PgSQL/PgSQLColumn.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,6 @@ private function setRawDefault(): void
123123
$this->rawDefault = true;
124124
}
125125

126-
/**
127-
* Get geometry mapping.
128-
*
129-
* @return array<string, \KitLoong\MigrationsGenerator\Enum\Migrations\Method\ColumnType>
130-
*/
131-
private function getGeometryMap(): array
132-
{
133-
return [
134-
'geometry' => ColumnType::GEOMETRY,
135-
'geometrycollection' => ColumnType::GEOMETRY_COLLECTION,
136-
'linestring' => ColumnType::LINE_STRING,
137-
'multilinestring' => ColumnType::MULTI_LINE_STRING,
138-
'multipoint' => ColumnType::MULTI_POINT,
139-
'multipolygon' => ColumnType::MULTI_POLYGON,
140-
'point' => ColumnType::POINT,
141-
'polygon' => ColumnType::POLYGON,
142-
];
143-
}
144-
145126
/**
146127
* Set to geometry type base on geography map.
147128
*/
@@ -171,17 +152,6 @@ private function setRealSpatialColumn(string $fullDefinitionType): void
171152
$spatialSubType = $matches[2];
172153
$spatialSrID = isset($matches[3]) ? (int) $matches[3] : null;
173154

174-
if (!$this->atLeastLaravel11()) {
175-
$map = $this->getGeometryMap();
176-
177-
if (!isset($map[$spatialSubType])) {
178-
return;
179-
}
180-
181-
$this->type = $map[$spatialSubType];
182-
return;
183-
}
184-
185155
$this->spatialSubType = $spatialSubType;
186156
$this->spatialSrID = $spatialSrID;
187157
}

src/Database/Models/PgSQL/PgSQLIndex.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
namespace KitLoong\MigrationsGenerator\Database\Models\PgSQL;
44

5-
use Illuminate\Database\Schema\Blueprint;
6-
use Illuminate\Support\Facades\Schema;
5+
use KitLoong\MigrationsGenerator\Database\Models\Blueprint;
76
use KitLoong\MigrationsGenerator\Database\Models\DatabaseIndex;
87
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\IndexType;
98
use KitLoong\MigrationsGenerator\Support\TableName;
@@ -37,6 +36,6 @@ public function __construct(string $table, array $index, bool $hasUDTColumn)
3736
// Generate the alter index statement.
3837
$blueprint->{$this->type->value}($this->columns, $this->name);
3938

40-
$this->udtColumnSqls = $blueprint->toSql(Schema::getConnection(), Schema::getConnection()->getSchemaGrammar());
39+
$this->udtColumnSqls = $blueprint->toSqlWithCompatible();
4140
}
4241
}

src/Database/Models/PgSQL/PgSQLUDTColumn.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace KitLoong\MigrationsGenerator\Database\Models\PgSQL;
44

5-
use Illuminate\Database\Schema\Blueprint;
6-
use Illuminate\Support\Facades\Schema;
75
use Illuminate\Support\Str;
6+
use KitLoong\MigrationsGenerator\Database\Models\Blueprint;
87
use KitLoong\MigrationsGenerator\Database\Models\DatabaseUDTColumn;
98
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\ColumnType;
109
use KitLoong\MigrationsGenerator\Support\TableName;
@@ -33,7 +32,7 @@ public function __construct(string $table, array $column)
3332
'nullable' => $column['nullable'],
3433
]);
3534

36-
$sqls = $blueprint->toSql(Schema::getConnection(), Schema::getConnection()->getSchemaGrammar());
35+
$sqls = $blueprint->toSqlWithCompatible();
3736

3837
// Replace the string column type with the user-defined type.
3938
$sqls[0] = Str::replaceFirst(' varchar ', ' ' . $column['type'] . ' ', $sqls[0]);

src/Database/Models/SQLSrv/SQLSrvIndex.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace KitLoong\MigrationsGenerator\Database\Models\SQLSrv;
44

5-
use Illuminate\Database\Schema\Blueprint;
6-
use Illuminate\Support\Facades\Schema;
75
use Illuminate\Support\Str;
6+
use KitLoong\MigrationsGenerator\Database\Models\Blueprint;
87
use KitLoong\MigrationsGenerator\Database\Models\DatabaseIndex;
98
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\IndexType;
109
use KitLoong\MigrationsGenerator\Support\TableName;
@@ -37,7 +36,7 @@ public function __construct(string $table, array $index, bool $hasUDTColumn)
3736
// Generate the alter index statement.
3837
$blueprint->{$this->type->value}($this->columns, $this->name);
3938

40-
$this->udtColumnSqls = $blueprint->toSql(Schema::getConnection(), Schema::getConnection()->getSchemaGrammar());
39+
$this->udtColumnSqls = $blueprint->toSqlWithCompatible();
4140
}
4241

4342
/**

src/Database/Models/SQLSrv/SQLSrvUDTColumn.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace KitLoong\MigrationsGenerator\Database\Models\SQLSrv;
44

5-
use Illuminate\Database\Schema\Blueprint;
6-
use Illuminate\Support\Facades\Schema;
75
use Illuminate\Support\Str;
6+
use KitLoong\MigrationsGenerator\Database\Models\Blueprint;
87
use KitLoong\MigrationsGenerator\Database\Models\DatabaseUDTColumn;
98
use KitLoong\MigrationsGenerator\Support\TableName;
109

@@ -30,7 +29,7 @@ public function __construct(string $table, array $column)
3029
'nullable' => $column['nullable'],
3130
]);
3231

33-
$sqls = $blueprint->toSql(Schema::getConnection(), Schema::getConnection()->getSchemaGrammar());
32+
$sqls = $blueprint->toSqlWithCompatible();
3433

3534
// Replace the string column type with the user-defined type.
3635
$sqls[0] = Str::replaceFirst(' nvarchar() ', ' ' . $column['type'] . ' ', $sqls[0]);

src/Database/MySQLSchema.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public function getViewNames(): Collection
4545
*/
4646
public function getViews(): Collection
4747
{
48-
return $this->getSchemaViews()
49-
->map(static fn (array $view) => new MySQLView($view));
48+
return $this->getSchemaViews()->map(static fn (array $view) => new MySQLView($view));
5049
}
5150

5251
/**

src/Database/PgSQLSchema.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public function getTable(string $name): Table
6666
*/
6767
public function getViewNames(): Collection
6868
{
69-
return $this->getViews()
70-
->map(static fn (View $view) => $view->getName());
69+
return $this->getViews()->map(static fn (View $view) => $view->getName());
7170
}
7271

7372
/**

src/Database/SQLiteSchema.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public function getViewNames(): Collection
3737
*/
3838
public function getViews(): Collection
3939
{
40-
return $this->getSchemaViews()
41-
->map(static fn (array $view) => new SQLiteView($view));
40+
return $this->getSchemaViews()->map(static fn (array $view) => new SQLiteView($view));
4241
}
4342

4443
/**

src/MigrateGenerateCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
class MigrateGenerateCommand extends Command
2828
{
2929
/**
30-
* The name and signature of the console command.
30+
* @inheritDoc
3131
*/
32-
// phpcs:ignore
3332
protected $signature = 'migrate:generate
3433
{tables? : A list of tables or views you wish to generate migrations for separated by a comma: users,posts,comments}
3534
{--c|connection= : The database connection to use}
@@ -54,9 +53,8 @@ class MigrateGenerateCommand extends Command
5453
{--with-has-table : Check for the existence of a table using `hasTable`}';
5554

5655
/**
57-
* The console command description.
56+
* @inheritDoc
5857
*/
59-
// phpcs:ignore
6058
protected $description = 'Generate migrations from an existing table structure.';
6159

6260
protected Schema $schema;

0 commit comments

Comments
 (0)