Skip to content

Commit ef33182

Browse files
authored
Merge pull request #127 from daniel-de-wit/main
Support connect_via_database
2 parents 48ed4e7 + 74c25bf commit ef33182

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/DbDumperFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ public static function createForConnection(string $connectionName): DbDumper
3232
$fallback
3333
);
3434

35+
$dbName = $dbConfig['connect_via_database'] ?? $dbConfig['database'];
36+
3537
$dbDumper = static::forDriver($dbConfig['driver'])
3638
->setHost($dbHost ?? '')
37-
->setDbName($dbConfig['database'])
39+
->setDbName($dbName)
3840
->setUserName($dbConfig['username'] ?? '')
3941
->setPassword($dbConfig['password'] ?? '');
4042

tests/DbDumperFactoryTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ public function it_will_use_the_read_db_when_one_is_defined()
7171
$this->assertEquals('localhost-read', $dumper->getHost());
7272
}
7373

74+
/** @test */
75+
public function it_will_use_connect_via_database_when_one_is_defined()
76+
{
77+
$dbConfig = [
78+
'driver' => 'pgsql',
79+
'connect_via_database' => 'connection_pool',
80+
'username' => 'root',
81+
'password' => 'myPassword',
82+
'database' => 'myDb',
83+
'dump' => ['add_extra_option' => '--extra-option=value'],
84+
];
85+
86+
$this->app['config']->set('database.connections.pgsql', $dbConfig);
87+
88+
$dumper = DbDumperFactory::createForConnection('pgsql');
89+
90+
$this->assertEquals('connection_pool', $dumper->getDbName());
91+
}
92+
7493
/** @test */
7594
public function it_will_throw_an_exception_when_creating_an_unknown_type_of_dumper()
7695
{

0 commit comments

Comments
 (0)