合并分支 'lyh-server' 到 'master'
gx复制项目数据 查看合并请求 !1910
正在显示
1 个修改的文件
包含
6 行增加
和
3 行删除
| @@ -238,17 +238,20 @@ class CopyProject extends Command | @@ -238,17 +238,20 @@ class CopyProject extends Command | ||
| 238 | $tables = array_column($tables, 'Tables_in_' . $database_name); | 238 | $tables = array_column($tables, 'Tables_in_' . $database_name); |
| 239 | foreach ($tables as $table) { | 239 | foreach ($tables as $table) { |
| 240 | // 1. 删除目标数据库中的表 | 240 | // 1. 删除目标数据库中的表 |
| 241 | - DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS {$table}"); | 241 | + $result = DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS {$table}"); |
| 242 | + @file_put_contents(storage_path('logs/copy_mysql_error.log'), var_export('先删除对应数据库的对应表返回结果:'.$result, true) . PHP_EOL, FILE_APPEND); | ||
| 242 | // 2. 复制建表 SQL | 243 | // 2. 复制建表 SQL |
| 243 | $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE `{$table}`"); | 244 | $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE `{$table}`"); |
| 244 | - DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']); | 245 | + $result1 = DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']); |
| 246 | + @file_put_contents(storage_path('logs/copy_mysql_error.log'), var_export('创建对应表数据:'.$result1, true) . PHP_EOL, FILE_APPEND); | ||
| 245 | // 3. 跳过指定的表 | 247 | // 3. 跳过指定的表 |
| 246 | if (in_array($table, ['gl_customer_visit', 'gl_customer_visit_item', 'gl_inquiry_other', 'gl_inquiry_form_data', 'gl_inquiry_form'])) { | 248 | if (in_array($table, ['gl_customer_visit', 'gl_customer_visit_item', 'gl_inquiry_other', 'gl_inquiry_form_data', 'gl_inquiry_form'])) { |
| 247 | continue; | 249 | continue; |
| 248 | } | 250 | } |
| 249 | // 4. 原生 SQL 插入数据(完全复制) | 251 | // 4. 原生 SQL 插入数据(完全复制) |
| 250 | $insert_sql = "INSERT INTO `{$table}` SELECT * FROM `gl_data_{$project_id}`.`{$table}`"; | 252 | $insert_sql = "INSERT INTO `{$table}` SELECT * FROM `gl_data_{$project_id}`.`{$table}`"; |
| 251 | - DB::connection('custom_mysql')->statement($insert_sql); | 253 | + $result2 = DB::connection('custom_mysql')->statement($insert_sql); |
| 254 | + @file_put_contents(storage_path('logs/copy_mysql_error.log'), var_export('对应表插入数据:'.$result2, true) . PHP_EOL, FILE_APPEND); | ||
| 252 | // 5. 更新 project_id(如果存在) | 255 | // 5. 更新 project_id(如果存在) |
| 253 | if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) { | 256 | if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) { |
| 254 | DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]); | 257 | DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]); |
-
请 注册 或 登录 后发表评论