-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5eeb7cb
commit 88a8e97
Showing
7 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
return [ | ||
'schema' => [ | ||
/* | ||
* Here you need to list all the names of the tables for which you need to dump data. | ||
*/ | ||
|
||
'tables' => [], | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DragonCode\LaravelDataDumper\Listeners; | ||
|
||
use DragonCode\LaravelDataDumper\Service\Dumper; | ||
use DragonCode\LaravelDataDumper\Service\Tables; | ||
use Illuminate\Database\Events\SchemaDumped; | ||
|
||
class DataDumpListener | ||
{ | ||
public function __construct( | ||
protected readonly Tables $tables, | ||
protected readonly Dumper $dumper | ||
) { | ||
} | ||
|
||
public function handle(SchemaDumped $event): void | ||
{ | ||
$this->dumper->dump( | ||
$event->connection, | ||
$event->path, | ||
$this->tables->dumpable() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DragonCode\LaravelDataDumper\Service; | ||
|
||
use Illuminate\Database\Connection; | ||
|
||
class Dumper | ||
{ | ||
public function dump(Connection $connection, string $path, array $tables): void | ||
{ | ||
foreach ($tables as $table) { | ||
$this->export($connection, $path, $table); | ||
} | ||
} | ||
|
||
protected function export(Connection $connection, string $path, string $table): void | ||
{ | ||
// export table data to file | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DragonCode\LaravelDataDumper\Service; | ||
|
||
use stdClass; | ||
|
||
class Tables | ||
{ | ||
public function dumpable(): array | ||
{ | ||
return array_intersect($this->flatten(), $this->toDump()); | ||
} | ||
|
||
protected function toDump(): array | ||
{ | ||
return config('database.schema.tables', []); | ||
} | ||
|
||
protected function flatten(): array | ||
{ | ||
return array_map(function (array | stdClass $item) { | ||
return is_array($item) ? $item['name'] : $item->name; | ||
}, $this->getTables()); | ||
} | ||
|
||
protected function getTables(): array | ||
{ | ||
return method_exists($this->schema(), 'getAllTables') | ||
? $this->schema()->getAllTables() | ||
: $this->schema()->getTables(); | ||
} | ||
|
||
protected function schema() | ||
{ | ||
return app('db.schema'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters