Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Console/DumpDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

class DumpDatabaseCommand extends Command
{
protected $signature = 'db:masked-dump {output} {--definition=default} {--gzip}';
protected $signature = 'db:masked-dump {output} {--definition=default} {--gzip} {--schema=}';

protected $description = 'Create a new database dump';

public function handle()
{
$definition = config('masked-dump.' . $this->option('definition'));
$definition = is_callable($definition) ? call_user_func($definition) : $definition;
$definition->load();
$definition->load($this->option('schema'));

$this->info('Starting Database dump');

Expand Down
8 changes: 4 additions & 4 deletions src/DumpSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ public function getDumpTables()
return $this->dumpTables;
}

protected function loadAvailableTables()
protected function loadAvailableTables(?string $schema = null)
{
if ($this->availableTables !== []) {
return;
}

$this->availableTables = $this->createDoctrineTables($this->getBuilder()->getTables());
$this->availableTables = $this->createDoctrineTables($this->getBuilder()->getTables($schema));
}

protected function createDoctrineTables(array $tables): array
Expand All @@ -152,9 +152,9 @@ protected function createDoctrineTables(array $tables): array
return $doctrineTables;
}

public function load()
public function load(?string $schema)
{
$this->loadAvailableTables();
$this->loadAvailableTables($schema);

if ($this->loadAllTables) {
$dumpTables = collect($this->availableTables)->mapWithKeys(function (Table $table) {
Expand Down
19 changes: 19 additions & 0 deletions tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace BeyondCode\LaravelMaskedDumper\Tests;

use Mockery\MockInterface;
use PHPUnit\Framework\Attributes\Test;
use BeyondCode\LaravelMaskedDumper\DumpSchema;
use BeyondCode\LaravelMaskedDumper\LaravelMaskedDumpServiceProvider;
use BeyondCode\LaravelMaskedDumper\TableDefinitions\TableDefinition;
Expand Down Expand Up @@ -341,4 +343,21 @@ public function it_still_includes_tables_with_repeated_use_of_include()

$this->assertMatchesTextSnapshot(file_get_contents($outputFile));
}

#[Test]
public function it_can_specify_the_schema(): void
{
$mock = $this->partialMock(DumpSchema::class, function (MockInterface $mock) {
$mock->shouldReceive('load')->with('my_schema')->once();
});

$this->app['config']['masked-dump.default'] = $mock;

$outputFile = base_path('test.sql');

$this->artisan('db:masked-dump', [
'output' => $outputFile,
'--schema' => 'my_schema',
]);
}
}