|
...
|
...
|
@@ -605,22 +605,23 @@ class ProjectLogic extends BaseLogic |
|
|
|
{
|
|
|
|
config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_'.$project_id]);
|
|
|
|
$database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName();
|
|
|
|
$table = Schema::connection('custom_tmp_mysql_copy')->getAllTables();
|
|
|
|
$table = array_column($table, 'Tables_in_' . $database_name);
|
|
|
|
foreach ($table as $v) {
|
|
|
|
$has_table = Schema::connection('custom_mysql')->hasTable($v);
|
|
|
|
if ($has_table) {
|
|
|
|
continue;
|
|
|
|
$tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables();
|
|
|
|
$tables = array_column($tables, 'Tables_in_' . $database_name);
|
|
|
|
foreach ($tables as $table) {
|
|
|
|
$has_table = Schema::connection('custom_mysql')->hasTable($table);
|
|
|
|
if (!$has_table) {
|
|
|
|
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}");
|
|
|
|
DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
|
|
|
|
}
|
|
|
|
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$v}");
|
|
|
|
DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
|
|
|
|
}
|
|
|
|
foreach ($table as $v1){
|
|
|
|
// 执行同步数据的操作
|
|
|
|
DB::connection('custom_mysql')->insert("INSERT INTO {$v1} SELECT * FROM custom_tmp_mysql_copy.{$v1}");
|
|
|
|
|
|
|
|
if (Schema::connection('custom_mysql')->hasColumn($v1, 'project_id')) {
|
|
|
|
DB::connection('custom_mysql')->table($v1)->update(['project_id' => $news_project_id]);
|
|
|
|
DB::connection('custom_mysql')->table($table)->truncate(); // 清空目标表数据
|
|
|
|
DB::connection('custom_mysql')->table($table)->insertUsing(
|
|
|
|
[], // 列名数组,留空表示插入所有列
|
|
|
|
function ($query) use ($table) {
|
|
|
|
$query->select('*')->from("custom_tmp_mysql_copy.{$table}");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
|
|
|
|
DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
...
|
...
|
|