-
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.
Save audit logs when a migration event is thrown.
- Loading branch information
Christopher Lorke
committed
Oct 21, 2018
1 parent
65c982b
commit c912753
Showing
7 changed files
with
182 additions
and
1 deletion.
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
24 changes: 24 additions & 0 deletions
24
src/Business/Repository/ElasticsearchMigrationStepAuditLog.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,24 @@ | ||
<?php | ||
namespace Triadev\EsMigration\Business\Repository; | ||
|
||
use Triadev\EsMigration\Contract\Repository\ElasticsearchMigrationStepAuditLogContract; | ||
|
||
class ElasticsearchMigrationStepAuditLog implements ElasticsearchMigrationStepAuditLogContract | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function create( | ||
int $migrationStepId, | ||
int $status | ||
): \Triadev\EsMigration\Models\Entity\ElasticsearchMigrationStepAuditLog { | ||
$entity = new \Triadev\EsMigration\Models\Entity\ElasticsearchMigrationStepAuditLog(); | ||
|
||
$entity->migration_step_id = $migrationStepId; | ||
$entity->status = $status; | ||
|
||
$entity->saveOrFail(); | ||
|
||
return $entity; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Contract/Repository/ElasticsearchMigrationStepAuditLogContract.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,21 @@ | ||
<?php | ||
namespace Triadev\EsMigration\Contract\Repository; | ||
|
||
use Triadev\EsMigration\Models\Entity\ElasticsearchMigrationStepAuditLog; | ||
|
||
interface ElasticsearchMigrationStepAuditLogContract | ||
{ | ||
/** | ||
* Create | ||
* | ||
* @param int $migrationStepId | ||
* @param int $status | ||
* @return ElasticsearchMigrationStepAuditLog | ||
* | ||
* @throws \Throwable | ||
*/ | ||
public function create( | ||
int $migrationStepId, | ||
int $status | ||
) : ElasticsearchMigrationStepAuditLog; | ||
} |
40 changes: 40 additions & 0 deletions
40
...rations/2018_10_21_000000_create_triadev_elasticsearch_migration_step_audit_log_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,40 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateTriadevElasticsearchMigrationStepAuditLogTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::enableForeignKeyConstraints(); | ||
|
||
Schema::create('triadev_elasticsearch_migration_step_audit_log', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->unsignedBigInteger('migration_step_id'); | ||
$table->integer('status'); | ||
$table->timestamps(); | ||
|
||
$table->foreign('migration_step_id') | ||
->references('id') | ||
->on('triadev_elasticsearch_migration_step') | ||
->onDelete('cascade'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::drop('triadev_elasticsearch_migration_step_audit_log'); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
namespace Triadev\EsMigration\Models\Entity; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @property integer $id | ||
* @property integer $migration_step_id | ||
* @property integer $status | ||
* @property string $created_at | ||
* @property string $updated_at | ||
*/ | ||
class ElasticsearchMigrationStepAuditLog extends Model | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'triadev_elasticsearch_migration_step_audit_log'; | ||
} |
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
67 changes: 67 additions & 0 deletions
67
tests/integration/Business/Repository/ElasticsearchMigrationStepAuditLogTest.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,67 @@ | ||
<?php | ||
namespace Tests\Integration\Business\Repository; | ||
|
||
use Tests\TestCase; | ||
use Triadev\EsMigration\Business\Mapper\MigrationStatus; | ||
use Triadev\EsMigration\Business\Mapper\MigrationTypes; | ||
use Triadev\EsMigration\Contract\Repository\ElasticsearchMigrationStepAuditLogContract; | ||
use Triadev\EsMigration\Contract\Repository\ElasticsearchMigrationContract; | ||
use Triadev\EsMigration\Contract\Repository\ElasticsearchMigrationStepContract; | ||
use Triadev\EsMigration\Models\Entity\ElasticsearchMigrationStepAuditLog; | ||
|
||
class ElasticsearchMigrationStepAuditLogTest extends TestCase | ||
{ | ||
/** @var ElasticsearchMigrationContract */ | ||
private $repositoryMigration; | ||
|
||
/** @var ElasticsearchMigrationStepContract */ | ||
private $repositoryMigrationStep; | ||
|
||
/** @var ElasticsearchMigrationStepAuditLogContract */ | ||
private $repository; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->repositoryMigration = app(ElasticsearchMigrationContract::class); | ||
$this->repositoryMigrationStep = app(ElasticsearchMigrationStepContract::class); | ||
$this->repository = app(ElasticsearchMigrationStepAuditLogContract::class); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_creates_a_migration() | ||
{ | ||
$this->assertEquals(0, ElasticsearchMigrationStepAuditLog::all()->count()); | ||
|
||
$migration = $this->repositoryMigration->createOrUpdate('phpunit'); | ||
|
||
$migrationStep = $this->repositoryMigrationStep->create( | ||
$migration->id, | ||
MigrationTypes::MIGRATION_TYPE_CREATE_INDEX, | ||
[], | ||
1, | ||
true | ||
); | ||
|
||
$this->assertInstanceOf( | ||
ElasticsearchMigrationStepAuditLog::class, | ||
$this->repository->create( | ||
$migrationStep->id, | ||
MigrationStatus::MIGRATION_STATUS_RUNNING | ||
) | ||
); | ||
|
||
$this->assertInstanceOf( | ||
ElasticsearchMigrationStepAuditLog::class, | ||
$this->repository->create( | ||
$migrationStep->id, | ||
MigrationStatus::MIGRATION_STATUS_DONE | ||
) | ||
); | ||
|
||
$this->assertEquals(2, ElasticsearchMigrationStepAuditLog::all()->count()); | ||
} | ||
} |