Skip to content
Open
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 @@ -33,4 +33,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0']
['8.1']
1 change: 0 additions & 1 deletion .github/workflows/mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
- ubuntu-latest

php:
- 8.0
- 8.1
- 8.2

Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,18 @@ jobs:
- ubuntu-latest

php:
- 8.0
- 8.1
- 8.2

mssql:
- server:2019-latest
- server:2022-latest
- server:2019-CU27-ubuntu-20.04
# - server:2022-latest

services:
mssql:
image: mcr.microsoft.com/mssql/${{ matrix.mssql }}
env:
SA_PASSWORD: YourStrong!Passw0rd
MSSQL_SA_PASSWORD: YourStrong!Passw0rd
ACCEPT_EULA: Y
MSSQL_PID: Developer
ports:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ jobs:

- name: Run infection.
run: |
vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ignore-msi-with-no-mutations --only-covered --test-framework-options="--testsuite=Pgsql"
vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ignore-msi-with-no-mutations --test-framework-options="--testsuite=Pgsql"
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
1 change: 0 additions & 1 deletion .github/workflows/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
- ubuntu-latest

php:
- 8.0
- 8.1
- 8.2

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
- ubuntu-latest

php:
- 8.0
- 8.1
- 8.2

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
- ubuntu-latest

php:
- 8.0
- 8.1
- 8.2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0']
['8.4']
3 changes: 2 additions & 1 deletion .github/workflows/sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ jobs:
- windows-latest

php:
- 8.0
- 8.1
- 8.2
- 8.3
- 8.4

steps:
- name: Checkout.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: composer self-update

- name: Install dependencies with composer.
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
run: composer require yiisoft/db-sqlite --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Static analysis,
run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle --php-version=${{ matrix.php }} | cs2pr --graceful-warnings --colorize
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 1.0.1 under development

- no changes in this release.
- Chg #88: Adapt to `yiisoft/db:2.0` changes, change supported version of `yiisoft/db` to `^2.0` (@batyrmastyr)
- Chg #88: Change supported PHP versions to `8.1 - 8.5` (@batyrmastyr)
- Chg #88: More correct types to pass static analysis (@batyrmastyr)

1.0.0 May 09, 2023
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
}
],
"require": {
"php": "^8.0",
"php": "8.1 - 8.4",
"ext-pdo": "*",
"psr/log": "^2.0|^3.0",
"psr/simple-cache": "^2.0|^3.0",
"yiisoft/db": "^1.0"
"yiisoft/db": "^2.0"
},
"suggest": {
"yiisoft/log": "^2.0"
Expand All @@ -45,7 +45,7 @@
"rector/rector": "^2.0.3",
"roave/infection-static-analysis-plugin": "^1.25|^1.30",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.22",
"vimeo/psalm": "^4.30|^5.22|^6.13.1",
"yiisoft/cache": "^3.0",
"yiisoft/log": "^2.0"
},
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
<MissingOverrideAttribute errorLevel="suppress" />
<RiskyTruthyFalsyComparison errorLevel="suppress" />
</issueHandlers>
</psalm>
6 changes: 3 additions & 3 deletions src/DbCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use Psr\SimpleCache\InvalidArgumentException;
use Throwable;
use Traversable;
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Expression\Value\Param;
use Yiisoft\Db\Query\Query;

