babenkoivan / elastic-migrations

Elasticsearch migrations for Laravel
MIT License
187 stars 32 forks source link

Add elastic:migration:fresh command #24

Closed stevebauman closed 3 years ago

stevebauman commented 3 years ago

Purpose

This PR adds the elastic:migrate:fresh command. It mirrors Laravel's migrate:fresh command, which drops all database tables and re-runs all migrations. In this case, we drop all indicies and re-run migrations.

Description

When I'm running my integration tests that use ElasticSearch, I'm unable to use any provided command to drop all of the (non-system) indicies with an empty elastic_migrations table. If I need to drop any index, I have to use a raw command, or insert the migration into the DB table manually and then run elastic:migrate:rollback.

This would allow us to easily use the below in our integration tests, making sure we have a completely fresh ES instance to work with during each test-case:

public function setUp(): void
{
    parent::setUp();

    $this->artisan('elastic:migrate:fresh');
}

public function test_with_clean_indexes()
{
    // My integration test...
}

More Info

The pattern used here:

$this->indexManager->get('*,-*.*');

Will fetch all non-system indicies (ones that are prefixed with a period), excluding indexes such as Kibana indexes (.kibana, .kibana_task_manager).

Dependents

This PR relies on the recently submitted PR here:

https://github.com/babenkoivan/elastic-adapter/pull/12


As always, please let me know if you have any issues with the implementation. I'd love to work with you to get this implemented.

Thanks for your time! ā¤ļø

stevebauman commented 3 years ago

Okay I've updated my PR. Everything's green.

Note -- I had to remove the final class declaration of the MigrationRepository so I could successfully test the FreshCommand.

babenkoivan commented 3 years ago

Hey @stevebauman, the new command is available since v1.6.0 šŸŽ‰

christian-at-sevenlab commented 3 years ago

@babenkoivan You forgot to add it to the ServiceProvider commands array. (Currently its still not available as artisan command)

babenkoivan commented 3 years ago

@christian-at-7lab ah.. what a shame! thank you for pointing it out! it's fixed now in v1.6.1.

stevebauman commented 3 years ago

Thanks @babenkoivan! Appreciate your time šŸ‘