-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a first migration config version.
- Loading branch information
Christopher Lorke
committed
Sep 11, 2018
1 parent
039973a
commit bd4bf46
Showing
13 changed files
with
512 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
namespace Triadev\EsMigration\Business\Repository; | ||
|
||
use Triadev\EsMigration\Contract\Repository\ElasticsearchMigrationContract; | ||
|
||
class ElasticsearchMigration implements ElasticsearchMigrationContract | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function createOrUpdate( | ||
string $migration, | ||
string $status | ||
): \Triadev\EsMigration\Models\Entity\ElasticsearchMigration { | ||
$dbMigration = $this->find($migration); | ||
|
||
if (!$dbMigration) { | ||
$dbMigration = new \Triadev\EsMigration\Models\Entity\ElasticsearchMigration(); | ||
$dbMigration->migration = $migration; | ||
} | ||
|
||
$dbMigration->status = $status; | ||
$dbMigration->saveOrFail(); | ||
|
||
return $dbMigration; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function find(string $migration): ?\Triadev\EsMigration\Models\Entity\ElasticsearchMigration | ||
{ | ||
return \Triadev\EsMigration\Models\Entity\ElasticsearchMigration::where('migration', $migration) | ||
->orderBy('created_at', 'desc') | ||
->first(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function delete(string $migration) | ||
{ | ||
if ($migration = $this->find($migration)) { | ||
$migration->delete(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Contract/Repository/ElasticsearchMigrationContract.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace Triadev\EsMigration\Contract\Repository; | ||
|
||
use Triadev\EsMigration\Models\Entity\ElasticsearchMigration; | ||
|
||
interface ElasticsearchMigrationContract | ||
{ | ||
/** | ||
* Create or update | ||
* | ||
* @param string $migration | ||
* @param string $status | ||
* @return ElasticsearchMigration | ||
* | ||
* @throws \Throwable | ||
*/ | ||
public function createOrUpdate(string $migration, string $status) : ElasticsearchMigration; | ||
|
||
/** | ||
* Find | ||
* | ||
* @param string $migration | ||
* @return null|ElasticsearchMigration | ||
*/ | ||
public function find(string $migration) : ?ElasticsearchMigration; | ||
|
||
/** | ||
* Delete | ||
* | ||
* @param string $migration | ||
* @return bool | ||
* | ||
* @throws \Throwable | ||
*/ | ||
public function delete(string $migration); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Database/Migrations/2018_09_11_000000_create_elasticsearch_migration_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateElasticsearchMigrationTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('triadev_elasticsearch_migration', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->string('migration'); | ||
$table->string('status'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::drop('triadev_elasticsearch_migration'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
namespace Triadev\EsMigration\Models\Entity; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ElasticsearchMigration extends Model | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'triadev_elasticsearch_migration'; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'migration', | ||
'status' | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
namespace Triadev\EsMigration\Models; | ||
|
||
class Migration | ||
{ | ||
/** @var string */ | ||
private $index; | ||
|
||
/** @var string */ | ||
private $type; | ||
|
||
/** @var array|null */ | ||
private $mappings; | ||
|
||
/** @var array|null */ | ||
private $settings; | ||
|
||
/** | ||
* Migrations constructor. | ||
* @param string $index | ||
* @param string $type | ||
*/ | ||
public function __construct(string $index, string $type) | ||
{ | ||
$this->index = $index; | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getIndex(): string | ||
{ | ||
return $this->index; | ||
} | ||
|
||
/** | ||
* @param string $index | ||
*/ | ||
public function setIndex(string $index) | ||
{ | ||
$this->index = $index; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
*/ | ||
public function setType(string $type) | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* @return array|null | ||
*/ | ||
public function getMappings(): ?array | ||
{ | ||
return $this->mappings; | ||
} | ||
|
||
/** | ||
* @param array|null $mappings | ||
*/ | ||
public function setMappings(?array $mappings) | ||
{ | ||
$this->mappings= $mappings; | ||
} | ||
|
||
/** | ||
* @return array|null | ||
*/ | ||
public function getSettings(): ?array | ||
{ | ||
return $this->settings; | ||
} | ||
|
||
/** | ||
* @param array|null $settings | ||
*/ | ||
public function setSettings(?array $settings): void | ||
{ | ||
$this->settings = $settings; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.