Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve deprecated methods #287

Merged
merged 5 commits into from
Feb 10, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Enh #282: Change property `Schema::$typeMap` to constant `Schema::TYPE_MAP` (@Tigrov)
- Enh #283: Remove unnecessary check for array type in `Schema::loadTableIndexes()` (@Tigrov)
- Enh #288: Minor refactoring of `DDLQueryBuilder` and `Schema` (@Tigrov)
- Enh #287: Resolve deprecated methods (@Tigrov)

## 1.1.0 November 12, 2023

Expand Down
17 changes: 13 additions & 4 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Yiisoft\Db\Schema\TableSchemaInterface;

use function array_column;
use function array_map;
use function array_merge;
use function count;
use function explode;
Expand Down Expand Up @@ -201,7 +202,7 @@ protected function loadTableForeignKeys(string $tableName): array

$foreignKeysList = $this->getPragmaForeignKeyList($tableName);
/** @psalm-var ForeignKeyInfo[] $foreignKeysList */
$foreignKeysList = $this->normalizeRowKeyCase($foreignKeysList, true);
$foreignKeysList = array_map('array_change_key_case', $foreignKeysList);
$foreignKeysList = DbArrayHelper::index($foreignKeysList, null, ['table']);
DbArrayHelper::multisort($foreignKeysList, 'seq');

Expand Down Expand Up @@ -553,7 +554,7 @@ private function loadTableColumnsInfo(string $tableName): array
{
$tableColumns = $this->getPragmaTableInfo($tableName);
/** @psalm-var ColumnInfo[] $tableColumns */
$tableColumns = $this->normalizeRowKeyCase($tableColumns, true);
$tableColumns = array_map('array_change_key_case', $tableColumns);

/** @psalm-var ColumnInfo[] */
return DbArrayHelper::index($tableColumns, 'cid');
Expand All @@ -575,7 +576,7 @@ private function loadTableConstraints(string $tableName, string $returnType): Co
{
$indexList = $this->getPragmaIndexList($tableName);
/** @psalm-var IndexListInfo[] $indexes */
$indexes = $this->normalizeRowKeyCase($indexList, true);
$indexes = array_map('array_change_key_case', $indexList);
$result = [
self::PRIMARY_KEY => null,
self::INDEXES => [],
Expand Down Expand Up @@ -642,9 +643,12 @@ private function createColumnSchema(string $name): ColumnSchemaInterface
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
*
* @psalm-return ForeignKeyInfo[]
*/
private function getPragmaForeignKeyList(string $tableName): array
{
/** @psalm-var ForeignKeyInfo[] */
return $this->db->createCommand(
'PRAGMA FOREIGN_KEY_LIST(' . $this->db->getQuoter()->quoteSimpleTableName($tableName) . ')'
)->queryAll();
Expand All @@ -662,7 +666,7 @@ private function getPragmaIndexInfo(string $name): array
$column = $this->db
->createCommand('PRAGMA INDEX_INFO(' . (string) $this->db->getQuoter()->quoteValue($name) . ')')
->queryAll();
$column = $this->normalizeRowKeyCase($column, true);
$column = array_map('array_change_key_case', $column);
DbArrayHelper::multisort($column, 'seqno');

/** @psalm-var IndexInfo[] $column */
Expand All @@ -673,9 +677,12 @@ private function getPragmaIndexInfo(string $name): array
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
*
* @psalm-return IndexListInfo[]
*/
private function getPragmaIndexList(string $tableName): array
{
/** @psalm-var IndexListInfo[] */
return $this->db
->createCommand('PRAGMA INDEX_LIST(' . (string) $this->db->getQuoter()->quoteValue($tableName) . ')')
->queryAll();
Expand Down Expand Up @@ -723,6 +730,8 @@ 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
{
Expand Down
4 changes: 2 additions & 2 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ public function testWorkWithPrimaryKeyConstraint(): void
public function testNotConnectionPDO(): void
{
$db = $this->createMock(ConnectionInterface::class);
$schema = new Schema($db, DbHelper::getSchemaCache(), 'system');
$schema = new Schema($db, DbHelper::getSchemaCache());

$this->expectException(NotSupportedException::class);
$this->expectExceptionMessage('Only PDO connections are supported.');

$schema->refreshTableSchema('customer');
$schema->refresh();
}
}
Loading