Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into add-column-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Aug 23, 2024
2 parents 474775c + 7550b54 commit aeba17d
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 150 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ jobs:
- mariadb:latest

include:
- php: 8.0
mariadb: mariadb:latest
- php: 8.1
mariadb: mariadb:latest
- php: 8.2
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ jobs:
- mysql:latest

include:
- php: 8.0
mysql: mysql:latest
- php: 8.1
mysql: mysql:latest
- php: 8.2
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
- ubuntu-latest

php:
- 8.0
- 8.1
- 8.2
- 8.3
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
- ubuntu-latest

php:
- '8.0'
- '8.1'
- '8.2'
- '8.3'
Expand Down Expand Up @@ -66,9 +65,4 @@ jobs:
run: composer update --no-interaction --no-progress --optimize-autoloader --ansi

- name: Static analysis.
if: ${{ matrix.php != '8.0' }}
run: vendor/bin/psalm --config=${{ inputs.psalm-config }} --shepherd --stats --output-format=github --php-version=${{ matrix.php }}

- name: Static analysis.
if: ${{ matrix.php == '8.0' }}
run: vendor/bin/psalm --config=psalm4.xml --shepherd --stats --output-format=github --php-version=${{ matrix.php }}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Chg #339: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov)
- Enh #342: Add JSON overlaps condition builder (@Tigrov)
- Enh #344: Update `bit` type according to main PR yiisoft/db#860 (@Tigrov)
- Enh #347: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov)
- Bug #349: Restore connection if closed by connection timeout (@Tigrov)

## 1.2.0 March 21, 2024

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ It is used in [Yii Framework](https://www.yiiframework.com/) but can be used sep

## Support version

| PHP | MySQL/MariaDB Version | CI-Actions |
|-----------|-----------------------|------------|
| **8.0-8.2** |**5.7-8.0**/**10.4-10.10**|[![build](https://github.com/yiisoft/db-mysql/actions/workflows/build.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-mysql/actions/workflows/build.yml) [![ansi-mode](https://github.com/yiisoft/db-mysql/actions/workflows/ansi-mode.yml/badge.svg)](https://github.com/yiisoft/db-mysql/actions/workflows/ansi-mode.yml) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-mysql%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-mysql/master) [![static analysis](https://github.com/yiisoft/db-mysql/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-mysql/actions/workflows/static.yml)
| PHP | MySQL/MariaDB Version | CI-Actions |
|-------------|-----------------------|------------|
| **8.1-8.3** |**5.7-8.0**/**10.4-10.10**|[![build](https://github.com/yiisoft/db-mysql/actions/workflows/build.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-mysql/actions/workflows/build.yml) [![ansi-mode](https://github.com/yiisoft/db-mysql/actions/workflows/ansi-mode.yml/badge.svg)](https://github.com/yiisoft/db-mysql/actions/workflows/ansi-mode.yml) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-mysql%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-mysql/master) [![static analysis](https://github.com/yiisoft/db-mysql/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-mysql/actions/workflows/static.yml)

## Installation

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-ctype": "*",
"ext-json": "*",
"ext-pdo": "*",
Expand All @@ -41,11 +41,11 @@
},
"require-dev": {
"maglnet/composer-require-checker": "^4.2",
"phpunit/phpunit": "^9.5|^10.0",
"phpunit/phpunit": "^10.0",
"rector/rector": "^1.0",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.20",
"vimeo/psalm": "^5.25",
"yiisoft/aliases": "^2.0",
"yiisoft/log-target-file": "^2.0",
"yiisoft/cache-file": "^3.1",
Expand Down
17 changes: 0 additions & 17 deletions psalm4.xml

This file was deleted.

8 changes: 5 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
Expand All @@ -23,10 +24,11 @@

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
LevelSetList::UP_TO_PHP_81,
]);

$rectorConfig->skip([
ClosureToArrowFunctionRector::class,
NullToStrictStringFuncCallArgRector::class,
ReadOnlyPropertyRector::class,
]);
};
19 changes: 19 additions & 0 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace Yiisoft\Db\Mysql;

use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand;
use Yiisoft\Db\Exception\IntegrityException;

use function str_starts_with;

/**
* Implements a database command that can be executed with a PDO (PHP Data Object) database connection for MySQL,
Expand Down Expand Up @@ -40,6 +43,22 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra
return $result;
}

protected function queryInternal(int $queryMode): mixed
{
try {
return parent::queryInternal($queryMode);
} catch (IntegrityException $e) {
if (str_starts_with($e->getMessage(), 'SQLSTATE[HY000]: General error: 2006 ')) {
$this->db->close();
$this->cancel();

return parent::queryInternal($queryMode);
}

throw $e;
}
}

public function showDatabases(): array
{
$sql = <<<SQL
Expand Down
15 changes: 6 additions & 9 deletions src/DQLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Yiisoft\Db\QueryBuilder\AbstractDQLQueryBuilder;
use Yiisoft\Db\QueryBuilder\Condition\JsonOverlapsCondition;

use function array_merge;
use function ctype_digit;

/**
Expand Down Expand Up @@ -82,13 +81,11 @@ protected function hasOffset(mixed $offset): bool
*/
protected function defaultExpressionBuilders(): array
{
return array_merge(
parent::defaultExpressionBuilders(),
[
JsonExpression::class => JsonExpressionBuilder::class,
JsonOverlapsCondition::class => JsonOverlapsConditionBuilder::class,
Expression::class => ExpressionBuilder::class,
]
);
return [
...parent::defaultExpressionBuilders(),
JsonExpression::class => JsonExpressionBuilder::class,
JsonOverlapsCondition::class => JsonOverlapsConditionBuilder::class,
Expression::class => ExpressionBuilder::class,
];
}
}
21 changes: 6 additions & 15 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

