Skip to content

Commit a21df90

Browse files
authored
Merge pull request #208 from kitloong/feature/patch
Fix error
2 parents 925b517 + 74a1601 commit a21df90

25 files changed

+211
-328
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ trim_trailing_whitespace = true
1111
[*.md]
1212
trim_trailing_whitespace = false
1313

14-
[*.{yml,yaml,xml}]
14+
[*.{yml,yaml}]
1515
indent_size = 2

.env.action

Lines changed: 0 additions & 33 deletions
This file was deleted.

.env.example

Lines changed: 0 additions & 33 deletions
This file was deleted.

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
/.github export-ignore
66
/tests export-ignore
77
/.editorconfig export-ignore
8-
/.env.* export-ignore
98
/.gitattributes export-ignore
109
/.gitignore export-ignore
1110
/.phpmd.xml export-ignore
1211
/check_migrations.sh export-ignore
1312
/phpcs.xml export-ignore
1413
/phpstan.neon export-ignore
1514
/phpunit.xml.dist export-ignore
15+
/phpunit-action.xml export-ignore
1616
/testbench.yaml export-ignore

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ If applicable, add screenshots to help explain your problem.
2525

2626
**Details (please complete the following information):**
2727
- DB: [e.g. MySQL]
28-
- DB Version: [e.g. 5.7.37]
28+
- DB Version: [e.g. 8.0.30]
2929
- Laravel Version:
3030
- PHP Version:
31-
- Migrations Generator Version:
32-
- Doctrine DBAL Version [`composer info doctrine/dbal | grep versions`]:
31+
- Migrations Generator Version:
3332

