修复安装数据库报错
This commit is contained in:
@@ -12,6 +12,7 @@ use ba\Filesystem;
|
|||||||
use app\common\controller\Api;
|
use app\common\controller\Api;
|
||||||
use app\admin\model\Admin as AdminModel;
|
use app\admin\model\Admin as AdminModel;
|
||||||
use app\admin\model\User as UserModel;
|
use app\admin\model\User as UserModel;
|
||||||
|
use app\process\Monitor;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
use Webman\Http\Request;
|
use Webman\Http\Request;
|
||||||
use Phinx\Config\Config as PhinxConfig;
|
use Phinx\Config\Config as PhinxConfig;
|
||||||
@@ -428,6 +429,20 @@ class Install extends Api
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Windows 下 php windows.php 会每秒检测监控目录;写入 config/.env 等会触发 taskkill 整进程,导致 POST 被中断(ERR_CONNECTION_RESET)
|
||||||
|
Monitor::pause();
|
||||||
|
try {
|
||||||
|
return $this->baseConfigPost($request, $envOk, $rootPath, $migrateCommand);
|
||||||
|
} finally {
|
||||||
|
Monitor::resume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统基础配置 POST:写入配置并执行迁移
|
||||||
|
*/
|
||||||
|
private function baseConfigPost(Request $request, bool $envOk, string $rootPath, string $migrateCommand): Response
|
||||||
|
{
|
||||||
$connectData = $databaseParam = $request->only(['hostname', 'username', 'password', 'hostport', 'database', 'prefix']);
|
$connectData = $databaseParam = $request->only(['hostname', 'username', 'password', 'hostport', 'database', 'prefix']);
|
||||||
|
|
||||||
// 数据库配置测试
|
// 数据库配置测试
|
||||||
@@ -455,6 +470,9 @@ class Install extends Api
|
|||||||
return "\$env('database.{$key}', '" . addslashes($value) . "')";
|
return "\$env('database.{$key}', '" . addslashes($value) . "')";
|
||||||
};
|
};
|
||||||
$dbConfigText = preg_replace_callback("/\\\$env\('database\.(hostname|database|username|password|hostport|prefix)',\s*'[^']*'\)/", $callback, $dbConfigContent);
|
$dbConfigText = preg_replace_callback("/\\\$env\('database\.(hostname|database|username|password|hostport|prefix)',\s*'[^']*'\)/", $callback, $dbConfigContent);
|
||||||
|
if ($dbConfigText === null) {
|
||||||
|
return $this->error(__('Failed to update database config file:%s', ['config/' . self::$dbConfigFileName]));
|
||||||
|
}
|
||||||
$result = @file_put_contents($dbConfigFile, $dbConfigText);
|
$result = @file_put_contents($dbConfigFile, $dbConfigText);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return $this->error(__('File has no write permission:%s', ['config/' . self::$dbConfigFileName]));
|
return $this->error(__('File has no write permission:%s', ['config/' . self::$dbConfigFileName]));
|
||||||
|
|||||||
@@ -227,6 +227,8 @@ class Install extends AbstractMigration
|
|||||||
->addColumn('extend', 'string', ['limit' => 255, 'default' => '', 'comment' => '扩展属性', 'null' => false])
|
->addColumn('extend', 'string', ['limit' => 255, 'default' => '', 'comment' => '扩展属性', 'null' => false])
|
||||||
->addColumn('allow_del', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '允许删除:0=否,1=是', 'null' => false])
|
->addColumn('allow_del', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '允许删除:0=否,1=是', 'null' => false])
|
||||||
->addColumn('weigh', 'integer', ['comment' => '权重', 'default' => 0, 'null' => false])
|
->addColumn('weigh', 'integer', ['comment' => '权重', 'default' => 0, 'null' => false])
|
||||||
|
->addColumn('update_time', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
|
||||||
|
->addColumn('create_time', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
|
||||||
->addIndex(['name'], [
|
->addIndex(['name'], [
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
])
|
])
|
||||||
|
|||||||
55
database/migrations/20231111000000_add_config_timestamps.php
Normal file
55
database/migrations/20231111000000_add_config_timestamps.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* config 表在初始 install 中未含 create_time/update_time,而 Config 模型开启自动时间戳,
|
||||||
|
* Version205 等迁移使用 Model::save() 会生成对 update_time 的 UPDATE,导致 1054 错误。
|
||||||
|
* 本迁移在 Version205 之前执行,补齐字段。
|
||||||
|
*/
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
class AddConfigTimestamps extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if (!$this->hasTable('config')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$config = $this->table('config');
|
||||||
|
if (!$config->hasColumn('update_time')) {
|
||||||
|
$config->addColumn('update_time', 'biginteger', [
|
||||||
|
'limit' => 16,
|
||||||
|
'signed' => false,
|
||||||
|
'null' => true,
|
||||||
|
'default' => null,
|
||||||
|
'comment' => '更新时间',
|
||||||
|
'after' => 'weigh',
|
||||||
|
])->save();
|
||||||
|
}
|
||||||
|
$config = $this->table('config');
|
||||||
|
if (!$config->hasColumn('create_time')) {
|
||||||
|
$config->addColumn('create_time', 'biginteger', [
|
||||||
|
'limit' => 16,
|
||||||
|
'signed' => false,
|
||||||
|
'null' => true,
|
||||||
|
'default' => null,
|
||||||
|
'comment' => '创建时间',
|
||||||
|
'after' => 'update_time',
|
||||||
|
])->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
if (!$this->hasTable('config')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$config = $this->table('config');
|
||||||
|
if ($config->hasColumn('create_time')) {
|
||||||
|
$config->removeColumn('create_time')->save();
|
||||||
|
}
|
||||||
|
$config = $this->table('config');
|
||||||
|
if ($config->hasColumn('update_time')) {
|
||||||
|
$config->removeColumn('update_time')->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user