优化sql生成&添加creator_id

This commit is contained in:
JaguarJack 2020-07-01 15:24:42 +08:00
parent 1a20159776
commit 51672734a6
2 changed files with 27 additions and 2 deletions

View File

@ -55,6 +55,10 @@ class SQL extends Factory
if ($ifHaveNotFields) {
throw new FailedException('Do you have set mysql fields?');
}
// 创建人
if ($extra['creator_id'] ?? false) {
$createSql .= $this->parseCreatorId();
}
// 创建时间
if ($extra['created_at'] ?? false) {
$createSql .= $this->parseCreatedAt();
@ -99,11 +103,11 @@ class SQL extends Factory
$default = trim(trim($sql['default'], '\''));
if (!$sql['nullable']) {
$_sql[] = 'not null';
if (!$default) {
if ($default == '' || $default === '') {
$_sql[] = ' default \'\'';
} else {
if (strpos('int', $sql['type']) === false) {
$_sql[] = ' default "' . $default . '"';
$_sql[] = ' default ' . (int)$default ;
} else {
$_sql[] = ' default ' . $default;
}
@ -152,6 +156,17 @@ class SQL extends Factory
return sprintf('`deleted_at` int unsigned not null default 0 comment \'%s\',', '软删除') . PHP_EOL;
}
/**
* parse creator id
*
* @time 2020年07月01日
* @return string
*/
protected function parseCreatorId()
{
return sprintf('`creator_id` int unsigned not null default 0 comment \'%s\',', '创建人ID') . PHP_EOL;
}
/**
* created table
*

View File

@ -0,0 +1,10 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------