3433
**Additional context**
3534
Add any other context about the problem here.

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
117117
composer update --prefer-stable --prefer-dist --no-interaction --no-progress
118118
119-
- name: Setup .env
119+
- name: Setup environment
120120
run: |
121121
mkdir ./database
122122
composer run action-env-setup

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/migrations
66
/storage
77
/vendor
8-
.env
98
.php-cs-fixer.cache
109
.php_cs.cache
1110
.phpstorm.meta.php

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"prefer-stable": true,
5353
"scripts": {
5454
"action-env-setup": [
55-
"@php -r \"file_exists('.env') || copy('.env.action', '.env');\""
55+
"@php -r \"file_exists('phpunit.xml') || copy('phpunit-action.xml', 'phpunit.xml');\""
5656
],
5757
"phpcs": [
5858
"phpcs"

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ parameters:
1111
level: 6
1212

1313
ignoreErrors:
14-
- '#Class Dotenv\\Dotenv constructor invoked with 1 parameter, 4 required.#'
15-
- '#Parameter \#1 \$store of class Dotenv\\Dotenv constructor expects Dotenv\\Store\\StoreInterface, string given.#'
1614
- '#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>.#'
1715
- '#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>.#'
1816
- '#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>.#'

phpunit-action.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
stderr="true"
8+
>
9+
<coverage includeUncoveredFiles="true"/>
10+
<testsuites>
11+
<testsuite name="Application Test Suite">
12+
<directory suffix="Test.php">tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
<source>
16+
<include>
17+
<directory suffix=".php">src</directory>
18+
</include>
19+
</source>
20+
<php>
21+
<env name="MYSQL57_HOST" value="127.0.0.1"/>
22+
<env name="MYSQL57_PORT" value="3306"/>
23+
<env name="MYSQL57_DATABASE" value="migration"/>
24+
<env name="MYSQL57_USERNAME" value="root"/>
25+
<env name="MYSQL57_PASSWORD" value=""/>
26+
27+
<env name="MYSQL8_HOST" value="127.0.0.1"/>
28+
<env name="MYSQL8_PORT" value="33062"/>
29+
<env name="MYSQL8_DATABASE" value="migration"/>
30+
<env name="MYSQL8_USERNAME" value="root"/>
31+
<env name="MYSQL8_PASSWORD" value=""/>
32+
33+
<env name="POSTGRES_HOST" value="127.0.0.1"/>
34+
<env name="POSTGRES_PORT" value="5432"/>
35+
<env name="POSTGRES_DATABASE" value="migration"/>
36+
<env name="POSTGRES_USERNAME" value="root"/>
37+
<env name="POSTGRES_PASSWORD" value="!QAZ2wsx"/>
38+
39+
<env name="SQLSRV_HOST" value="127.0.0.1"/>
40+
<env name="SQLSRV_PORT" value="1433"/>
41+
<env name="SQLSRV_DATABASE" value="migration"/>
42+
<env name="SQLSRV_USERNAME" value="sa"/>
43+
<env name="SQLSRV_PASSWORD" value="!QAZ2wsx"/>
44+
45+
<env name="MARIADB_HOST" value="127.0.0.1"/>
46+
<env name="MARIADB_PORT" value="3307"/>
47+
<env name="MARIADB_DATABASE" value="migration"/>
48+
<env name="MARIADB_USERNAME" value="root"/>
49+
<env name="MARIADB_PASSWORD" value=""/>
50+
51+
<env name="SQLITE_DATABASE" value="./database/migration.sqlite"/>
52+
53+
<env name="MYSQLDUMP_HAS_OPTION_SKIP_COLUMN_STATISTICS" value="true"/>
54+
</php>
55+
</phpunit>

phpunit.xml.dist

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,43 @@
1313
</testsuite>
1414
</testsuites>
1515
<source>
16-
<include>
17-
<directory suffix=".php">src</directory>
18-
</include>
19-
<exclude>
20-
<directory>src/DBAL/Types</directory>
21-
</exclude>
16+
<include>
17+
<directory suffix=".php">src</directory>
18+
</include>
2219
</source>
20+
<php>
21+
<env name="MYSQL57_HOST" value="mysql57"/>
22+
<env name="MYSQL57_PORT" value="3306"/>
23+
<env name="MYSQL57_DATABASE" value="migration"/>
24+
<env name="MYSQL57_USERNAME" value=""/>
25+
<env name="MYSQL57_PASSWORD" value=""/>
26+
27+
<env name="MYSQL8_HOST" value="mysql8"/>
28+
<env name="MYSQL8_PORT" value="3306"/>
29+
<env name="MYSQL8_DATABASE" value="migration"/>
30+
<env name="MYSQL8_USERNAME" value=""/>
31+
<env name="MYSQL8_PASSWORD" value=""/>
32+
33+
<env name="POSTGRES_HOST" value="postgis"/>
34+
<env name="POSTGRES_PORT" value="5432"/>
35+
<env name="POSTGRES_DATABASE" value="migration"/>
36+
<env name="POSTGRES_USERNAME" value=""/>
37+
<env name="POSTGRES_PASSWORD" value=""/>
38+
39+
<env name="SQLSRV_HOST" value="sqlsrv"/>
40+
<env name="SQLSRV_PORT" value="1433"/>
41+
<env name="SQLSRV_DATABASE" value="migration"/>
42+
<env name="SQLSRV_USERNAME" value=""/>
43+
<env name="SQLSRV_PASSWORD" value=""/>
44+
45+
<env name="MARIADB_HOST" value="mariadb"/>
46+
<env name="MARIADB_PORT" value="3306"/>
47+
<env name="MARIADB_DATABASE" value="migration"/>
48+
<env name="MARIADB_USERNAME" value=""/>
49+
<env name="MARIADB_PASSWORD" value=""/>
50+
51+
<env name="SQLITE_DATABASE" value="./database/migration.sqlite"/>
52+
53+
<env name="MYSQLDUMP_HAS_OPTION_SKIP_COLUMN_STATISTICS" value="false"/>
54+
</php>
2355
</phpunit>

src/Database/Models/PgSQL/PgSQLColumn.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

5+
use Illuminate\Support\Str;
56
use KitLoong\MigrationsGenerator\Database\Models\DatabaseColumn;
67
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\ColumnType;
78
use KitLoong\MigrationsGenerator\Repositories\PgSQLRepository;
@@ -80,6 +81,17 @@ protected function escapeDefault(?string $default): ?string
8081
return parent::escapeDefault($default);
8182
}
8283

84+
protected function setTypeToIncrements(bool $supportUnsigned): void
85+
{
86+
parent::setTypeToIncrements($supportUnsigned);
87+
88+
if (!Str::startsWith($this->default, 'nextval(') || !Str::endsWith($this->default, '::regclass)')) {
89+
return;
90+
}
91+
92+
$this->default = null;
93+
}
94+
8395
/**
8496
* Check and set to use raw default.
8597
* Raw default will be generated with DB::raw().

src/Database/Models/PgSQL/PgSQLUDTColumn.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function __construct(string $table, array $column)
2929
'comment' => $column['comment'],
3030
'default' => $this->parseDefault($column['default'], ColumnType::STRING), // Assume is string
3131
'nullable' => $column['nullable'],
32-
// 'after' => "id",
3332
]);
3433

3534
$sqls = $blueprint->toSql(Schema::getConnection(), Schema::getConnection()->getSchemaGrammar());

src/Database/Models/SQLSrv/SQLSrvIndex.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Support\Str;
66
use KitLoong\MigrationsGenerator\Database\Models\DatabaseIndex;
77
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\IndexType;
8-
use KitLoong\MigrationsGenerator\Support\Regex;
98

109
class SQLSrvIndex extends DatabaseIndex
1110
{
@@ -36,7 +35,7 @@ private function resetPrimaryNameToEmptyIfIsDefaultName(): void
3635

3736
// Can be improved by generate exact 16 characters of sequence number instead of `\w{16}`
3837
// if the rules of sequence number generation is known.
39-
if ($this->name !== Regex::match('/' . $prefix . '\w{16}/', $this->name)) {
38+
if ($this->name !== Str::match('/' . $prefix . '\w{16}/', $this->name)) {
4039
return;
4140
}
4241

src/Database/Models/SQLSrv/SQLSrvUDTColumn.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public function __construct(string $table, array $column)
2626
'autoIncrement' => $column['auto_increment'],
2727
'default' => $this->parseDefault($column['default']),
2828
'nullable' => $column['nullable'],
29-
// 'after' => "id",
3029
]);
3130

3231
$sqls = $blueprint->toSql(Schema::getConnection(), Schema::getConnection()->getSchemaGrammar());

src/Migration/Migrator/Migrator.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Support\Facades\Config;
77
use Illuminate\Support\Facades\DB;
88
use Illuminate\Support\Facades\File;
9-
use KitLoong\MigrationsGenerator\Support\Regex;
9+
use Illuminate\Support\Str;
1010

1111
class Migrator extends DefaultMigrator
1212
{
@@ -41,7 +41,7 @@ public function getVendorTableNames(): array
4141
$queries = $this->getMigrationQueries($file->getPathname());
4242

4343
foreach ($queries as $q) {
44-
$matched = Regex::match('/^create table ["|`](.*?)["|`]/', $q['query']);
44+
$matched = Str::match('/^create table ["|`](.*?)["|`]/', $q['query']);
4545

4646
if ($matched === '') {
4747
continue;
@@ -76,14 +76,6 @@ protected function getMigrationQueries(string $path): array
7676
*/
7777
protected function resolveMigration(string $path): object
7878
{
79-
if (method_exists(DefaultMigrator::class, 'resolvePath')) {
80-
return $this->resolvePath($path);
81-
}
82-
83-
// @codeCoverageIgnoreStart
84-
return $this->resolve(
85-
$this->getMigrationName($path),
86-
);
87-
// @codeCoverageIgnoreEnd
79+
return $this->resolvePath($path);
8880
}
8981
}

src/MigrationsGeneratorServiceProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
use Illuminate\Database\Migrations\MigrationRepositoryInterface;
66
use Illuminate\Support\ServiceProvider;
7-
use KitLoong\MigrationsGenerator\Database\MySQLSchema as DBALMySQLSchema;
8-
use KitLoong\MigrationsGenerator\Database\PgSQLSchema as DBALPgSQLSchema;
9-
use KitLoong\MigrationsGenerator\Database\SQLiteSchema as DBALSQLiteSchema;
10-
use KitLoong\MigrationsGenerator\Database\SQLSrvSchema as DBALSQLSrvSchema;
7+
use KitLoong\MigrationsGenerator\Database\MySQLSchema as DatabaseMySQLSchema;
8+
use KitLoong\MigrationsGenerator\Database\PgSQLSchema as DatabasePgSQLSchema;
9+
use KitLoong\MigrationsGenerator\Database\SQLiteSchema as DatabaseSQLiteSchema;
10+
use KitLoong\MigrationsGenerator\Database\SQLSrvSchema as DatabaseSQLSrvSchema;
1111
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\ColumnType;
1212
use KitLoong\MigrationsGenerator\Migration\Generator\Columns\BooleanColumn;
1313
use KitLoong\MigrationsGenerator\Migration\Generator\Columns\DatetimeColumn;
@@ -58,10 +58,10 @@ public function register(): void
5858

5959
foreach (
6060
[
61-
MySQLSchema::class => DBALMySQLSchema::class,
62-
PgSQLSchema::class => DBALPgSQLSchema::class,
63-
SQLiteSchema::class => DBALSQLiteSchema::class,
64-
SQLSrvSchema::class => DBALSQLSrvSchema::class,
61+
MySQLSchema::class => DatabaseMySQLSchema::class,
62+
PgSQLSchema::class => DatabasePgSQLSchema::class,
63+
SQLiteSchema::class => DatabaseSQLiteSchema::class,
64+
SQLSrvSchema::class => DatabaseSQLSrvSchema::class,
6565
] as $abstract => $concrete
6666
) {
6767
$this->app->bind($abstract, $concrete);

src/Repositories/Entities/SQLSrv/ViewDefinition.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)