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