mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
改进数据表字段缓存生成 支持生成多个数据库的
This commit is contained in:
@@ -24,7 +24,8 @@ class Schema extends Command
|
|||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this->setName('optimize:schema')
|
$this->setName('optimize:schema')
|
||||||
->addOption('table', null, Option::VALUE_REQUIRED, 'Build table schema cache .')
|
->addOption('db', null, Option::VALUE_REQUIRED, 'db name .')
|
||||||
|
->addOption('table', null, Option::VALUE_REQUIRED, 'table name .')
|
||||||
->setDescription('Build database schema cache.');
|
->setDescription('Build database schema cache.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,19 +33,25 @@ class Schema extends Command
|
|||||||
{
|
{
|
||||||
if ($input->hasOption('table')) {
|
if ($input->hasOption('table')) {
|
||||||
$tables[] = $input->getOption('table');
|
$tables[] = $input->getOption('table');
|
||||||
|
} else {
|
||||||
|
if ($input->hasOption('db')) {
|
||||||
|
$dbName = $input->getOption('db');
|
||||||
|
$tables = Db::getTables($dbName);
|
||||||
} else {
|
} else {
|
||||||
$tables = Db::getTables();
|
$tables = Db::getTables();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_dir(RUNTIME_PATH . 'schema')) {
|
if (!is_dir(RUNTIME_PATH . 'schema')) {
|
||||||
@mkdir(RUNTIME_PATH . 'schema', 0755, true);
|
@mkdir(RUNTIME_PATH . 'schema', 0755, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$db = isset($dbName) ? $dbName . '.' : '';
|
||||||
foreach ($tables as $table) {
|
foreach ($tables as $table) {
|
||||||
$content = '<?php ' . PHP_EOL . 'return ';
|
$content = '<?php ' . PHP_EOL . 'return ';
|
||||||
$info = Db::getFields($table);
|
$info = Db::getFields($db . $table);
|
||||||
$content .= var_export($info, true) . ';';
|
$content .= var_export($info, true) . ';';
|
||||||
file_put_contents(RUNTIME_PATH . 'schema' . DS . $table . EXT, $content);
|
file_put_contents(RUNTIME_PATH . 'schema' . DS . $db . $table . EXT, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->writeln('<info>Succeed!</info>');
|
$output->writeln('<info>Succeed!</info>');
|
||||||
|
|||||||
Reference in New Issue
Block a user