Skip to content

Commit

Permalink
Merge pull request Sammyjo20#3 from amaelftah/support-multiple-db-con…
Browse files Browse the repository at this point in the history
…nection

Support multiple db connection
  • Loading branch information
ksimenic authored Feb 21, 2023
2 parents 66169f0 + e0b25c5 commit 3ab0ee9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions config/haystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,15 @@

'keep_finished_haystacks_for_days' => 1,

/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which database connectionsyou wish
| to use to store haystack jobs .
|
*/

'db_connection' => env('DB_CONNECTION'),
];
10 changes: 10 additions & 0 deletions src/Models/Haystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,14 @@ public function getFinishedAttribute(): bool
{
return $this->finished_at instanceof CarbonImmutable;
}

/**
* Get the current connection name for the model.
*
* @return string|null
*/
public function getConnectionName()
{
return config('haystack.db_connection');
}
}
10 changes: 10 additions & 0 deletions src/Models/HaystackBale.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,14 @@ public function configuredJob(): StackableJob

return $job;
}

/**
* Get the current connection name for the model.
*
* @return string|null
*/
public function getConnectionName()
{
return config('haystack.db_connection');
}
}
10 changes: 10 additions & 0 deletions src/Models/HaystackData.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ public function getValueAttribute($value): mixed

return $this->castAttribute('value', $value);
}

/**
* Get the current connection name for the model.
*
* @return string|null
*/
public function getConnectionName()
{
return config('haystack.db_connection');
}
}
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function getApplicationTimezone($app)

public function getEnvironmentSetUp($app)
{
config()->set('haystack.db_connection', 'testing');
config()->set('database.default', 'testing');
config()->set('database.connections.testing.foreign_key_constraints', true);
config()->set('haystack.process_automatically', false);
Expand Down

0 comments on commit 3ab0ee9

Please sign in to comment.