Schema.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\db\mysql;
  8. use yii\base\InvalidConfigException;
  9. use yii\base\NotSupportedException;
  10. use yii\db\Constraint;
  11. use yii\db\ConstraintFinderInterface;
  12. use yii\db\ConstraintFinderTrait;
  13. use yii\db\Exception;
  14. use yii\db\Expression;
  15. use yii\db\ForeignKeyConstraint;
  16. use yii\db\IndexConstraint;
  17. use yii\db\TableSchema;
  18. use yii\helpers\ArrayHelper;
  19. /**
  20. * Schema is the class for retrieving metadata from a MySQL database (version 4.1.x and 5.x).
  21. *
  22. * @author Qiang Xue <qiang.xue@gmail.com>
  23. * @since 2.0
  24. */
  25. class Schema extends \yii\db\Schema implements ConstraintFinderInterface
  26. {
  27. use ConstraintFinderTrait;
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public $columnSchemaClass = 'yii\db\mysql\ColumnSchema';
  32. /**
  33. * @var bool whether MySQL used is older than 5.1.
  34. */
  35. private $_oldMysql;
  36. /**
  37. * @var array mapping from physical column types (keys) to abstract column types (values)
  38. */
  39. public $typeMap = [
  40. 'tinyint' => self::TYPE_TINYINT,
  41. 'bit' => self::TYPE_INTEGER,
  42. 'smallint' => self::TYPE_SMALLINT,
  43. 'mediumint' => self::TYPE_INTEGER,
  44. 'int' => self::TYPE_INTEGER,
  45. 'integer' => self::TYPE_INTEGER,
  46. 'bigint' => self::TYPE_BIGINT,
  47. 'float' => self::TYPE_FLOAT,
  48. 'double' => self::TYPE_DOUBLE,
  49. 'real' => self::TYPE_FLOAT,
  50. 'decimal' => self::TYPE_DECIMAL,
  51. 'numeric' => self::TYPE_DECIMAL,
  52. 'tinytext' => self::TYPE_TEXT,
  53. 'mediumtext' => self::TYPE_TEXT,
  54. 'longtext' => self::TYPE_TEXT,
  55. 'longblob' => self::TYPE_BINARY,
  56. 'blob' => self::TYPE_BINARY,
  57. 'text' => self::TYPE_TEXT,
  58. 'varchar' => self::TYPE_STRING,
  59. 'string' => self::TYPE_STRING,
  60. 'char' => self::TYPE_CHAR,
  61. 'datetime' => self::TYPE_DATETIME,
  62. 'year' => self::TYPE_DATE,
  63. 'date' => self::TYPE_DATE,
  64. 'time' => self::TYPE_TIME,
  65. 'timestamp' => self::TYPE_TIMESTAMP,
  66. 'enum' => self::TYPE_STRING,
  67. 'varbinary' => self::TYPE_BINARY,
  68. 'json' => self::TYPE_JSON,
  69. ];
  70. /**
  71. * {@inheritdoc}
  72. */
  73. protected $tableQuoteCharacter = '`';
  74. /**
  75. * {@inheritdoc}
  76. */
  77. protected $columnQuoteCharacter = '`';
  78. /**
  79. * {@inheritdoc}
  80. */
  81. protected function resolveTableName($name)
  82. {
  83. $resolvedName = new TableSchema();
  84. $parts = explode('.', str_replace('`', '', $name));
  85. if (isset($parts[1])) {
  86. $resolvedName->schemaName = $parts[0];
  87. $resolvedName->name = $parts[1];
  88. } else {
  89. $resolvedName->schemaName = $this->defaultSchema;
  90. $resolvedName->name = $name;
  91. }
  92. $resolvedName->fullName = ($resolvedName->schemaName !== $this->defaultSchema ? $resolvedName->schemaName . '.' : '') . $resolvedName->name;
  93. return $resolvedName;
  94. }
  95. /**
  96. * {@inheritdoc}
  97. */
  98. protected function findTableNames($schema = '')
  99. {
  100. $sql = 'SHOW TABLES';
  101. if ($schema !== '') {
  102. $sql .= ' FROM ' . $this->quoteSimpleTableName($schema);
  103. }
  104. return $this->db->createCommand($sql)->queryColumn();
  105. }
  106. /**
  107. * {@inheritdoc}
  108. */
  109. protected function loadTableSchema($name)
  110. {
  111. $table = new TableSchema();
  112. $this->resolveTableNames($table, $name);
  113. if ($this->findColumns($table)) {
  114. $this->findConstraints($table);
  115. return $table;
  116. }
  117. return null;
  118. }
  119. /**
  120. * {@inheritdoc}
  121. */
  122. protected function loadTablePrimaryKey($tableName)
  123. {
  124. return $this->loadTableConstraints($tableName, 'primaryKey');
  125. }
  126. /**
  127. * {@inheritdoc}
  128. */
  129. protected function loadTableForeignKeys($tableName)
  130. {
  131. return $this->loadTableConstraints($tableName, 'foreignKeys');
  132. }
  133. /**
  134. * {@inheritdoc}
  135. */
  136. protected function loadTableIndexes($tableName)
  137. {
  138. static $sql = <<<'SQL'
  139. SELECT
  140. `s`.`INDEX_NAME` AS `name`,
  141. `s`.`COLUMN_NAME` AS `column_name`,
  142. `s`.`NON_UNIQUE` ^ 1 AS `index_is_unique`,
  143. `s`.`INDEX_NAME` = 'PRIMARY' AS `index_is_primary`
  144. FROM `information_schema`.`STATISTICS` AS `s`
  145. WHERE `s`.`TABLE_SCHEMA` = COALESCE(:schemaName, DATABASE()) AND `s`.`INDEX_SCHEMA` = `s`.`TABLE_SCHEMA` AND `s`.`TABLE_NAME` = :tableName
  146. ORDER BY `s`.`SEQ_IN_INDEX` ASC
  147. SQL;
  148. $resolvedName = $this->resolveTableName($tableName);
  149. $indexes = $this->db->createCommand($sql, [
  150. ':schemaName' => $resolvedName->schemaName,
  151. ':tableName' => $resolvedName->name,
  152. ])->queryAll();
  153. $indexes = $this->normalizePdoRowKeyCase($indexes, true);
  154. $indexes = ArrayHelper::index($indexes, null, 'name');
  155. $result = [];
  156. foreach ($indexes as $name => $index) {
  157. $result[] = new IndexConstraint([
  158. 'isPrimary' => (bool) $index[0]['index_is_primary'],
  159. 'isUnique' => (bool) $index[0]['index_is_unique'],
  160. 'name' => $name !== 'PRIMARY' ? $name : null,
  161. 'columnNames' => ArrayHelper::getColumn($index, 'column_name'),
  162. ]);
  163. }
  164. return $result;
  165. }
  166. /**
  167. * {@inheritdoc}
  168. */
  169. protected function loadTableUniques($tableName)
  170. {
  171. return $this->loadTableConstraints($tableName, 'uniques');
  172. }
  173. /**
  174. * {@inheritdoc}
  175. * @throws NotSupportedException if this method is called.
  176. */
  177. protected function loadTableChecks($tableName)
  178. {
  179. throw new NotSupportedException('MySQL does not support check constraints.');
  180. }
  181. /**
  182. * {@inheritdoc}
  183. * @throws NotSupportedException if this method is called.
  184. */
  185. protected function loadTableDefaultValues($tableName)
  186. {
  187. throw new NotSupportedException('MySQL does not support default value constraints.');
  188. }
  189. /**
  190. * Creates a query builder for the MySQL database.
  191. * @return QueryBuilder query builder instance
  192. */
  193. public function createQueryBuilder()
  194. {
  195. return new QueryBuilder($this->db);
  196. }
  197. /**
  198. * Resolves the table name and schema name (if any).
  199. * @param TableSchema $table the table metadata object
  200. * @param string $name the table name
  201. */
  202. protected function resolveTableNames($table, $name)
  203. {
  204. $parts = explode('.', str_replace('`', '', $name));
  205. if (isset($parts[1])) {
  206. $table->schemaName = $parts[0];
  207. $table->name = $parts[1];
  208. $table->fullName = $table->schemaName . '.' . $table->name;
  209. } else {
  210. $table->fullName = $table->name = $parts[0];
  211. }
  212. }
  213. /**
  214. * Loads the column information into a [[ColumnSchema]] object.
  215. * @param array $info column information
  216. * @return ColumnSchema the column schema object
  217. */
  218. protected function loadColumnSchema($info)
  219. {
  220. $column = $this->createColumnSchema();
  221. $column->name = $info['field'];
  222. $column->allowNull = $info['null'] === 'YES';
  223. $column->isPrimaryKey = strpos($info['key'], 'PRI') !== false;
  224. $column->autoIncrement = stripos($info['extra'], 'auto_increment') !== false;
  225. $column->comment = $info['comment'];
  226. $column->dbType = $info['type'];
  227. $column->unsigned = stripos($column->dbType, 'unsigned') !== false;
  228. $column->type = self::TYPE_STRING;
  229. if (preg_match('/^(\w+)(?:\(([^\)]+)\))?/', $column->dbType, $matches)) {
  230. $type = strtolower($matches[1]);
  231. if (isset($this->typeMap[$type])) {
  232. $column->type = $this->typeMap[$type];
  233. }
  234. if (!empty($matches[2])) {
  235. if ($type === 'enum') {
  236. preg_match_all("/'[^']*'/", $matches[2], $values);
  237. foreach ($values[0] as $i => $value) {
  238. $values[$i] = trim($value, "'");
  239. }
  240. $column->enumValues = $values;
  241. } else {
  242. $values = explode(',', $matches[2]);
  243. $column->size = $column->precision = (int) $values[0];
  244. if (isset($values[1])) {
  245. $column->scale = (int) $values[1];
  246. }
  247. if ($column->size === 1 && $type === 'bit') {
  248. $column->type = 'boolean';
  249. } elseif ($type === 'bit') {
  250. if ($column->size > 32) {
  251. $column->type = 'bigint';
  252. } elseif ($column->size === 32) {
  253. $column->type = 'integer';
  254. }
  255. }
  256. }
  257. }
  258. }
  259. $column->phpType = $this->getColumnPhpType($column);
  260. if (!$column->isPrimaryKey) {
  261. /**
  262. * When displayed in the INFORMATION_SCHEMA.COLUMNS table, a default CURRENT TIMESTAMP is displayed
  263. * as CURRENT_TIMESTAMP up until MariaDB 10.2.2, and as current_timestamp() from MariaDB 10.2.3.
  264. *
  265. * See details here: https://mariadb.com/kb/en/library/now/#description
  266. */
  267. if (($column->type === 'timestamp' || $column->type === 'datetime') &&
  268. ($info['default'] === 'CURRENT_TIMESTAMP' || $info['default'] === 'current_timestamp()')) {
  269. $column->defaultValue = new Expression('CURRENT_TIMESTAMP');
  270. } elseif (isset($type) && $type === 'bit') {
  271. $column->defaultValue = bindec(trim($info['default'], 'b\''));
  272. } else {
  273. $column->defaultValue = $column->phpTypecast($info['default']);
  274. }
  275. }
  276. return $column;
  277. }
  278. /**
  279. * Collects the metadata of table columns.
  280. * @param TableSchema $table the table metadata
  281. * @return bool whether the table exists in the database
  282. * @throws \Exception if DB query fails
  283. */
  284. protected function findColumns($table)
  285. {
  286. $sql = 'SHOW FULL COLUMNS FROM ' . $this->quoteTableName($table->fullName);
  287. try {
  288. $columns = $this->db->createCommand($sql)->queryAll();
  289. } catch (\Exception $e) {
  290. $previous = $e->getPrevious();
  291. if ($previous instanceof \PDOException && strpos($previous->getMessage(), 'SQLSTATE[42S02') !== false) {
  292. // table does not exist
  293. // https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html#error_er_bad_table_error
  294. return false;
  295. }
  296. throw $e;
  297. }
  298. foreach ($columns as $info) {
  299. if ($this->db->slavePdo->getAttribute(\PDO::ATTR_CASE) !== \PDO::CASE_LOWER) {
  300. $info = array_change_key_case($info, CASE_LOWER);
  301. }
  302. $column = $this->loadColumnSchema($info);
  303. $table->columns[$column->name] = $column;
  304. if ($column->isPrimaryKey) {
  305. $table->primaryKey[] = $column->name;
  306. if ($column->autoIncrement) {
  307. $table->sequenceName = '';
  308. }
  309. }
  310. }
  311. return true;
  312. }
  313. /**
  314. * Gets the CREATE TABLE sql string.
  315. * @param TableSchema $table the table metadata
  316. * @return string $sql the result of 'SHOW CREATE TABLE'
  317. */
  318. protected function getCreateTableSql($table)
  319. {
  320. $row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->quoteTableName($table->fullName))->queryOne();
  321. if (isset($row['Create Table'])) {
  322. $sql = $row['Create Table'];
  323. } else {
  324. $row = array_values($row);
  325. $sql = $row[1];
  326. }
  327. return $sql;
  328. }
  329. /**
  330. * Collects the foreign key column details for the given table.
  331. * @param TableSchema $table the table metadata
  332. * @throws \Exception
  333. */
  334. protected function findConstraints($table)
  335. {
  336. $sql = <<<'SQL'
  337. SELECT
  338. kcu.constraint_name,
  339. kcu.column_name,
  340. kcu.referenced_table_name,
  341. kcu.referenced_column_name
  342. FROM information_schema.referential_constraints AS rc
  343. JOIN information_schema.key_column_usage AS kcu ON
  344. (
  345. kcu.constraint_catalog = rc.constraint_catalog OR
  346. (kcu.constraint_catalog IS NULL AND rc.constraint_catalog IS NULL)
  347. ) AND
  348. kcu.constraint_schema = rc.constraint_schema AND
  349. kcu.constraint_name = rc.constraint_name
  350. WHERE rc.constraint_schema = database() AND kcu.table_schema = database()
  351. AND rc.table_name = :tableName AND kcu.table_name = :tableName1
  352. SQL;
  353. try {
  354. $rows = $this->db->createCommand($sql, [':tableName' => $table->name, ':tableName1' => $table->name])->queryAll();
  355. $constraints = [];
  356. foreach ($rows as $row) {
  357. $constraints[$row['constraint_name']]['referenced_table_name'] = $row['referenced_table_name'];
  358. $constraints[$row['constraint_name']]['columns'][$row['column_name']] = $row['referenced_column_name'];
  359. }
  360. $table->foreignKeys = [];
  361. foreach ($constraints as $name => $constraint) {
  362. $table->foreignKeys[$name] = array_merge(
  363. [$constraint['referenced_table_name']],
  364. $constraint['columns']
  365. );
  366. }
  367. } catch (\Exception $e) {
  368. $previous = $e->getPrevious();
  369. if (!$previous instanceof \PDOException || strpos($previous->getMessage(), 'SQLSTATE[42S02') === false) {
  370. throw $e;
  371. }
  372. // table does not exist, try to determine the foreign keys using the table creation sql
  373. $sql = $this->getCreateTableSql($table);
  374. $regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+([^\(^\s]+)\s*\(([^\)]+)\)/mi';
  375. if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) {
  376. foreach ($matches as $match) {
  377. $fks = array_map('trim', explode(',', str_replace('`', '', $match[1])));
  378. $pks = array_map('trim', explode(',', str_replace('`', '', $match[3])));
  379. $constraint = [str_replace('`', '', $match[2])];
  380. foreach ($fks as $k => $name) {
  381. $constraint[$name] = $pks[$k];
  382. }
  383. $table->foreignKeys[md5(serialize($constraint))] = $constraint;
  384. }
  385. $table->foreignKeys = array_values($table->foreignKeys);
  386. }
  387. }
  388. }
  389. /**
  390. * Returns all unique indexes for the given table.
  391. *
  392. * Each array element is of the following structure:
  393. *
  394. * ```php
  395. * [
  396. * 'IndexName1' => ['col1' [, ...]],
  397. * 'IndexName2' => ['col2' [, ...]],
  398. * ]
  399. * ```
  400. *
  401. * @param TableSchema $table the table metadata
  402. * @return array all unique indexes for the given table.
  403. */
  404. public function findUniqueIndexes($table)
  405. {
  406. $sql = $this->getCreateTableSql($table);
  407. $uniqueIndexes = [];
  408. $regexp = '/UNIQUE KEY\s+\`(.+)\`\s*\((\`.+\`)+\)/mi';
  409. if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) {
  410. foreach ($matches as $match) {
  411. $indexName = $match[1];
  412. $indexColumns = array_map('trim', explode('`,`', trim($match[2], '`')));
  413. $uniqueIndexes[$indexName] = $indexColumns;
  414. }
  415. }
  416. return $uniqueIndexes;
  417. }
  418. /**
  419. * {@inheritdoc}
  420. */
  421. public function createColumnSchemaBuilder($type, $length = null)
  422. {
  423. return new ColumnSchemaBuilder($type, $length, $this->db);
  424. }
  425. /**
  426. * @return bool whether the version of the MySQL being used is older than 5.1.
  427. * @throws InvalidConfigException
  428. * @throws Exception
  429. * @since 2.0.13
  430. */
  431. protected function isOldMysql()
  432. {
  433. if ($this->_oldMysql === null) {
  434. $version = $this->db->getSlavePdo()->getAttribute(\PDO::ATTR_SERVER_VERSION);
  435. $this->_oldMysql = version_compare($version, '5.1', '<=');
  436. }
  437. return $this->_oldMysql;
  438. }
  439. /**
  440. * Loads multiple types of constraints and returns the specified ones.
  441. * @param string $tableName table name.
  442. * @param string $returnType return type:
  443. * - primaryKey
  444. * - foreignKeys
  445. * - uniques
  446. * @return mixed constraints.
  447. */
  448. private function loadTableConstraints($tableName, $returnType)
  449. {
  450. static $sql = <<<'SQL'
  451. SELECT
  452. `kcu`.`CONSTRAINT_NAME` AS `name`,
  453. `kcu`.`COLUMN_NAME` AS `column_name`,
  454. `tc`.`CONSTRAINT_TYPE` AS `type`,
  455. CASE
  456. WHEN :schemaName IS NULL AND `kcu`.`REFERENCED_TABLE_SCHEMA` = DATABASE() THEN NULL
  457. ELSE `kcu`.`REFERENCED_TABLE_SCHEMA`
  458. END AS `foreign_table_schema`,
  459. `kcu`.`REFERENCED_TABLE_NAME` AS `foreign_table_name`,
  460. `kcu`.`REFERENCED_COLUMN_NAME` AS `foreign_column_name`,
  461. `rc`.`UPDATE_RULE` AS `on_update`,
  462. `rc`.`DELETE_RULE` AS `on_delete`,
  463. `kcu`.`ORDINAL_POSITION` AS `position`
  464. FROM
  465. `information_schema`.`KEY_COLUMN_USAGE` AS `kcu`,
  466. `information_schema`.`REFERENTIAL_CONSTRAINTS` AS `rc`,
  467. `information_schema`.`TABLE_CONSTRAINTS` AS `tc`
  468. WHERE
  469. `kcu`.`TABLE_SCHEMA` = COALESCE(:schemaName, DATABASE()) AND `kcu`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `kcu`.`TABLE_NAME` = :tableName
  470. AND `rc`.`CONSTRAINT_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `rc`.`TABLE_NAME` = :tableName AND `rc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME`
  471. AND `tc`.`TABLE_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `tc`.`TABLE_NAME` = :tableName AND `tc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME` AND `tc`.`CONSTRAINT_TYPE` = 'FOREIGN KEY'
  472. UNION
  473. SELECT
  474. `kcu`.`CONSTRAINT_NAME` AS `name`,
  475. `kcu`.`COLUMN_NAME` AS `column_name`,
  476. `tc`.`CONSTRAINT_TYPE` AS `type`,
  477. NULL AS `foreign_table_schema`,
  478. NULL AS `foreign_table_name`,
  479. NULL AS `foreign_column_name`,
  480. NULL AS `on_update`,
  481. NULL AS `on_delete`,
  482. `kcu`.`ORDINAL_POSITION` AS `position`
  483. FROM
  484. `information_schema`.`KEY_COLUMN_USAGE` AS `kcu`,
  485. `information_schema`.`TABLE_CONSTRAINTS` AS `tc`
  486. WHERE
  487. `kcu`.`TABLE_SCHEMA` = COALESCE(:schemaName, DATABASE()) AND `kcu`.`TABLE_NAME` = :tableName
  488. AND `tc`.`TABLE_SCHEMA` = `kcu`.`TABLE_SCHEMA` AND `tc`.`TABLE_NAME` = :tableName AND `tc`.`CONSTRAINT_NAME` = `kcu`.`CONSTRAINT_NAME` AND `tc`.`CONSTRAINT_TYPE` IN ('PRIMARY KEY', 'UNIQUE')
  489. ORDER BY `position` ASC
  490. SQL;
  491. $resolvedName = $this->resolveTableName($tableName);
  492. $constraints = $this->db->createCommand($sql, [
  493. ':schemaName' => $resolvedName->schemaName,
  494. ':tableName' => $resolvedName->name,
  495. ])->queryAll();
  496. $constraints = $this->normalizePdoRowKeyCase($constraints, true);
  497. $constraints = ArrayHelper::index($constraints, null, ['type', 'name']);
  498. $result = [
  499. 'primaryKey' => null,
  500. 'foreignKeys' => [],
  501. 'uniques' => [],
  502. ];
  503. foreach ($constraints as $type => $names) {
  504. foreach ($names as $name => $constraint) {
  505. switch ($type) {
  506. case 'PRIMARY KEY':
  507. $result['primaryKey'] = new Constraint([
  508. 'columnNames' => ArrayHelper::getColumn($constraint, 'column_name'),
  509. ]);
  510. break;
  511. case 'FOREIGN KEY':
  512. $result['foreignKeys'][] = new ForeignKeyConstraint([
  513. 'name' => $name,
  514. 'columnNames' => ArrayHelper::getColumn($constraint, 'column_name'),
  515. 'foreignSchemaName' => $constraint[0]['foreign_table_schema'],
  516. 'foreignTableName' => $constraint[0]['foreign_table_name'],
  517. 'foreignColumnNames' => ArrayHelper::getColumn($constraint, 'foreign_column_name'),
  518. 'onDelete' => $constraint[0]['on_delete'],
  519. 'onUpdate' => $constraint[0]['on_update'],
  520. ]);
  521. break;
  522. case 'UNIQUE':
  523. $result['uniques'][] = new Constraint([
  524. 'name' => $name,
  525. 'columnNames' => ArrayHelper::getColumn($constraint, 'column_name'),
  526. ]);
  527. break;
  528. }
  529. }
  530. }
  531. foreach ($result as $type => $data) {
  532. $this->setTableMetadata($tableName, $type, $data);
  533. }
  534. return $result[$returnType];
  535. }
  536. }