修复代码生成器bug

This commit is contained in:
yanwenwu 2020-05-20 11:03:21 +08:00
parent 181ceefd55
commit ff1d7dfd2e
3 changed files with 15 additions and 8 deletions

View File

@ -100,8 +100,13 @@ class Generator
'other_function' => $params['controller']['other_function'], 'other_function' => $params['controller']['other_function'],
]; ];
$table = $params['controller']['table'] ?? '';
if ($table) {
$table = \config('database.connections.mysql.prefix') . $table;
}
$model = [ $model = [
'table' => $params['controller']['table'] ?? '', 'table' => $table,
'model' => $params['controller']['model'] ?? '', 'model' => $params['controller']['model'] ?? '',
'sql' => $params['model']['data'], 'sql' => $params['model']['data'],
'extra' => $params['model']['extra'], 'extra' => $params['model']['extra'],

View File

@ -93,8 +93,6 @@ abstract class Factory
{ {
$tables = Db::getConnection()->getTables(); $tables = Db::getConnection()->getTables();
$table = \config('database.connections.mysql.prefix') . $table;
return in_array($table, $tables) ? $table : false; return in_array($table, $tables) ? $table : false;
} }
} }

View File

@ -12,7 +12,6 @@ class SQL extends Factory
public function done($params) public function done($params)
{ {
//dd($this->createSQL($params));
Db::execute($this->createSQL($params)); Db::execute($this->createSQL($params));
// 判断表是否创建成功 // 判断表是否创建成功
@ -36,7 +35,7 @@ class SQL extends Factory
throw new FailedException('table name has lost~'); throw new FailedException('table name has lost~');
} }
if ($table = $this->hasTableExists($params['table'])) { if ($this->hasTableExists($params['table'])) {
throw new FailedException(sprintf('table [%s] has existed', $params['table'])); throw new FailedException(sprintf('table [%s] has existed', $params['table']));
} }
@ -70,7 +69,7 @@ class SQL extends Factory
} }
$createSql = rtrim($createSql, ',' . PHP_EOL); $createSql = rtrim($createSql, ',' . PHP_EOL);
// 创建表 SQL // 创建表 SQL
return $this->createTable($table, $createSql, $extra['engine'], 'utf8mb4', $extra['comment']); return $this->createTable($params['table'], $createSql, $extra['engine'], 'utf8mb4', $extra['comment']);
} }
/** /**
@ -101,10 +100,15 @@ class SQL extends Factory
$_sql[] = 'not null'; $_sql[] = 'not null';
if (!$sql['default']) { if (!$sql['default']) {
$_sql[] = ' default \'\''; $_sql[] = ' default \'\'';
} else {
if (strpos('int', $sql['type']) === false) {
$_sql[] = ' default "' . $sql['default'] . '"';
} else { } else {
$_sql[] = ' default ' . $sql['default']; $_sql[] = ' default ' . $sql['default'];
} }
} }
}
// 字段注释 // 字段注释
$_sql[] = $sql['comment'] ? sprintf('comment \'%s\'', $sql['comment']) : ''; $_sql[] = $sql['comment'] ? sprintf('comment \'%s\'', $sql['comment']) : '';