From 25373e654022fd505c98548b147a6cc18f518848 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sat, 11 Jul 2020 15:50:12 +0900 Subject: [PATCH] Support more index types in DB::addIndex() --- common/framework/db.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/framework/db.php b/common/framework/db.php index adaab6483..786f74547 100644 --- a/common/framework/db.php +++ b/common/framework/db.php @@ -865,19 +865,24 @@ class DB * @param string $table_name * @param string $index_name * @param array $columns - * @param bool $unique + * @param string $type * @return \BaseObject */ - public function addIndex(string $table_name, string $index_name, $columns, $unique = false): \BaseObject + public function addIndex(string $table_name, string $index_name, $columns, $type = ''): \BaseObject { if (!is_array($columns)) { $columns = array($columns); } + if ($type === true || $type === 1) + { + $type = 'UNIQUE'; + } + $query = vsprintf("ALTER TABLE `%s` ADD %s `%s` (%s);", array( $this->addQuotes($this->_prefix . $table_name), - $unique ? 'UNIQUE INDEX' : 'INDEX', + ltrim($type . ' INDEX'), $this->addQuotes($index_name), implode(', ', array_map(function($column_name) { if (preg_match('/^([^()]+)\(([0-9]+)\)$/', $column_name, $matches))