Support index options

This commit is contained in:
Kijin Sung 2020-07-11 18:00:36 +09:00
parent 25373e6540
commit 4ad35bff8c
6 changed files with 25 additions and 6 deletions

View file

@ -138,6 +138,7 @@ class DBTableParser extends BaseParser
// Load indexes.
foreach ($xml->index as $index_info)
{
// Get the index name and list of columns.
$index_info = self::_getAttributes($index_info);
$index = new DBTable\Index;
$index->name = $index_info['name'];
@ -155,6 +156,7 @@ class DBTableParser extends BaseParser
}
}
// Get the index type.
if (isset($index_info['type']) && $index_info['type'])
{
$index->type = strtoupper($index_info['type']);
@ -163,11 +165,21 @@ class DBTableParser extends BaseParser
{
$index->type = 'UNIQUE';
}
// Set attributes on indexed columns.
if (isset($table->columns[$idxcolumn]) && is_object($table->columns[$idxcolumn]))
{
$table->columns[$idxcolumn]->is_indexed = true;
$table->columns[$idxcolumn]->is_unique = $index->type === 'UNIQUE';
$table->columns[$idxcolumn]->is_unique = $index->type === 'UNIQUE' ? true : $table->columns[$idxcolumn]->is_unique;
}
// If any index options are given, also store them in the index class.
if (isset($index_info['options']) && $index_info['options'])
{
$index->options = $index_info['options'];
}
// Add the index to the column definition.
$table->indexes[$index->name] = $index;
}