|
@@ -64,6 +64,8 @@ class CopyOldProject extends Command |
|
@@ -64,6 +64,8 @@ class CopyOldProject extends Command |
|
64
|
{
|
64
|
{
|
|
65
|
// 设置源数据库
|
65
|
// 设置源数据库
|
|
66
|
config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_' . $project_id]);
|
66
|
config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_' . $project_id]);
|
|
|
|
67
|
+ DB::purge('custom_tmp_mysql_copy');
|
|
|
|
68
|
+ DB::reconnect('custom_tmp_mysql_copy');
|
|
67
|
$database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName();
|
69
|
$database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName();
|
|
68
|
// 获取源数据库的所有表
|
70
|
// 获取源数据库的所有表
|
|
69
|
$tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables();
|
71
|
$tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables();
|
|
@@ -80,11 +82,9 @@ class CopyOldProject extends Command |
|
@@ -80,11 +82,9 @@ class CopyOldProject extends Command |
|
80
|
);
|
82
|
);
|
|
81
|
continue;
|
83
|
continue;
|
|
82
|
}
|
84
|
}
|
|
83
|
-
|
|
|
|
84
|
// 2. 删除目标数据库中的表
|
85
|
// 2. 删除目标数据库中的表
|
|
85
|
$result = DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS `{$table}`");
|
86
|
$result = DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS `{$table}`");
|
|
86
|
@file_put_contents(storage_path('logs/copy_mysql_error.log'), "删除旧表:{$table} => {$result}" . PHP_EOL, FILE_APPEND);
|
87
|
@file_put_contents(storage_path('logs/copy_mysql_error.log'), "删除旧表:{$table} => {$result}" . PHP_EOL, FILE_APPEND);
|
|
87
|
-
|
|
|
|
88
|
// 3. 复制建表 SQL
|
88
|
// 3. 复制建表 SQL
|
|
89
|
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE `{$table}`");
|
89
|
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE `{$table}`");
|
|
90
|
$createSql = get_object_vars($sql[0])['Create Table'];
|
90
|
$createSql = get_object_vars($sql[0])['Create Table'];
|
|
@@ -115,7 +115,6 @@ class CopyOldProject extends Command |
|
@@ -115,7 +115,6 @@ class CopyOldProject extends Command |
|
115
|
);
|
115
|
);
|
|
116
|
continue; // 跳过这个表,不中断整个流程
|
116
|
continue; // 跳过这个表,不中断整个流程
|
|
117
|
}
|
117
|
}
|
|
118
|
-
|
|
|
|
119
|
// 7. 更新 project_id(如果存在)
|
118
|
// 7. 更新 project_id(如果存在)
|
|
120
|
if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
|
119
|
if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
|
|
121
|
DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
|
120
|
DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
|