public findUniqueIndexes ( yii\db\TableSchema $table ) : array | ||
$table | yii\db\TableSchema | the table metadata |
return | array | all unique indexes for the given table. |
public function findUniqueIndexes($table)
{
$sql = 'PRAGMA index_list(' . $this->quoteSimpleTableName($table->name) . ')';
$indexes = $this->db->createCommand($sql)->queryAll();
$uniqueIndexes = [];
foreach ($indexes as $index) {
$indexName = $index['name'];
$indexInfo = $this->db->createCommand('PRAGMA index_info(' . $this->quoteValue($index['name']) . ')')->queryAll();
if ($index['unique']) {
$uniqueIndexes[$indexName] = [];
foreach ($indexInfo as $row) {
$uniqueIndexes[$indexName][] = $row['name'];
}
}
}
return $uniqueIndexes;
}