Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.3']
['8.4']
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
php:
- 8.1
- 8.2
- 8.3
- 8.4

steps:
- name: Checkout.
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
run: vendor/bin/phpunit --testsuite=Migration --coverage-clover=coverage.xml --colors=always

- name: Upload coverage to Codecov.
if: matrix.php == '8.3'
if: matrix.php == '8.4'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2', '8.3']
['8.1', '8.2', '8.3', '8.4']
3 changes: 2 additions & 1 deletion .github/workflows/mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- 8.1
- 8.2
- 8.3
- 8.4

services:
mssql:
Expand Down Expand Up @@ -100,7 +101,7 @@ jobs:
run: vendor/bin/phpunit --testsuite=Mssql --coverage-clover=coverage.xml --colors=always

- name: Upload coverage to Codecov.
if: matrix.php == '8.3'
if: matrix.php == '8.4'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
matrix:
php:
- 8.3
- 8.4

services:
postgres:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- 8.1
- 8.2
- 8.3
- 8.4

services:
mysql:
Expand Down Expand Up @@ -92,7 +93,7 @@ jobs:
run: vendor/bin/phpunit --testsuite=Mysql --coverage-clover=coverage.xml --colors=always

- name: Upload coverage to Codecov.
if: matrix.php == '8.3'
if: matrix.php == '8.4'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- 8.1
- 8.2
- 8.3
- 8.4

services:
oci:
Expand Down Expand Up @@ -96,7 +97,7 @@ jobs:
run: vendor/bin/phpunit --testsuite=Oracle --coverage-clover=coverage.xml --colors=always

- name: Upload coverage to Codecov.
if: matrix.php == '8.3'
if: matrix.php == '8.4'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- 8.1
- 8.2
- 8.3
- 8.4

services:
postgres:
Expand Down Expand Up @@ -92,7 +93,7 @@ jobs:
run: vendor/bin/phpunit --testsuite=Pgsql --coverage-clover=coverage.xml --colors=always

- name: Upload coverage to Codecov.
if: matrix.php == '8.3'
if: matrix.php == '8.4'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.3']
['8.4']
4 changes: 2 additions & 2 deletions .github/workflows/sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
php:
- 8.1
- 8.2
- 8.3
- 8.4

steps:
- name: Checkout.
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
run: vendor/bin/phpunit --testsuite=Sqlite --coverage-clover=coverage.xml --colors=always

- name: Upload coverage to Codecov.
if: matrix.php == '8.3'
if: matrix.php == '8.4'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- 8.1
- 8.2
- 8.3
- 8.4

steps:
- name: Checkout.
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- Chg #279: Use `ColumnBuilder` class to create table column definitions (@Tigrov)
- Enh #282, #283: Adapt to Yii DB changes (@Tigrov)
- Bug #286: Explicitly mark nullable parameters (@vjik)
- Chg #287: Change supported PHP versions to `8.1 - 8.4` (@Tigrov)
- Enh #287: Minor refactoring (@Tigrov)

## 1.2.0 November 27, 2024

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Supports the following databases out of the box:

## Requirements

- PHP 8.0 or higher.
- PHP 8.1 - 8.4.
- `Filter` PHP extension.

## Installation
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@
}
],
"require": {
"php": "^8.1",
"php": "8.1 - 8.4",
"ext-filter": "*",
"symfony/console": "^6.0|^7.0",
"yiisoft/db": "dev-master",
"yiisoft/injector": "^1.2"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.4",
"phpunit/phpunit": "^10.5",
"rector/rector": "^2.0",
"maglnet/composer-require-checker": "^4.7.1",
"phpunit/phpunit": "^10.5.45",
"rector/rector": "^2.0.10",
"roave/infection-static-analysis-plugin": "^1.35",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^5.25",
"spatie/phpunit-watcher": "^1.24",
"vimeo/psalm": "^5.26.1 || ^6.8.8",
"yiisoft/db-sqlite": "dev-master",
"yiisoft/di": "^1.2",
"yiisoft/di": "^1.3",
"yiisoft/files": "^2.0",
"yiisoft/test-support": "^3.0",
"yiisoft/yii-console": "^2.0"
"yiisoft/test-support": "^3.0.2",
"yiisoft/yii-console": "^2.3"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
ensureOverrideAttribute="false"
findUnusedBaselineEntry="true"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
56 changes: 25 additions & 31 deletions src/MigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Exception;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Constant\IndexType;
use Yiisoft\Db\Constant\PseudoType;
use Yiisoft\Db\Constant\ReferentialAction;
use Yiisoft\Db\Constraint\Constraint;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
Expand Down Expand Up @@ -435,53 +437,45 @@ public function dropPrimaryKey(string $table, string $name): void
}

