Skip to content

Commit

Permalink
Merge pull request #24 from hossein142001/multi_index
Browse files Browse the repository at this point in the history
multi index
  • Loading branch information
c006 authored Apr 24, 2017
2 parents 6d8568f + 8617540 commit b6c020d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions assets/AppUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ private function runMySql()
} else {
$this->string .= (empty($this->array['defaultValue'])) ? '' : " DEFAULT " . $this->array['defaultValue']['expression'] . " ";
}
if (isset($this->array['comment']))
$this->string .= (empty($this->array['comment'])) ? '' : " COMMENT \'{$this->array['comment']}\'";
}

private function runSqlite()
Expand Down
26 changes: 17 additions & 9 deletions controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,27 @@ public function actionIndex()

$table_indexes = Yii::$app->db->createCommand('SHOW INDEX FROM `' . $table . '`')->queryAll();

$table_indexes_new = [];
foreach ($table_indexes as $item) {
if ($item['Key_name'] != 'PRIMARY' && $item['Seq_in_index'] == 1) {

$unique = ($item['Non_unique']) ? '' : '_UNIQUE';
$array['indexes'][] = [
'name' => 'idx' . $unique . '_' . $item['Column_name'] . '_' . explode('.', microtime('usec'))[1] . '_' . substr("000" . sizeof($array['indexes']), -2),
'unique' => (($item['Non_unique']) ? 0 : 1),
'column' => $item['Column_name'],
'table' => $item['Table'],
];
if ($item['Key_name'] != 'PRIMARY' ) {
$table_indexes_new[$item['Key_name']]['cols'][] = $item['Column_name'];
$table_indexes_new[$item['Key_name']]['Column_name'][] = $item['Column_name'];
$table_indexes_new[$item['Key_name']]['Non_unique'] = $item['Non_unique'];
$table_indexes_new[$item['Key_name']]['Table'] = $item['Table'];
}

}

foreach ($table_indexes_new as $item) {
$unique = ($item['Non_unique']) ? '' : '_UNIQUE';
$array['indexes'][] = [
'name' => 'idx' . $unique . '_' . implode("_" ,array_values($item['Column_name'])) . '_' . explode('.', microtime('usec'))[1] . '_' . substr("000" . sizeof($array['indexes']), -2),
'unique' => (($item['Non_unique']) ? 0 : 1),
'column' => implode(",", array_values($item['cols'])),//$item['Column_name'],
'table' => $item['Table'],
];
}

if ($ifThen) {
$output->tabLevel--;
$output->addStr('}');
Expand Down

0 comments on commit b6c020d

Please sign in to comment.