Skip to content

Commit

Permalink
Orchestra migrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Lorke committed Sep 18, 2018
1 parent 2ea4bba commit 2da748e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ The package is registered through the package discovery of laravel and Composer.
## Usage

### Start migration
>php artisan triadev:elasticsearch:migrate:start VERSION
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
Expand Down
8 changes: 6 additions & 2 deletions src/Console/Commands/StartMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class StartMigration extends Command
* @var string
*/
protected $signature = 'triadev:elasticsearch:migration:start
{version : version of migration}';
{versions : versions of migrations}';

/**
* The console command description.
Expand All @@ -31,6 +31,10 @@ class StartMigration extends Command
*/
public function handle(ElasticsearchMigrationContract $elasticsearchMigration)
{
$elasticsearchMigration->migrate($this->argument('version'));
$versions = explode(',', $this->argument('versions'));

foreach ($versions as $version) {
$elasticsearchMigration->migrate(trim($version));
}
}
}
28 changes: 27 additions & 1 deletion tests/integration/Console/Commands/StartMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public function setUp()
'index' => 'phpunit'
]);
}

if ($this->esClient->indices()->exists(['index' => 'phpunit_1.0.1'])) {
$this->esClient->indices()->delete([
'index' => 'phpunit_1.0.1'
]);
}

$this->migrationRepository = app(
\Triadev\EsMigration\Contract\Repository\ElasticsearchMigrationContract::class
Expand Down Expand Up @@ -64,7 +70,7 @@ public function it_creates_and_updates_mappings_and_settings_with_command()
'index' => 'phpunit'
]));

$this->artisan('triadev:elasticsearch:migration:start', ['version' => '1.0.0']);
$this->artisan('triadev:elasticsearch:migration:start', ['versions' => '1.0.0']);

$this->assertTrue($this->esClient->indices()->exists(['index' => 'phpunit']));

Expand All @@ -89,4 +95,24 @@ public function it_creates_and_updates_mappings_and_settings_with_command()
$this->assertEquals('1.0.0', $migration->migration);
$this->assertEquals('done', $migration->status);
}

/**
* @test
*/
public function it_starts_to_orchestra_migrations()
{
$this->assertNull($this->migrationRepository->find('1.0.0'));
$this->assertNull($this->migrationRepository->find('1.0.1'));

$this->assertFalse($this->esClient->indices()->exists([
'index' => 'phpunit,phpunit_1.0.1'
]));

$this->artisan('triadev:elasticsearch:migration:start', ['versions' => '1.0.0, 1.0.1']);

$this->assertTrue($this->esClient->indices()->exists(['index' => 'phpunit,phpunit_1.0.1']));

$this->assertEquals('done', $this->migrationRepository->find('1.0.0')->status);
$this->assertEquals('done', $this->migrationRepository->find('1.0.1')->status);
}
}

0 comments on commit 2da748e

Please sign in to comment.