Support more index types in DB table parser

UNIQUE, SPATIAL, FULLTEXT
This commit is contained in:
Kijin Sung 2020-07-11 15:42:37 +09:00
parent 5f8ceafdf6
commit 9b776942e5
5 changed files with 25 additions and 8 deletions

View file

@ -9,5 +9,5 @@ class Index
{
public $name;
public $columns = array();
public $is_unique = false;
public $type = null;
}

View file

@ -90,7 +90,7 @@ class Table
}
$idxcolumns[] = '`' . $column_name . '`' . ($prefix_size > 0 ? "($prefix_size)" : '');
}
$idxtype = ($index->is_unique ? 'UNIQUE' : 'INDEX');
$idxtype = $index->type ? ($index->type . ' INDEX') : 'INDEX';
$idxdef = ' ' . $idxtype . ' `' . $index->name . '` (' . implode(', ', $idxcolumns) . ')';
$columns[] = $idxdef;
}

View file

@ -154,11 +154,19 @@ class DBTableParser extends BaseParser
$index->columns[$idxcolumn] = 0;
}
}
$index->is_unique = toBool($index_info['unique'] ?? '');
if (isset($index_info['type']) && $index_info['type'])
{
$index->type = strtoupper($index_info['type']);
}
elseif (toBool($index_info['unique']))
{
$index->type = 'UNIQUE';
}
if (isset($table->columns[$idxcolumn]) && is_object($table->columns[$idxcolumn]))
{
$table->columns[$idxcolumn]->is_indexed = true;
$table->columns[$idxcolumn]->is_unique = $index->is_unique;
$table->columns[$idxcolumn]->is_unique = $index->type === 'UNIQUE';
}
$table->indexes[$index->name] = $index;
}