|
@@ -244,20 +244,18 @@ class CopyProject extends Command |
|
@@ -244,20 +244,18 @@ class CopyProject extends Command |
|
244
|
if (!$exists) {
|
244
|
if (!$exists) {
|
|
245
|
@file_put_contents(
|
245
|
@file_put_contents(
|
|
246
|
storage_path('logs/copy_mysql_error.log'),
|
246
|
storage_path('logs/copy_mysql_error.log'),
|
|
247
|
- "源库中不存在表:{$table}" . PHP_EOL,
|
247
|
+ date('Y-m-d H:i:s')."源库中不存在表:{$table}" . PHP_EOL,
|
|
248
|
FILE_APPEND
|
248
|
FILE_APPEND
|
|
249
|
);
|
249
|
);
|
|
250
|
continue;
|
250
|
continue;
|
|
251
|
}
|
251
|
}
|
|
252
|
// 2. 删除目标数据库中的表
|
252
|
// 2. 删除目标数据库中的表
|
|
253
|
$result = DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS `{$table}`");
|
253
|
$result = DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS `{$table}`");
|
|
254
|
- @file_put_contents(storage_path('logs/copy_mysql_error.log'), "删除旧表:{$table} => {$result}" . PHP_EOL, FILE_APPEND);
|
|
|
|
255
|
// 3. 复制建表 SQL
|
254
|
// 3. 复制建表 SQL
|
|
256
|
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE `{$table}`");
|
255
|
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE `{$table}`");
|
|
257
|
$createSql = get_object_vars($sql[0])['Create Table'];
|
256
|
$createSql = get_object_vars($sql[0])['Create Table'];
|
|
258
|
$result1 = DB::connection('custom_mysql')->statement($createSql);
|
257
|
$result1 = DB::connection('custom_mysql')->statement($createSql);
|
|
259
|
- @file_put_contents(storage_path('logs/copy_mysql_error.log'), "创建表:{$table} => {$result1}" . PHP_EOL, FILE_APPEND);
|
|
|
|
260
|
-
|
258
|
+ @file_put_contents(storage_path('logs/copy_mysql_error.log'), date('Y-m-d H:i:s')."创建表:{$table} => {$result1}" . PHP_EOL, FILE_APPEND);
|
|
261
|
// 4. 跳过指定表
|
259
|
// 4. 跳过指定表
|
|
262
|
if (in_array($table, [
|
260
|
if (in_array($table, [
|
|
263
|
'gl_customer_visit', 'gl_customer_visit_item',
|
261
|
'gl_customer_visit', 'gl_customer_visit_item',
|
|
@@ -268,14 +266,13 @@ class CopyProject extends Command |
|
@@ -268,14 +266,13 @@ class CopyProject extends Command |
|
268
|
}
|
266
|
}
|
|
269
|
// 5. 插入数据前,再次确认源表存在(双保险)
|
267
|
// 5. 插入数据前,再次确认源表存在(双保险)
|
|
270
|
if (!Schema::connection('custom_tmp_mysql_copy')->hasTable($table)) {
|
268
|
if (!Schema::connection('custom_tmp_mysql_copy')->hasTable($table)) {
|
|
271
|
- @file_put_contents(storage_path('logs/copy_mysql_error.log'), "插入数据前发现表不存在:{$table}" . PHP_EOL, FILE_APPEND);
|
|
|
|
272
|
continue;
|
269
|
continue;
|
|
273
|
}
|
270
|
}
|
|
274
|
// 6. 原生 SQL 插入数据(完全复制)
|
271
|
// 6. 原生 SQL 插入数据(完全复制)
|
|
275
|
$insert_sql = "INSERT INTO `{$table}` SELECT * FROM `gl_data_{$project_id}`.`{$table}`";
|
272
|
$insert_sql = "INSERT INTO `{$table}` SELECT * FROM `gl_data_{$project_id}`.`{$table}`";
|
|
276
|
try {
|
273
|
try {
|
|
277
|
$result2 = DB::connection('custom_mysql')->statement($insert_sql);
|
274
|
$result2 = DB::connection('custom_mysql')->statement($insert_sql);
|
|
278
|
- @file_put_contents(storage_path('logs/copy_mysql_error.log'), "插入数据成功:{$table} => {$result2}" . PHP_EOL, FILE_APPEND);
|
275
|
+ @file_put_contents(storage_path('logs/copy_mysql_error.log'), date('Y-m-d H:i:s')."插入数据成功:{$table} => {$result2}" . PHP_EOL, FILE_APPEND);
|
|
279
|
} catch (\Exception $e) {
|
276
|
} catch (\Exception $e) {
|
|
280
|
@file_put_contents(storage_path('logs/copy_mysql_error.log'),
|
277
|
@file_put_contents(storage_path('logs/copy_mysql_error.log'),
|
|
281
|
"插入数据失败:{$table} => " . $e->getMessage() . PHP_EOL,
|
278
|
"插入数据失败:{$table} => " . $e->getMessage() . PHP_EOL,
|