修复代码生成器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'],
];
$table = $params['controller']['table'] ?? '';
if ($table) {
$table = \config('database.connections.mysql.prefix') . $table;
}
$model = [
'table' => $params['controller']['table'] ?? '',
'table' => $table,
'model' => $params['controller']['model'] ?? '',
'sql' => $params['model']['data'],
'extra' => $params['model']['extra'],

View File

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

View File

@ -12,12 +12,11 @@ class SQL extends Factory
public function done($params)
{
//dd($this->createSQL($params));
Db::execute($this->createSQL($params));
// 判断表是否创建成功
if (!$this->hasTableExists($params['table'])) {
throw new FailedException(sprintf('create table [%s] failed',$params['table']));
throw new FailedException(sprintf('create table [%s] failed', $params['table']));
}
return true;
@ -36,7 +35,7 @@ class SQL extends Factory
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']));
}
@ -70,7 +69,7 @@ class SQL extends Factory
}
$createSql = rtrim($createSql, ',' . PHP_EOL);
// 创建表 SQL
return $this->createTable($table, $createSql, $extra['engine'], 'utf8mb4', $extra['comment']);
return $this->createTable($params['table'], $createSql, $extra['engine'], 'utf8mb4', $extra['comment']);
}
/**
@ -102,9 +101,14 @@ class SQL extends Factory
if (!$sql['default']) {
$_sql[] = ' default \'\'';
} else {
$_sql[] = ' default ' . $sql['default'];
if (strpos('int', $sql['type']) === false) {
$_sql[] = ' default "' . $sql['default'] . '"';
} else {
$_sql[] = ' default ' . $sql['default'];
}
}
}
// 字段注释
$_sql[] = $sql['comment'] ? sprintf('comment \'%s\'', $sql['comment']) : '';