Skip to content

Commit

Permalink
Multiple connections support
Browse files Browse the repository at this point in the history
  • Loading branch information
babenkoivan committed Jul 28, 2022
1 parent 24c796d commit 253aadb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ You can delete an alias by its name:
Index::deleteAlias('my-index', 'my-alias');
```
#### Multiple Connections
You can configure multiple connections to Elasticsearch in the [client's configuration file](https://github.com/babenkoivan/elastic-client/tree/master#configuration),
and then use a different connection for every operation:
```php
Index::connection('my-connection')->drop('my-index');
```
#### More
Finally, you are free to inject `Elastic\Elasticsearch\Client` in the migration constructor and execute any supported by client actions.
Expand Down
7 changes: 7 additions & 0 deletions src/Adapters/IndexManagerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,11 @@ public function deleteAlias(string $indexName, string $aliasName): IndexManagerI

return $this;
}

public function connection(string $connection): IndexManagerInterface
{
$self = clone $this;
$self->indexManager = $self->indexManager->connection($connection);
return $self;
}
}
2 changes: 2 additions & 0 deletions src/IndexManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public function pushSettingsRaw(string $indexName, array $settings): self;
public function drop(string $indexName): self;

public function dropIfExists(string $indexName): self;

public function connection(string $connection): self;
}
12 changes: 12 additions & 0 deletions tests/Integration/Adapters/IndexManagerAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,18 @@ public function test_alias_can_be_deleted(string $aliasNamePrefix): void
$this->indexManagerAdapter->deleteAlias($indexName, $aliasName);
}

public function test_connection_can_be_changed(): void
{
$connection = 'test';

$this->indexManagerMock
->expects($this->once())
->method('connection')
->with($connection);

$this->indexManagerAdapter->connection($connection);
}

public function prefixProvider(): array
{
return [
Expand Down

0 comments on commit 253aadb

Please sign in to comment.