Skip to content

Commit e82d755

Browse files
Remove src\TestSupport\TestSchemaTrait from yiisoft\db. (#154)
* Remove src\TestSupport\TestSchemaTrait from yiisoft\db.
1 parent 6554fca commit e82d755

4 files changed

Lines changed: 508 additions & 450 deletions

File tree

src/Schema.php

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ protected function loadTablePrimaryKey(string $tableName): Constraint|null
192192
protected function loadTableForeignKeys(string $tableName): array
193193
{
194194
$result = [];
195-
/** @psalm-var PragmaForeignKeyList */
195+
/** @psalm-var PragmaForeignKeyList $foreignKeysList */
196196
$foreignKeysList = $this->getPragmaForeignKeyList($tableName);
197-
/** @psalm-var NormalizePragmaForeignKeyList */
197+
/** @psalm-var NormalizePragmaForeignKeyList $foreignKeysList */
198198
$foreignKeysList = $this->normalizeRowKeyCase($foreignKeysList, true);
199-
/** @psalm-var NormalizePragmaForeignKeyList */
199+
/** @psalm-var NormalizePragmaForeignKeyList $foreignKeysList */
200200
$foreignKeysList = ArrayHelper::index($foreignKeysList, null, 'table');
201201
ArraySorter::multisort($foreignKeysList, 'seq', SORT_ASC, SORT_NUMERIC);
202202

@@ -344,7 +344,7 @@ public function createColumnSchemaBuilder(string $type, array|int|string $length
344344
*/
345345
protected function findColumns(TableSchemaInterface $table): bool
346346
{
347-
/** @psalm-var PragmaTableInfo */
347+
/** @psalm-var PragmaTableInfo $columns */
348348
$columns = $this->getPragmaTableInfo($table->getName());
349349

350350
foreach ($columns as $info) {
@@ -375,7 +375,7 @@ protected function findColumns(TableSchemaInterface $table): bool
375375
*/
376376
protected function findConstraints(TableSchemaInterface $table): void
377377
{
378-
/** @psalm-var PragmaForeignKeyList */
378+
/** @psalm-var PragmaForeignKeyList $foreignKeysList */
379379
$foreignKeysList = $this->getPragmaForeignKeyList($table->getName());
380380

381381
foreach ($foreignKeysList as $foreignKey) {
@@ -411,13 +411,13 @@ protected function findConstraints(TableSchemaInterface $table): void
411411
*/
412412
public function findUniqueIndexes(TableSchemaInterface $table): array
413413
{
414-
/** @psalm-var PragmaIndexList */
414+
/** @psalm-var PragmaIndexList $indexList */
415415
$indexList = $this->getPragmaIndexList($table->getName());
416416
$uniqueIndexes = [];
417417

418418
foreach ($indexList as $index) {
419419
$indexName = $index['name'];
420-
/** @psalm-var PragmaIndexInfo */
420+
/** @psalm-var PragmaIndexInfo $indexInfo */
421421
$indexInfo = $this->getPragmaIndexInfo($index['name']);
422422

423423
if ($index['unique']) {
@@ -431,6 +431,14 @@ public function findUniqueIndexes(TableSchemaInterface $table): array
431431
return $uniqueIndexes;
432432
}
433433

434+
/**
435+
* @throws NotSupportedException
436+
*/
437+
public function getSchemaDefaultValues(string $schema = '', bool $refresh = false): array
438+
{
439+
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
440+
}
441+
434442
/**
435443
* Loads the column information into a {@see ColumnSchemaInterface} object.
436444
*
@@ -504,7 +512,7 @@ protected function loadColumnSchema(array $info): ColumnSchemaInterface
504512
private function loadTableColumnsInfo(string $tableName): array
505513
{
506514
$tableColumns = $this->getPragmaTableInfo($tableName);
507-
/** @psalm-var PragmaTableInfo */
515+
/** @psalm-var PragmaTableInfo $tableColumns */
508516
$tableColumns = $this->normalizeRowKeyCase($tableColumns, true);
509517

510518
return ArrayHelper::index($tableColumns, 'cid');
@@ -557,9 +565,9 @@ private function loadTableConstraints(string $tableName, string $returnType): Co
557565
/**
558566
* Additional check for PK in case of INTEGER PRIMARY KEY with ROWID.
559567
*
560-
* {@See https://www.sqlite.org/lang_createtable.html#primkeyconst}
568+
* {@link https://www.sqlite.org/lang_createtable.html#primkeyconst}
561569
*
562-
* @psalm-var PragmaTableInfo
570+
* @psalm-var PragmaTableInfo $tableColumns
563571
*/
564572
$tableColumns = $this->loadTableColumnsInfo($tableName);
565573

@@ -608,15 +616,17 @@ private function getPragmaIndexInfo(string $name): array
608616
$column = $this->db
609617
->createCommand('PRAGMA INDEX_INFO(' . (string) $this->db->getQuoter()->quoteValue($name) . ')')
610618
->queryAll();
611-
/** @psalm-var Column */
619+
/** @psalm-var Column $column */
612620
$column = $this->normalizeRowKeyCase($column, true);
613621
ArraySorter::multisort($column, 'seqno', SORT_ASC, SORT_NUMERIC);
614622

615623
return $column;
616624
}
617625

618626
/**
619-
* @throws Exception|InvalidConfigException|Throwable
627+
* @throws Exception
628+
* @throws InvalidConfigException
629+
* @throws Throwable
620630
*/
621631
private function getPragmaIndexList(string $tableName): array
622632
{
@@ -635,6 +645,27 @@ private function getPragmaTableInfo(string $tableName): array
635645
)->queryAll();
636646
}
637647

648+
/**
649+
* @throws Exception
650+
* @throws InvalidConfigException
651+
* @throws Throwable
652+
*/
653+
protected function findViewNames(string $schema = ''): array
654+
{
655+
/** @psalm-var string[][] $views */
656+
$views = $this->db->createCommand(
657+
<<<SQL
658+
SELECT name as view FROM sqlite_master WHERE type = 'view' AND name NOT LIKE 'sqlite_%'
659+
SQL,
660+
)->queryAll();
661+
662+
foreach ($views as $key => $view) {
663+
$views[$key] = $view['view'];
664+
}
665+
666+
return $views;
667+
}
668+
638669
/**
639670
* Returns the cache key for the specified table name.
640671
*

0 commit comments

Comments
 (0)