Skip to content

Commit

Permalink
Merge pull request #208 from kitloong/feature/patch
Browse files Browse the repository at this point in the history
Fix error
  • Loading branch information
kitloong authored Mar 5, 2024
2 parents 925b517 + 74a1601 commit a21df90
Show file tree
Hide file tree
Showing 25 changed files with 211 additions and 328 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml,xml}]
[*.{yml,yaml}]
indent_size = 2
33 changes: 0 additions & 33 deletions .env.action

This file was deleted.

33 changes: 0 additions & 33 deletions .env.example

This file was deleted.

2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
/.github export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.env.* export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.phpmd.xml export-ignore
/check_migrations.sh export-ignore
/phpcs.xml export-ignore
/phpstan.neon export-ignore
/phpunit.xml.dist export-ignore
/phpunit-action.xml export-ignore
/testbench.yaml export-ignore
5 changes: 2 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ If applicable, add screenshots to help explain your problem.

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

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --prefer-stable --prefer-dist --no-interaction --no-progress
- name: Setup .env
- name: Setup environment
run: |
mkdir ./database
composer run action-env-setup
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/migrations
/storage
/vendor
.env
.php-cs-fixer.cache
.php_cs.cache
.phpstorm.meta.php
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"prefer-stable": true,
"scripts": {
"action-env-setup": [
"@php -r \"file_exists('.env') || copy('.env.action', '.env');\""
"@php -r \"file_exists('phpunit.xml') || copy('phpunit-action.xml', 'phpunit.xml');\""
],
"phpcs": [
"phpcs"
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ parameters:
level: 6

ignoreErrors:
- '#Class Dotenv\\Dotenv constructor invoked with 1 parameter, 4 required.#'
- '#Parameter \#1 \$store of class Dotenv\\Dotenv constructor expects Dotenv\\Store\\StoreInterface, string given.#'
- '#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>.#'
- '#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>.#'
- '#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>.#'
Expand Down
55 changes: 55 additions & 0 deletions phpunit-action.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
stderr="true"
>
<coverage includeUncoveredFiles="true"/>
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<php>
<env name="MYSQL57_HOST" value="127.0.0.1"/>
<env name="MYSQL57_PORT" value="3306"/>
<env name="MYSQL57_DATABASE" value="migration"/>
<env name="MYSQL57_USERNAME" value="root"/>
<env name="MYSQL57_PASSWORD" value=""/>

<env name="MYSQL8_HOST" value="127.0.0.1"/>
<env name="MYSQL8_PORT" value="33062"/>
<env name="MYSQL8_DATABASE" value="migration"/>
<env name="MYSQL8_USERNAME" value="root"/>
<env name="MYSQL8_PASSWORD" value=""/>

<env name="POSTGRES_HOST" value="127.0.0.1"/>
<env name="POSTGRES_PORT" value="5432"/>
<env name="POSTGRES_DATABASE" value="migration"/>
<env name="POSTGRES_USERNAME" value="root"/>
<env name="POSTGRES_PASSWORD" value="!QAZ2wsx"/>

<env name="SQLSRV_HOST" value="127.0.0.1"/>
<env name="SQLSRV_PORT" value="1433"/>
<env name="SQLSRV_DATABASE" value="migration"/>
<env name="SQLSRV_USERNAME" value="sa"/>
<env name="SQLSRV_PASSWORD" value="!QAZ2wsx"/>

<env name="MARIADB_HOST" value="127.0.0.1"/>
<env name="MARIADB_PORT" value="3307"/>
<env name="MARIADB_DATABASE" value="migration"/>
<env name="MARIADB_USERNAME" value="root"/>
<env name="MARIADB_PASSWORD" value=""/>

<env name="SQLITE_DATABASE" value="./database/migration.sqlite"/>

<env name="MYSQLDUMP_HAS_OPTION_SKIP_COLUMN_STATISTICS" value="true"/>
</php>
</phpunit>
44 changes: 38 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,43 @@
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory>src/DBAL/Types</directory>
</exclude>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<php>
<env name="MYSQL57_HOST" value="mysql57"/>
<env name="MYSQL57_PORT" value="3306"/>
<env name="MYSQL57_DATABASE" value="migration"/>
<env name="MYSQL57_USERNAME" value=""/>
<env name="MYSQL57_PASSWORD" value=""/>

<env name="MYSQL8_HOST" value="mysql8"/>
<env name="MYSQL8_PORT" value="3306"/>
<env name="MYSQL8_DATABASE" value="migration"/>
<env name="MYSQL8_USERNAME" value=""/>
<env name="MYSQL8_PASSWORD" value=""/>

<env name="POSTGRES_HOST" value="postgis"/>
<env name="POSTGRES_PORT" value="5432"/>
<env name="POSTGRES_DATABASE" value="migration"/>
<env name="POSTGRES_USERNAME" value=""/>
<env name="POSTGRES_PASSWORD" value=""/>

<env name="SQLSRV_HOST" value="sqlsrv"/>
<env name="SQLSRV_PORT" value="1433"/>
<env name="SQLSRV_DATABASE" value="migration"/>
<env name="SQLSRV_USERNAME" value=""/>
<env name="SQLSRV_PASSWORD" value=""/>

<env name="MARIADB_HOST" value="mariadb"/>
<env name="MARIADB_PORT" value="3306"/>
<env name="MARIADB_DATABASE" value="migration"/>
<env name="MARIADB_USERNAME" value=""/>
<env name="MARIADB_PASSWORD" value=""/>

<env name="SQLITE_DATABASE" value="./database/migration.sqlite"/>

<env name="MYSQLDUMP_HAS_OPTION_SKIP_COLUMN_STATISTICS" value="false"/>
</php>
</phpunit>
12 changes: 12 additions & 0 deletions src/Database/Models/PgSQL/PgSQLColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace KitLoong\MigrationsGenerator\Database\Models\PgSQL;

use Illuminate\Support\Str;
use KitLoong\MigrationsGenerator\Database\Models\DatabaseColumn;
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\ColumnType;
use KitLoong\MigrationsGenerator\Repositories\PgSQLRepository;
Expand Down Expand Up @@ -80,6 +81,17 @@ protected function escapeDefault(?string $default): ?string
return parent::escapeDefault($default);
}

protected function setTypeToIncrements(bool $supportUnsigned): void
{
parent::setTypeToIncrements($supportUnsigned);

if (!Str::startsWith($this->default, 'nextval(') || !Str::endsWith($this->default, '::regclass)')) {
return;
}

$this->default = null;
}

/**
* Check and set to use raw default.
* Raw default will be generated with DB::raw().
Expand Down
1 change: 0 additions & 1 deletion src/Database/Models/PgSQL/PgSQLUDTColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function __construct(string $table, array $column)
'comment' => $column['comment'],
'default' => $this->parseDefault($column['default'], ColumnType::STRING), // Assume is string
'nullable' => $column['nullable'],
// 'after' => "id",
]);

$sqls = $blueprint->toSql(Schema::getConnection(), Schema::getConnection()->getSchemaGrammar());
Expand Down
3 changes: 1 addition & 2 deletions src/Database/Models/SQLSrv/SQLSrvIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Support\Str;
use KitLoong\MigrationsGenerator\Database\Models\DatabaseIndex;
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\IndexType;
use KitLoong\MigrationsGenerator\Support\Regex;

class SQLSrvIndex extends DatabaseIndex
{
Expand Down Expand Up @@ -36,7 +35,7 @@ private function resetPrimaryNameToEmptyIfIsDefaultName(): void

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

Expand Down
1 change: 0 additions & 1 deletion src/Database/Models/SQLSrv/SQLSrvUDTColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function __construct(string $table, array $column)
'autoIncrement' => $column['auto_increment'],
'default' => $this->parseDefault($column['default']),
'nullable' => $column['nullable'],
// 'after' => "id",
]);

$sqls = $blueprint->toSql(Schema::getConnection(), Schema::getConnection()->getSchemaGrammar());
Expand Down
14 changes: 3 additions & 11 deletions src/Migration/Migrator/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use KitLoong\MigrationsGenerator\Support\Regex;
use Illuminate\Support\Str;

class Migrator extends DefaultMigrator
{
Expand Down Expand Up @@ -41,7 +41,7 @@ public function getVendorTableNames(): array
$queries = $this->getMigrationQueries($file->getPathname());

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

if ($matched === '') {
continue;
Expand Down Expand Up @@ -76,14 +76,6 @@ protected function getMigrationQueries(string $path): array
*/
protected function resolveMigration(string $path): object
{
if (method_exists(DefaultMigrator::class, 'resolvePath')) {
return $this->resolvePath($path);
}

// @codeCoverageIgnoreStart
return $this->resolve(
$this->getMigrationName($path),
);
// @codeCoverageIgnoreEnd
return $this->resolvePath($path);
}
}
16 changes: 8 additions & 8 deletions src/MigrationsGeneratorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use Illuminate\Database\Migrations\MigrationRepositoryInterface;
use Illuminate\Support\ServiceProvider;
use KitLoong\MigrationsGenerator\Database\MySQLSchema as DBALMySQLSchema;
use KitLoong\MigrationsGenerator\Database\PgSQLSchema as DBALPgSQLSchema;
use KitLoong\MigrationsGenerator\Database\SQLiteSchema as DBALSQLiteSchema;
use KitLoong\MigrationsGenerator\Database\SQLSrvSchema as DBALSQLSrvSchema;
use KitLoong\MigrationsGenerator\Database\MySQLSchema as DatabaseMySQLSchema;
use KitLoong\MigrationsGenerator\Database\PgSQLSchema as DatabasePgSQLSchema;
use KitLoong\MigrationsGenerator\Database\SQLiteSchema as DatabaseSQLiteSchema;
use KitLoong\MigrationsGenerator\Database\SQLSrvSchema as DatabaseSQLSrvSchema;
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\ColumnType;
use KitLoong\MigrationsGenerator\Migration\Generator\Columns\BooleanColumn;
use KitLoong\MigrationsGenerator\Migration\Generator\Columns\DatetimeColumn;
Expand Down Expand Up @@ -58,10 +58,10 @@ public function register(): void

foreach (
[
MySQLSchema::class => DBALMySQLSchema::class,
PgSQLSchema::class => DBALPgSQLSchema::class,
SQLiteSchema::class => DBALSQLiteSchema::class,
SQLSrvSchema::class => DBALSQLSrvSchema::class,
MySQLSchema::class => DatabaseMySQLSchema::class,
PgSQLSchema::class => DatabasePgSQLSchema::class,
SQLiteSchema::class => DatabaseSQLiteSchema::class,
SQLSrvSchema::class => DatabaseSQLSrvSchema::class,
] as $abstract => $concrete
) {
$this->app->bind($abstract, $concrete);
Expand Down
20 changes: 0 additions & 20 deletions src/Repositories/Entities/SQLSrv/ViewDefinition.php

This file was deleted.

Loading

0 comments on commit a21df90

Please sign in to comment.