代码功能更新
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use think\facade\Config;
|
||||
use think\migration\Migrator;
|
||||
|
||||
class FilesCategory extends Migrator
|
||||
{
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('files_category', [
|
||||
'engine' => 'InnoDB',
|
||||
'comment' => '附件分类管理',
|
||||
'collation' => 'utf8mb4_general_ci'
|
||||
]);
|
||||
|
||||
//删除表
|
||||
if ($table->exists()) {
|
||||
$dbPrefix = Config::get('database.connections.' . Config::get('database.default') . '.prefix');
|
||||
$tableName = $table->getName();
|
||||
\think\facade\Db::execute('drop table if exists ' . $dbPrefix . $tableName);
|
||||
// $table->drop(); // 为什么不用这个方法来删除表,因为在我使用thinkphp6时,think-migrate的composer包并没有对这个方法进行具体实现,所以不能删除表
|
||||
}
|
||||
|
||||
$table
|
||||
->addColumn('name', 'string', ['limit' => 255, 'null' => 0, 'default' => '0', 'comment' => '分类名称'])
|
||||
->addColumn('pid', 'integer', ['limit' => 11, 'null' => 1, 'default' => '0', 'comment' => '父级'])
|
||||
->addColumn('sort', 'integer', ['limit' => 11, 'null' => 1, 'default' => '0', 'comment' => '排序'])
|
||||
->addColumn('create_time', 'datetime', ['null' => 1, 'comment' => '创建时间'])
|
||||
->addColumn('update_time', 'datetime', ['null' => 1, 'comment' => '更新时间'])
|
||||
->addColumn('delete_time', 'datetime', ['null' => 1, 'comment' => '删除时间'])
|
||||
|
||||
;
|
||||
|
||||
$data = [
|
||||
[
|
||||
'id' => '1',
|
||||
'name' => '默认分类',
|
||||
'pid' => '0',
|
||||
'sort' => '0',
|
||||
'create_time' => '2024-07-07 17:15:55',
|
||||
'update_time' => '2024-07-07 17:15:55',
|
||||
'delete_time' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$table->setData($data)->create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user