28 private $resourceConnection;
33 private $definitionAggregator;
46 $this->definitionAggregator = $definitionAggregator;
55 $dbName = $this->resourceConnection->getSchemaName(
$resource);
58 [
'i_tables' =>
'information_schema.TABLES'],
61 'comment' =>
'TABLE_COMMENT',
62 'collation' =>
'TABLE_COLLATION' 66 [
'charset_applicability' =>
'information_schema.COLLATION_CHARACTER_SET_APPLICABILITY'],
67 'i_tables.table_collation = charset_applicability.collation_name',
69 'charset' =>
'charset_applicability.CHARACTER_SET_NAME' 72 ->where(
'TABLE_SCHEMA = ?', $dbName)
89 $dbName = $this->resourceConnection->getSchemaName(
$resource);
92 'information_schema.COLUMNS',
94 'name' =>
'COLUMN_NAME',
95 'default' =>
'COLUMN_DEFAULT',
96 'type' =>
'DATA_TYPE',
97 'nullable' =>
new Expression(
'IF(IS_NULLABLE="YES", true, false)'),
98 'definition' =>
'COLUMN_TYPE',
100 'comment' =>
new Expression(
'IF(COLUMN_COMMENT="", NULL, COLUMN_COMMENT)')
103 ->where(
'TABLE_SCHEMA = ?', $dbName)
105 ->order(
'ORDINAL_POSITION ASC');
107 $columnsDefinition =
$adapter->fetchAssoc($stmt);
109 foreach ($columnsDefinition as $columnDefinition) {
110 $column = $this->definitionAggregator->fromDefinition($columnDefinition);
111 $columns[$column[
'name']] = $column;
128 $condition = sprintf(
'`Non_unique` = 1');
129 $sql = sprintf(
'SHOW INDEXES FROM %s WHERE %s',
$tableName, $condition);
135 foreach ($indexesDefinition as $indexDefinition) {
136 $indexDefinition[
'type'] =
'index';
137 $index = $this->definitionAggregator->fromDefinition($indexDefinition);
139 if (!isset($indexes[
$index[
'name']])) {
140 $indexes[
$index[
'name']] = [];
159 $createTableSql[
'type'] =
'reference';
160 return $this->definitionAggregator->fromDefinition($createTableSql);
173 $sql = sprintf(
'SHOW CREATE TABLE %s',
$tableName);
188 $condition = sprintf(
'`Non_unique` = 0');
189 $sql = sprintf(
'SHOW INDEXES FROM %s WHERE %s',
$tableName, $condition);
195 foreach ($constraintsDefinition as $constraintDefinition) {
197 $constraint = $this->definitionAggregator->fromDefinition($constraintDefinition);
218 $dbName = $this->resourceConnection->getSchemaName(
$resource);
221 [
'information_schema.TABLES'],
224 ->where(
'TABLE_SCHEMA = ?', $dbName)
225 ->where(
'TABLE_TYPE = ?', self::MYSQL_TABLE_TYPE);
getTableOptions($tableName, $resource)
__construct(ResourceConnection $resourceConnection, DefinitionAggregator $definitionAggregator)
readColumns($tableName, $resource)
readIndexes($tableName, $resource)
getCreateTableSql($tableName, $resource)
readConstraints($tableName, $resource)
readReferences($tableName, $resource)