babenkoivan / elastic-migrations

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

`elastic:migrate:fresh` calls `truncate()`, which breaks testing with MySQL due to transaction closing #34

Closed stevebauman closed 2 years ago

stevebauman commented 2 years ago
Software Version
PHP 8.0
Elasticsearch 6.8.10
Laravel 8.77.*

Describe the bug The elastic:migrate:fresh command calls truncate() on the Laravel database query builder which closes open transactions during testing with MySQL using the RefreshDatabase trait, causing the following exception to be thrown upon tearDown():

PDOException: There is no active transaction

/Users/stevebauman/Sites/App/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:279
/Users/stevebauman/Sites/App/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:254
/Users/stevebauman/Sites/App/vendor/laravel/framework/src/Illuminate/Foundation/Testing/RefreshDatabase.php:104
/Users/stevebauman/Sites/App/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:246
/Users/stevebauman/Sites/App/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:158
/Users/stevebauman/Sites/App/tests/Feature/MyTest.php:28

To Reproduce

class MyTest extends TestCase
{
    protected function setUp(): void
    {
        parent::setUp();

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

    public function test()
    {
        // Create some eloquent record...
        Foo::factory()->create();
    }
}

Expected behavior The migration repository should instead have all records deleted, instead of the table being truncated.