調整 同步Branch 資料會全部到分店去的問題 v3 20250616
This commit is contained in:
parent
046c880676
commit
a943c75a44
@ -8,7 +8,6 @@ use Illuminate\Support\Collection;
|
|||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class SqliteExportService
|
class SqliteExportService
|
||||||
{
|
{
|
||||||
@ -60,9 +59,7 @@ class SqliteExportService
|
|||||||
public function exportMultiple(array $tables): void
|
public function exportMultiple(array $tables): void
|
||||||
{
|
{
|
||||||
foreach ($tables as $tableName => $config) {
|
foreach ($tables as $tableName => $config) {
|
||||||
Log::info("[SqliteExport] Processing table: {$tableName}");
|
|
||||||
$this->dropAndCreateTable($tableName, $config['tableSchema']);
|
$this->dropAndCreateTable($tableName, $config['tableSchema']);
|
||||||
Log::info("[SqliteExport] Created table schema: {$tableName}");
|
|
||||||
$transformer = $config['transformer'] ?? fn($row) => (array)$row;
|
$transformer = $config['transformer'] ?? fn($row) => (array)$row;
|
||||||
|
|
||||||
if (isset($config['modelClass'])) {
|
if (isset($config['modelClass'])) {
|
||||||
@ -74,7 +71,6 @@ class SqliteExportService
|
|||||||
$rows = $chunk->map($transformer)->toArray();
|
$rows = $chunk->map($transformer)->toArray();
|
||||||
$this->insertData($tableName, $rows);
|
$this->insertData($tableName, $rows);
|
||||||
});
|
});
|
||||||
Log::info("[SqliteExport] Exported {$totalCount} records to {$tableName} (via model)");
|
|
||||||
} elseif (isset($config['query']) && is_callable($config['query'])) {
|
} elseif (isset($config['query']) && is_callable($config['query'])) {
|
||||||
$rows = call_user_func($config['query']);
|
$rows = call_user_func($config['query']);
|
||||||
|
|
||||||
@ -84,13 +80,11 @@ class SqliteExportService
|
|||||||
|
|
||||||
$data = $rows->map($transformer)->toArray();
|
$data = $rows->map($transformer)->toArray();
|
||||||
$this->insertData($tableName, $data);
|
$this->insertData($tableName, $data);
|
||||||
Log::info("[SqliteExport] Exported " . count($data) . " records to {$tableName} (via query)");
|
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException("Each table config must define either 'modelClass' or 'query'.");
|
throw new \InvalidArgumentException("Each table config must define either 'modelClass' or 'query'.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->purge();
|
$this->purge();
|
||||||
Log::info("[SqliteExport] Connection purged: {$this->connection}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function dropAndCreateTable(string $table, Closure $schema): void
|
protected function dropAndCreateTable(string $table, Closure $schema): void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user