refactor:更新表注释和删除表均已经可以使用 phinx 完成

This commit is contained in:
妙码生花 2024-02-26 04:30:14 +08:00
parent 31696eff2c
commit 34e5b974f9
2 changed files with 10 additions and 14 deletions

View File

@ -88,17 +88,17 @@ class Crud extends Backend
'status' => 'start',
]);
// 表名称
$tableName = TableManager::tableName($table['name'], false);
if ($type == 'create' || $table['rebuild'] == 'Yes') {
// 数据表存在则删除
Helper::delTable($table['name']);
TableManager::phinxTable($tableName)->drop()->save();
}
// 处理表设计
[$tablePk] = Helper::handleTableDesign($table, $fields);
// 表名称
$tableName = TableManager::tableName($table['name'], false);
// 表注释
$tableComment = mb_substr($table['comment'], -1) == '表' ? mb_substr($table['comment'], 0, -1) . '管理' : $table['comment'];
@ -757,6 +757,10 @@ class Crud extends Backend
}
}
/**
* 组装前台表单的数据
* @throws Throwable
*/
private function getFormField($field, $columnDict): array
{
// 表单项属性

View File

@ -480,9 +480,9 @@ class Helper
if ($adapter->hasTable($name)) {
// 更新表
TableManager::changeComment($name, $comment);
if ($designChange) {
$table = TableManager::phinxTable($name, [], false);
$table->changeComment($comment)->update();
// 改名和删除操作优先
$priorityOpt = false;
@ -727,17 +727,9 @@ class Helper
return str_pad('', 4 * $num);
}
/**
* 删除数据表
*/
public static function delTable(string $table): void
{
$sql = 'DROP TABLE IF EXISTS `' . TableManager::tableName($table) . '`';
Db::execute($sql);
}
/**
* 根据数据表解析字段数据
* @throws Throwable
*/
public static function parseTableColumns(string $table, bool $analyseField = false): array
{