作者 赵彬吉

Merge remote-tracking branch 'origin/zhl' into dev

... ... @@ -14,4 +14,5 @@ yarn-error.log
/.idea
/.vscode
composer.lock
app/Console/Commands/Test/Demo.php
/public/upload
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/4/19
* Time: 15:04
*/
namespace App\Console\Commands;
use App\Models\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* Class ProjectDatabaseUpdate
* @package App\Console\Commands
*/
class ProjectDatabaseUpdate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project:database_update';
/**
* The console command description.
*
* @var string
*/
protected $description = '项目数据库更新';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
#TODO 未处理更新 更新对象(base, project) 更新内容
return true;
}
/**
* 主库内容更新
* @param $sql
* @return array
*/
public function baseUpdate($sql)
{
return DB::select($sql);
}
/**
* 客户数据表更新
* @param $sql
* @return bool
*/
public function projectDatabaseUpdate($sql)
{
$project = Project::get();
foreach ($project as $val) {
ProjectServer::useProject($val->id);
DB::connection('custom_mysql')->select($sql);
}
return true;
}
/**
* 指定项目数据库更新
* @param $project_id
* @param $sql
*/
public function appointProjectUpdate($project_id, $sql)
{
ProjectServer::useProject($project_id);
DB::connection('custom_mysql')->select($sql);
}
}
\ No newline at end of file
... ...
... ... @@ -8,6 +8,7 @@
namespace App\Console\Commands;
use App\Models\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
... ... @@ -71,11 +72,7 @@ class ProjectInit extends Command
// 创建数据库失败 添加通知以及再次处理
}
// 设置 database.connections.custom_mysql 数据
config(['database.connections.custom_mysql.host' => $project->mysqlConfig()->host]);
config(['database.connections.custom_mysql.port' => $project->mysqlConfig()->port]);
config(['database.connections.custom_mysql.database' => $project->databaseName()]);
config(['database.connections.custom_mysql.username' => $project->mysqlConfig()->user]);
config(['database.connections.custom_mysql.password' => $project->mysqlConfig()->password]);
ProjectServer::useProject($project->id);
// TODO 创建对应库 初始化数据表
$this->initTable();
... ... @@ -87,12 +84,6 @@ class ProjectInit extends Command
*/
public function initTable()
{
// $table = DB::select('show tables');
// $table = array_column($table, 'Tables_in_globalso_dev');
// $table = DB::connection('custom_tmp_mysql')->select('show tables');
// $table_in = DB::connection('custom_tmp_mysql')->getDatabaseName();
// dd($table, $table_in);
$database_name = DB::connection('custom_tmp_mysql')->getDatabaseName();
$table = Schema::connection('custom_tmp_mysql')->getAllTables();
... ...