/**
* Builds an SQL statement for adding a foreign key constraint to an existing table.
* Builds and executes an SQL statement for adding a foreign key constraint to an existing table.
* The method will quote the `name`, `table`, `referenceTable` parameters before using them in the generated SQL.
*
* The method will properly quote the table and column names.
*
* @param string $table The table that the foreign key constraint will be added to.
* @param string $table The name of the table to add foreign key constraint to.
* @param string $name The name of the foreign key constraint.
* @param array|string $columns The name of the column to that the constraint will be added on. If there are
* multiple columns, separate them with commas or use an array.
* @param string $refTable The table that the foreign key references to.
* @param array|string $refColumns The name of the column that the foreign key references to. If there are multiple
* columns, separate them with commas or use an array.
* @param string|null $delete The `ON DELETE` option. Most DBMS support these options: `RESTRICT`, `CASCADE`,
* `NO ACTION`, `SET DEFAULT`, `SET NULL`.
* @param string|null $update The `ON UPDATE` option. Most DBMS support these options: `RESTRICT`, `CASCADE`,
* `NO ACTION`, `SET DEFAULT`, `SET NULL`.
* @param string|string[] $columns The name of the column to add foreign key constraint to. If there are
* many columns, separate them with commas.
* @param string $referenceTable The name of the table that the foreign key references to.
* @param string|string[] $referenceColumns The name of the column that the foreign key references to. If there are
* many columns, separate them with commas.
* @param string|null $delete The `ON DELETE` option. See {@see ReferentialAction} class for possible values.
* @param string|null $update The `ON UPDATE` option. See {@see ReferentialAction} class for possible values.
*
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
*
* @psalm-param string[]|string $columns
* @psalm-param string[]|string $refColumns
* @psalm-param ReferentialAction::*|null $delete
* @psalm-param ReferentialAction::*|null $update
*/
public function addForeignKey(
string $table,
string $name,
array|string $columns,
string $refTable,
array|string $refColumns,
string $referenceTable,
array|string $referenceColumns,
string|null $delete = null,
string|null $update = null
): void {
$time = $this->beginCommand(
"Add foreign key $name: $table (" . implode(
',',
(array) $columns
) . ") references $refTable (" . implode(
',',
(array) $refColumns
) . ')'
"Add foreign key $name: $table (" . implode(',', (array) $columns) . ')'
. " references $referenceTable (" . implode(',', (array) $referenceColumns) . ')'
);
$this->db->createCommand()->addForeignKey(
$table,
$name,
$columns,
$refTable,
$refColumns,
$referenceTable,
$referenceColumns,
$delete,
$update
)->execute();
Expand Down Expand Up @@ -511,18 +505,18 @@ public function dropForeignKey(string $table, string $name): void
* @param string $table The table that the new index will be created for. The table name will be properly quoted by
* the method.
* @param string $name The name of the index. The name will be properly quoted by the method.
* @param array|string $columns The column(s) that should be included in the index. If there are multiple columns,
* @param string|string[] $columns The column(s) that should be included in the index. If there are multiple columns,
* please separate them by commas or use an array. Each column name will be properly quoted by the method. Quoting
* will be skipped for column names that include a left parenthesis "(".
* @param string|null $indexType Type of index supported DBMS - for example, `UNIQUE`, `FULLTEXT`, `SPATIAL`,
* `BITMAP` or `null` as default.
* @param string|null $indexMethod For setting index organization method (with 'USING', not all DBMS).
* @param string|null $indexType The type of the index supported by DBMS {@see IndexType} - for example: `UNIQUE`,
* `FULLTEXT`, `SPATIAL`, `BITMAP` or null as default.
* @param string|null $indexMethod The index organization method (with `USING`, not all DBMS).
*
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
*
* @psalm-param string[]|string $columns
* @psalm-param IndexType::*|null $indexType
*/
public function createIndex(
string $table,
Expand Down
1 change: 1 addition & 0 deletions src/Service/Generate/FieldsParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function parse(
foreach ($chunks as $i => $chunk) {
if (str_starts_with($chunk, 'foreignKey')) {
preg_match('/foreignKey\((\w*)\s?(\w*)\)/', $chunk, $matches);
/** @psalm-suppress PossiblyNullArgument */
$foreignKeys[] = $this->foreignKeyFactory->create(
$table,
$columnName,
Expand Down
3 changes: 2 additions & 1 deletion src/Service/Generate/PhpRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function render(string $file, array $params = []): string

try {
$this->renderer($file, $params);
/** @var string */
return ob_get_clean();
} catch (Throwable $e) {
while (ob_get_level() > $obInitialLevel) {
Expand All @@ -40,7 +41,7 @@ public function render(string $file, array $params = []): string

private function renderer(): void
{
/** @psalm-suppress MixedArgument */
/** @psalm-suppress MixedArgument, PossiblyFalseArgument */
extract(func_get_arg(1));
/** @psalm-suppress UnresolvableInclude */
require func_get_arg(0);
Expand Down
22 changes: 16 additions & 6 deletions src/Service/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function getNewMigrations(): array
continue;
}

/** @var resource $handle */
$handle = opendir($sourcePath);
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
Expand Down Expand Up @@ -335,8 +336,9 @@ public function getNewMigrationNamespace(): string
*/
public function generateClassName(string $name): string
{
return 'M' . gmdate('ymdHis')
. str_replace(' ', '', ucwords(preg_replace('/[^a-z0-9]+/i', ' ', $name)));
/** @var string $words */
$words = preg_replace('/[^a-z0-9]+/i', ' ', $name);
return 'M' . gmdate('ymdHis') . str_replace(' ', '', ucwords($words));
}

/**
Expand Down Expand Up @@ -398,7 +400,9 @@ public function filterMigrations(array $classes, array $namespaces = [], array $
continue;
}

$className = substr(strrchr($class, '\\'), 1);
/** @var string $className */
$className = strrchr($class, '\\');
$className = substr($className, 1);
$file = $path . DIRECTORY_SEPARATOR . $className . '.php';

if (is_file($file)) {
Expand Down Expand Up @@ -428,7 +432,9 @@ private function getNamespacePath(string $namespace): string

foreach ($map as $mapNamespace => $mapDirectories) {
if (str_starts_with($namespace, trim($mapNamespace, '\\'))) {
return reset($mapDirectories) . '/' . str_replace('\\', '/', substr($namespace, strlen($mapNamespace)));
/** @var string $mapDirectory */
$mapDirectory = reset($mapDirectories);
return $mapDirectory . '/' . str_replace('\\', '/', substr($namespace, strlen($mapNamespace)));
}
}

Expand All @@ -445,7 +451,9 @@ private function getNamespacePath(string $namespace): string
private function getNamespacesFromPath(string $path): array
{
$namespaces = [];
$path = realpath($path) . DIRECTORY_SEPARATOR;
/** @var string $path */
$path = realpath($path);
$path .= DIRECTORY_SEPARATOR;

/**
* @psalm-suppress UnresolvableInclude
Expand All @@ -459,7 +467,9 @@ private function getNamespacesFromPath(string $path): array
continue;
}

$directory = realpath($directory) . DIRECTORY_SEPARATOR;
/** @var string $directory */
$directory = realpath($directory);
$directory .= DIRECTORY_SEPARATOR;

if (str_starts_with($path, $directory)) {
$length = strlen($directory);
Expand Down