|
...
|
...
|
@@ -350,17 +350,27 @@ class UpdateRoute extends Command |
|
|
|
{
|
|
|
|
$sourceTable = 'gl_route_map';
|
|
|
|
$destinationTable = 'gl_route_map_copy';
|
|
|
|
|
|
|
|
if (!Schema::connection('custom_mysql')->hasTable($sourceTable)) {
|
|
|
|
$this->error("Source table {$sourceTable} does not exist.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Schema::connection('custom_mysql')->hasTable($destinationTable)) {
|
|
|
|
Schema::connection('custom_mysql')->dropIfExists($destinationTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
$columns = DB::connection('custom_mysql')->select(DB::raw("SHOW COLUMNS FROM {$sourceTable}"));
|
|
|
|
$columnsDefinition = collect($columns)->map(function($column) {
|
|
|
|
return $column->Field . ' ' . $column->Type . ($column->Null === 'NO' ? ' NOT NULL' : '') . ($column->Default !== null ? " DEFAULT '" . $column->Default . "'" : '') . ($column->Extra ? ' ' . $column->Extra : '');
|
|
|
|
$columnDefinition = $column->Field . ' ' . $column->Type .
|
|
|
|
($column->Null === 'NO' ? ' NOT NULL' : '') .
|
|
|
|
($column->Default !== null ? " DEFAULT '" . $column->Default . "'" : '') .
|
|
|
|
($column->Extra ? ' ' . $column->Extra : '');
|
|
|
|
return $columnDefinition;
|
|
|
|
})->implode(', ');
|
|
|
|
// Add PRIMARY KEY to the id column
|
|
|
|
$primaryKey = collect($columns)->firstWhere('Field', 'id') ? 'PRIMARY KEY (id)' : '';
|
|
|
|
$columnsDefinition = $columnsDefinition . ($primaryKey ? ', ' . $primaryKey : '');
|
|
|
|
DB::connection('custom_mysql')->statement("CREATE TABLE {$destinationTable} ({$columnsDefinition})");
|
|
|
|
DB::connection('custom_mysql')->statement("INSERT INTO {$destinationTable} SELECT * FROM {$sourceTable}");
|
|
|
|
$this->info("Table {$sourceTable} has been copied to {$destinationTable} successfully.");
|
...
|
...
|
|