Improve addColumn() and modifyColumn()

- 특정 컬럼 이후에 컬럼을 추가할 수 있도록 허용
- 모든 integer 타입의 size 속성을 무시 (tinyint 제외)
This commit is contained in:
Kijin Sung 2018-07-05 22:43:53 +09:00
parent 35b73eec0b
commit 32c9de472a

View file

@ -467,10 +467,11 @@ class DBMySQL extends DB
* @param boolean $notnull not null status, default value is false
* @return void
*/
function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = null, $notnull = false)
function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = null, $notnull = false, $after = null)
{
$type = $this->column_type[$type];
if(strtoupper($type) == 'INTEGER')
$type = strtolower($type);
$type = isset($this->column_type[$type]) ? $this->column_type[$type] : $type;
if(in_array($type, ['integer', 'int', 'bigint', 'smallint']))
{
$size = '';
}
@ -492,6 +493,10 @@ class DBMySQL extends DB
{
$query .= " NOT NULL ";
}
if($after_column)
{
$query .= sprintf(" AFTER `%s` ", $after_column);
}
return $this->_query($query);
}
@ -520,12 +525,13 @@ class DBMySQL extends DB
*/
function modifyColumn($table_name, $column_name, $type = 'number', $size = '', $default = '', $notnull = false)
{
$type = $this->column_type[$type];
if(strtoupper($type) == 'INTEGER')
$type = strtolower($type);
$type = isset($this->column_type[$type]) ? $this->column_type[$type] : $type;
if(in_array($type, ['integer', 'int', 'bigint', 'smallint']))
{
$size = '';
}
$query = sprintf("ALTER TABLE `%s%s` MODIFY `%s` ", $this->prefix, $table_name, $column_name);
if($size)
{