mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 18:12:50 +08:00
feat(scheme): 增强 Scheme 与数据库同步机制并添加严格校验
This commit is contained in:
@@ -5,24 +5,28 @@ namespace base\common\command\scheme;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
use think\facade\Config;
|
||||
use app\common\service\scheme\DbToSchemeService;
|
||||
use app\common\service\scheme\SchemeToDbService;
|
||||
|
||||
class Make extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('scheme:make')
|
||||
->addOption('table', 't', Option::VALUE_REQUIRED, "The table name (without prefix)")
|
||||
->addArgument('table', Argument::OPTIONAL, "The table name (without prefix)")
|
||||
->setDescription('Generate Scheme class from Database table');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$table = $input->getArgument('table');
|
||||
$table = $input->getOption('table') ?: $input->getArgument('table');
|
||||
$service = new DbToSchemeService();
|
||||
$compare = new SchemeToDbService();
|
||||
|
||||
$tables = [];
|
||||
if ($table) {
|
||||
@@ -62,6 +66,18 @@ class Make extends Command
|
||||
if (preg_match('/class\s+(\w+)/', $code, $matches)) {
|
||||
$className = $matches[1];
|
||||
$path = app()->getAppPath() . 'admin/scheme/' . $className . '.php';
|
||||
|
||||
if (is_file($path)) {
|
||||
require_once $path;
|
||||
$schemeClass = 'app\\admin\\scheme\\' . $className;
|
||||
if (class_exists($schemeClass)) {
|
||||
$diffs = $compare->diff($schemeClass);
|
||||
if (empty($diffs)) {
|
||||
$output->writeln("<info>Skipping (no schema changes): $path</info>");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 确保目录存在
|
||||
if (!is_dir(dirname($path))) {
|
||||
|
||||
Reference in New Issue
Block a user