use function array_fill_keys;
Expand Down Expand Up @@ -174,7 +174,7 @@ public function setMultiple(iterable $values, DateInterval|int|string|null $ttl
if (!empty($rows) && !$this->isExpiredTtl($ttl)) {
$this->db
->createCommand()
->batchInsert($this->table, ['id', 'expire', 'data'], $rows)
->insertBatch($this->table, $rows, ['id', 'expire', 'data'])
->execute();
}

Expand Down Expand Up @@ -228,7 +228,7 @@ public function setLoggerMessageUpdate(string $value): void
* Gets the cache data from the database.
*
* @param array|string $id One or more IDs for deleting data.
* @param array $fields Selectable fields.
* @param string[] $fields Selectable fields.
* @param string $method Method of the returned data ("all", "scalar", "exists").
*
* @return mixed The cache data.
Expand Down
23 changes: 10 additions & 13 deletions src/DbSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Schema\SchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnBuilder;

/**
* Manages the cache table schema in the database.
Expand All @@ -32,19 +32,17 @@ public function __construct(private ConnectionInterface $db)
*/
public function ensureTable(string $table = '{{%yii_cache}}'): void
{
$schema = $this->db->getSchema();
$tableRawName = $schema->getRawTableName($table);

if ($this->hasTable($table)) {
$tableRawName = $this->db->getQuoter()->getRawTableName($table);
if ($this->hasTable($tableRawName)) {
return;
}

$this->db->createCommand()->createTable(
$table,
[
'id' => $schema->createColumn(SchemaInterface::TYPE_STRING, 128)->notNull(),
'data' => $schema->createColumn(SchemaInterface::TYPE_BINARY),
'expire' => $schema->createColumn(SchemaInterface::TYPE_INTEGER),
'id' => ColumnBuilder::string(128)->notNull(),
'data' => ColumnBuilder::binary(),
'expire' => ColumnBuilder::integer(),
"CONSTRAINT [[PK_$tableRawName]] PRIMARY KEY ([[id]])",
],
)->execute();
Expand All @@ -61,10 +59,9 @@ public function ensureTable(string $table = '{{%yii_cache}}'): void
*/
public function ensureNoTable(string $table = '{{%yii_cache}}'): void
{
$tableRawName = $this->db->getSchema()->getRawTableName($table);

if ($this->hasTable($table)) {
$this->db->createCommand()->dropTable($tableRawName)->execute();
$rawTableName = $this->db->getQuoter()->getRawTableName($table);
if ($this->hasTable($rawTableName)) {
$this->db->createCommand()->dropTable($rawTableName)->execute();
}
}

Expand All @@ -77,6 +74,6 @@ public function ensureNoTable(string $table = '{{%yii_cache}}'): void
*/
private function hasTable(string $table): bool
{
return $this->db->getTableSchema($table, true) !== null;
return $this->db->getSchema()->hasTable($table, refresh: true);
}
}
21 changes: 10 additions & 11 deletions tests/Common/AbstractDbSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
use Yiisoft\Cache\Db\DbCache;
use Yiisoft\Cache\Db\DbSchemaManager;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Constraint\IndexConstraint;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Schema\SchemaInterface;

/**
* @group Mssql
Expand Down Expand Up @@ -99,12 +98,12 @@ public function testVerifyTableIndexes(string $table): void

$schema = $this->db->getSchema();

/** @psalm-var IndexConstraint[] $indexes */
$indexes = $schema->getTableIndexes($dbCache->getTable(), true);
$index = $schema->getTablePrimaryKey($dbCache->getTable(), true);

$this->assertSame(['id'], $indexes[0]->getColumnNames());
$this->assertTrue($indexes[0]->isUnique());
$this->assertTrue($indexes[0]->isPrimary());
$this->assertNotNull($index);
$this->assertSame(['id'], $index->columnNames);
$this->assertTrue($index->isUnique);
$this->assertTrue($index->isPrimaryKey);

$this->dbSchemaManager->ensureNoTable($dbCache->getTable());

Expand All @@ -126,17 +125,17 @@ public function testVerifyTableStructure(string $table): void
$this->dbSchemaManager->ensureTable($dbCache->getTable());

$tableSchema = $this->db->getTableSchema($dbCache->getTable());
$tableRawName = $this->db->getSchema()->getRawTableName($dbCache->getTable());
$tableRawName = $this->db->getQuoter()->getRawTableName($dbCache->getTable());

$this->assertNotNull($tableSchema);

$this->assertSame($tableRawName, $tableSchema->getName());
$this->assertSame(['id'], $tableSchema->getPrimaryKey());
$this->assertSame(['id', 'data', 'expire'], $tableSchema->getColumnNames());
$this->assertSame(SchemaInterface::TYPE_STRING, $tableSchema->getColumn('id')?->getType());
$this->assertSame(ColumnType::STRING, $tableSchema->getColumn('id')?->getType());
$this->assertSame(128, $tableSchema->getColumn('id')?->getSize());
$this->assertSame(SchemaInterface::TYPE_BINARY, $tableSchema->getColumn('data')?->getType());
$this->assertSame(SchemaInterface::TYPE_INTEGER, $tableSchema->getColumn('expire')?->getType());
$this->assertSame(ColumnType::BINARY, $tableSchema->getColumn('data')?->getType());
$this->assertSame(ColumnType::INTEGER, $tableSchema->getColumn('expire')?->getType());

$this->dbSchemaManager->ensureNoTable($dbCache->getTable());

Expand Down
21 changes: 10 additions & 11 deletions tests/Common/AbstractSQLDumpFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
use Throwable;
use Yiisoft\Cache\Db\DbCache;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Constraint\IndexConstraint;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Schema\SchemaInterface;

/**
* @group Mssql
Expand Down Expand Up @@ -71,12 +70,12 @@ public function testVerifyTableIndexes(): void

$schema = $this->db->getSchema();

/** @psalm-var IndexConstraint[] $indexes */
$indexes = $schema->getTableIndexes($dbCache->getTable(), true);
$index = $schema->getTablePrimaryKey($dbCache->getTable(), true);

$this->assertSame(['id'], $indexes[0]->getColumnNames());
$this->assertTrue($indexes[0]->isUnique());
$this->assertTrue($indexes[0]->isPrimary());
$this->assertNotNull($index);
$this->assertSame(['id'], $index->columnNames);
$this->assertTrue($index->isPrimaryKey);
$this->assertTrue($index->isUnique);

$this->loadFromSQLDumpFile(dirname(__DIR__, 2) . "/sql/$this->driverName-down.sql");

Expand All @@ -96,17 +95,17 @@ public function testVerifyTableStructure(): void
$this->loadFromSQLDumpFile(dirname(__DIR__, 2) . "/sql/$this->driverName-up.sql");

$tableSchema = $this->db->getTableSchema($dbCache->getTable());
$tableRawName = $this->db->getSchema()->getRawTableName($dbCache->getTable());
$tableRawName = $this->db->getQuoter()->getRawTableName($dbCache->getTable());

$this->assertNotNull($tableSchema);

$this->assertSame($tableRawName, $tableSchema->getName());
$this->assertSame(['id'], $tableSchema->getPrimaryKey());
$this->assertSame(['id', 'data', 'expire'], $tableSchema->getColumnNames());
$this->assertSame(SchemaInterface::TYPE_STRING, $tableSchema->getColumn('id')?->getType());
$this->assertSame(ColumnType::STRING, $tableSchema->getColumn('id')?->getType());
$this->assertSame(128, $tableSchema->getColumn('id')?->getSize());
$this->assertSame(SchemaInterface::TYPE_BINARY, $tableSchema->getColumn('data')?->getType());
$this->assertSame(SchemaInterface::TYPE_INTEGER, $tableSchema->getColumn('expire')?->getType());
$this->assertSame(ColumnType::BINARY, $tableSchema->getColumn('data')?->getType());
$this->assertSame(ColumnType::INTEGER, $tableSchema->getColumn('expire')?->getType());

$this->loadFromSQLDumpFile(dirname(__DIR__, 2) . "/sql/$this->driverName-down.sql");

Expand Down
2 changes: 1 addition & 1 deletion tests/Support/MssqlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class MssqlFactory extends ConnectionFactory
public function createConnection(): ConnectionInterface
{
$pdoDriver = new Driver(
(new Dsn('sqlsrv', 'localhost', 'yiitest'))->asString(),
(new Dsn('sqlsrv', 'localhost', 'yiitest'))->__toString(),
'SA',
'YourStrong!Passw0rd',
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/MysqlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class MysqlFactory extends ConnectionFactory
public function createConnection(): ConnectionInterface
{
$pdoDriver = new Driver(
(new Dsn('mysql', '127.0.0.1', 'yiitest', '3306', ['charset' => 'utf8mb4']))->asString(),
(new Dsn('mysql', '127.0.0.1', 'yiitest', '3306', ['charset' => 'utf8mb4']))->__toString(),
'root',
'',
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/OracleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class OracleFactory extends ConnectionFactory
public function createConnection(): ConnectionInterface
{
$pdoDriver = new Driver(
(new Dsn('oci', 'localhost', 'XE', '1521', ['charset' => 'AL32UTF8']))->asString(),
(new Dsn('oci', 'localhost', 'XE', '1521', ['charset' => 'AL32UTF8']))->__toString(),
'system',
'root'
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/PgsqlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class PgsqlFactory extends ConnectionFactory
public function createConnection(): ConnectionInterface
{
$pdoDriver = new Driver(
(new Dsn('pgsql', '127.0.0.1', 'yiitest', '5432'))->asString(),
(new Dsn('pgsql', '127.0.0.1', 'yiitest', '5432'))->__toString(),
'root',
'root',
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/SqliteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class SqliteFactory extends ConnectionFactory
{
public function createConnection(): ConnectionInterface
{
$pdoDriver = new Driver((new Dsn('sqlite', __DIR__ . '/runtime/yiitest.sq3'))->asString());
$pdoDriver = new Driver((new Dsn('sqlite', __DIR__ . '/runtime/yiitest.sq3'))->__toString());

return new Connection($pdoDriver, $this->createSchemaCache());
}
Expand Down
Loading