Skip to content

Commit

Permalink
Delete file migrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Lorke committed Oct 18, 2018
1 parent 458c27b commit f80b1ea
Show file tree
Hide file tree
Showing 43 changed files with 756 additions and 2,508 deletions.
35 changes: 0 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,6 @@ Elasticsearch migration for laravel.
The package is registered through the package discovery of laravel and Composer.
>https://laravel.com/docs/5.6/packages
## Configuration
| Key | ENV | Value | Description |
|:-------------:|-------------:|:-------------:|:-----:|
| host | ELASTICSEARCH_HOST | STRING | Host |
| port | ELASTICSEARCH_PORT | INTEGER | Default: 9200 |
| scheme | ELASTICSEARCH_SCHEME | STRING | https or http |
| user | ELASTICSEARCH_USER | STRING | Username |
| pass | ELASTICSEARCH_PASS | STRING | Password |
| migration.filePath | --- | STRING | File path for migration scripts |

## Usage

### Build migration
>Triadev\EsMigration\Business\Factory\MigrationBuilder::TYPE()
- createIndex
- updateIndex
- deleteIndex
- alias
- reindex
- deleteByQuery
- updateByQuery

### Commands

#### Start migration
Orchestra migrations
>php artisan triadev:elasticsearch:migrate:start VERSIONS
Example:
>php artisan triadev:elasticsearch:migrate:start migration1,migration2,migration3
#### Show migrations
>php artisan triadev:elasticsearch:migration:show
### Events
[Documentation: Laravel Events](https://laravel.com/docs/5.7/events)

Expand Down
13 changes: 0 additions & 13 deletions examples/addAndRemoveAlias/migrations.php

This file was deleted.

36 changes: 0 additions & 36 deletions examples/createAndUpdateIndex/migrations.php

This file was deleted.

19 changes: 0 additions & 19 deletions examples/createIndex/migrations.php

This file was deleted.

16 changes: 0 additions & 16 deletions examples/deleteByQuery/migrations.php

This file was deleted.

5 changes: 0 additions & 5 deletions examples/deleteIndex/migrations.php

This file was deleted.

9 changes: 0 additions & 9 deletions examples/reindex/migrations.php

This file was deleted.

20 changes: 0 additions & 20 deletions examples/updateByQuery/migrations.php

This file was deleted.

21 changes: 0 additions & 21 deletions examples/updateIndex/migrations.php

This file was deleted.

1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="ELASTICSEARCH_PORT" value="9222"/>
</php>
</phpunit>
32 changes: 32 additions & 0 deletions src/Business/Mapper/MigrationStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace Triadev\EsMigration\Business\Mapper;

class MigrationStatus
{
const MIGRATION_STATUS_WAIT = 0;
const MIGRATION_STATUS_RUNNING = 1;
const MIGRATION_STATUS_DONE = 2;
const MIGRATION_STATUS_ERROR = 3;

/**
* Is migration status valid
*
* @param int $status
* @return bool
*/
public function isMigrationStatusValid(int $status) : bool
{
$valid = [
self::MIGRATION_STATUS_WAIT,
self::MIGRATION_STATUS_RUNNING,
self::MIGRATION_STATUS_DONE,
self::MIGRATION_STATUS_ERROR
];

if (in_array($status, $valid)) {
return true;
}

return false;
}
}
36 changes: 36 additions & 0 deletions src/Business/Mapper/MigrationTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace Triadev\EsMigration\Business\Mapper;

class MigrationTypes
{
const MIGRATION_TYPE_CREATE_INDEX = 'createIndex';
const MIGRATION_TYPE_UPDATE_INDEX = 'updateIndex';
const MIGRATION_TYPE_DELETE_INDEX = 'deleteIndex';
const MIGRATION_TYPE_ALIAS = 'alias';
const MIGRATION_TYPE_DELETE_BY_QUERY = 'deleteByQuery';
const MIGRATION_TYPE_UPDATE_BY_QUERY = 'updateByQuery';
const MIGRATION_TYPE_REINDEX = 'reindex';

/**
* Is migration type valid
*
* @param string $type
* @return bool
*/
public function isMigrationTypeValid(string $type) : bool
{
if (in_array($type, [
self::MIGRATION_TYPE_CREATE_INDEX,
self::MIGRATION_TYPE_UPDATE_INDEX,
self::MIGRATION_TYPE_DELETE_INDEX,
self::MIGRATION_TYPE_ALIAS,
self::MIGRATION_TYPE_DELETE_BY_QUERY,
self::MIGRATION_TYPE_UPDATE_BY_QUERY,
self::MIGRATION_TYPE_REINDEX,
])) {
return true;
}

return false;
}
}
2 changes: 1 addition & 1 deletion src/Business/Migration/CreateIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function migrate(Client $esClient, \Triadev\EsMigration\Models\Migrations
if ($migration->getSettings()) {
$body['settings'] = $migration->getSettings();
}

$esClient->indices()->create([
'index' => $migration->getIndex(),
'body' => $body
Expand Down
74 changes: 74 additions & 0 deletions src/Business/Repository/ElasticsearchClients.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
namespace Triadev\EsMigration\Business\Repository;

use Elasticsearch\Client;
use Elasticsearch\ClientBuilder;

class ElasticsearchClients
{
/**
* @var array
*/
private $elasticsearchClients = [];

/** @var ClientBuilder */
private $clientBuilder;

/**
* ElasticsearchClients constructor.
*/
public function __construct()
{
$this->clientBuilder = ClientBuilder::create();
}

/**
* Add
*
* @param string $esClientKey
* @param string $host
* @param int $port
* @param string $scheme
* @param null|string $user
* @param null|string $password
*/
public function add(
string $esClientKey,
string $host,
int $port,
string $scheme,
?string $user = null,
?string $password = null
) {
$this->elasticsearchClients[$esClientKey] = $this->clientBuilder->setHosts([
[
'host' => $host,
'port' => $port,
'scheme' => $scheme,
'user' => $user,
'pass' => $password
]
])->build();
}

/**
* Get
*
* @param string $esClientKey
* @return Client|null
*/
public function get(string $esClientKey) : ?Client
{
return array_get($this->elasticsearchClients, $esClientKey);
}

/**
* All
*
* @return Client[]
*/
public function all() : array
{
return $this->elasticsearchClients;
}
}
Loading

0 comments on commit f80b1ea

Please sign in to comment.