use function array_change_key_case;
use function array_map;
use function array_merge;
use function array_values;
use function bindec;
use function in_array;
Expand Down Expand Up @@ -117,7 +116,7 @@ public function findUniqueIndexes(TableSchemaInterface $table): array
if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER) > 0) {
foreach ($matches as $match) {
$indexName = $match[1];
$indexColumns = array_map('trim', preg_split('/[`"],[`"]/', trim($match[2], '`"')));
$indexColumns = array_map(trim(...), preg_split('/[`"],[`"]/', trim($match[2], '`"')));
$uniqueIndexes[$indexName] = $indexColumns;
}
}
Expand Down Expand Up @@ -256,13 +255,7 @@ protected function findConstraints(TableSchemaInterface $table): void
* @psalm-var array{referenced_table_name: string, columns: array} $constraint
*/
foreach ($constraints as $name => $constraint) {
$table->foreignKey(
$name,
array_merge(
[$constraint['referenced_table_name']],
$constraint['columns']
),
);
$table->foreignKey($name, [$constraint['referenced_table_name'], ...$constraint['columns']]);
}
}

Expand Down Expand Up @@ -361,12 +354,10 @@ protected function findViewNames(string $schema = ''): array
* @param string $name The table name.
*
* @return array The cache key.
*
* @psalm-suppress DeprecatedMethod
*/
protected function getCacheKey(string $name): array
{
return array_merge([self::class], $this->generateCacheKey(), [$this->db->getQuoter()->getRawTableName($name)]);
return [self::class, ...$this->generateCacheKey(), $this->db->getQuoter()->getRawTableName($name)];
}

/**
Expand All @@ -378,7 +369,7 @@ protected function getCacheKey(string $name): array
*/
protected function getCacheTag(): string
{
return md5(serialize(array_merge([self::class], $this->generateCacheKey())));
return md5(serialize([self::class, ...$this->generateCacheKey()]));
}

/**
Expand Down Expand Up @@ -585,7 +576,7 @@ private function loadTableConstraints(string $tableName, string $returnType): ar
])->queryAll();

/** @psalm-var array[][] $constraints */
$constraints = array_map('array_change_key_case', $constraints);
$constraints = array_map(array_change_key_case(...), $constraints);
$constraints = DbArrayHelper::index($constraints, null, ['type', 'name']);

$result = [
Expand Down Expand Up @@ -700,7 +691,7 @@ protected function loadTableIndexes(string $tableName): array
])->queryAll();

/** @psalm-var array[] $indexes */
$indexes = array_map('array_change_key_case', $indexes);
$indexes = array_map(array_change_key_case(...), $indexes);
$indexes = DbArrayHelper::index($indexes, null, ['name']);
$result = [];

Expand Down
20 changes: 20 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public function testTransactionIsolation(): void

/* should not be any exception so far */
$this->assertTrue(true);

$db->close();
}

/**
Expand Down Expand Up @@ -119,5 +121,23 @@ static function (ConnectionInterface $db) {
)->queryScalar();

$this->assertSame('1', $profilesCount, 'profile should be inserted in transaction shortcut');

$db->close();
}

/** @link https://github.com/yiisoft/db-mysql/issues/348 */
public function testRestartConnectionOnTimeout(): void
{
$db = $this->getConnection();

$db->createCommand('SET SESSION wait_timeout = 1')->execute();

sleep(1);

$result = $db->createCommand("SELECT '1'")->queryScalar();

$this->assertSame('1', $result);

$db->close();
}
}
2 changes: 1 addition & 1 deletion tests/DeadLockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private function childrenUpdateLocked(): int
*/
private function setErrorHandler(): void
{
set_error_handler(static function ($errno, $errstr, $errfile, $errline) {
set_error_handler(static function ($errno, $errstr, $errfile, $errline): never {
throw new ErrorException($errstr, $errno, $errno, $errfile, $errline);
});
}
Expand Down
28 changes: 13 additions & 15 deletions tests/Provider/ColumnSchemaBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,23 @@ public static function types(): array
$types[1][0] = 'integer(10) UNSIGNED';
$types[2][0] = 'integer(10) COMMENT \'test\'';

return array_merge(
$types,
[
['integer UNSIGNED', SchemaInterface::TYPE_INTEGER, null, [['unsigned']]],
return [
...$types,
['integer UNSIGNED', SchemaInterface::TYPE_INTEGER, null, [['unsigned']]],

/**
* {@link https://github.com/yiisoft/yii2/issues/11945}, real test against database.
*/
/**
* {@link https://github.com/yiisoft/yii2/issues/11945}, real test against database.
*/
[
'string(50) NOT NULL COMMENT \'Property name\' COLLATE ascii_general_ci',
SchemaInterface::TYPE_STRING, 50,
[
'string(50) NOT NULL COMMENT \'Property name\' COLLATE ascii_general_ci',
SchemaInterface::TYPE_STRING, 50,
[
['comment', 'Property name'],
['append', 'COLLATE ascii_general_ci'],
['notNull'],
],
['comment', 'Property name'],
['append', 'COLLATE ascii_general_ci'],
['notNull'],
],
],
);
];
}

public static function createColumnTypes(): array
Expand Down
Loading

0 comments on commit aeba17d

Please sign in to comment.