diff --git a/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php b/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php index 6dbbcb08..7f0dda63 100644 --- a/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php +++ b/src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php @@ -60,7 +60,9 @@ public function __construct(ConnectionRegistry $doctrine, array $options) public function setup(): void { $assetFilter = $this->connection->getConfiguration()->getSchemaAssetsFilter(); - $this->connection->getConfiguration()->setSchemaAssetsFilter(null); + $this->connection->getConfiguration()->setSchemaAssetsFilter( + fn(string $tableName) => $tableName === $this->table, + ); $schemaManager = method_exists($this->connection, 'createSchemaManager') ? $this->connection->createSchemaManager() diff --git a/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php b/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php index 2f8ce24a..546a4a8f 100644 --- a/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php +++ b/src/batch-doctrine-dbal/tests/DoctrineDBALJobExecutionStorageTest.php @@ -5,6 +5,8 @@ namespace Yokai\Batch\Tests\Bridge\Doctrine\DBAL; use DateTimeImmutable; +use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Types\Types; use Generator; use RuntimeException; use Throwable; @@ -31,7 +33,7 @@ private function createStorage(array $options = []): DoctrineDBALJobExecutionSto public function testCreateStandardTable(): void { - $schemaManager = $this->connection->getSchemaManager(); + $schemaManager = $this->connection->createSchemaManager(); self::assertFalse($schemaManager->tablesExist(['yokai_batch_job_execution'])); $this->createStorage()->setup(); @@ -58,7 +60,7 @@ public function testCreateStandardTable(): void public function testCreateCustomTable(): void { - $schemaManager = $this->connection->getSchemaManager(); + $schemaManager = $this->connection->createSchemaManager(); self::assertFalse($schemaManager->tablesExist(['acme_job_executions'])); $this->createStorage(['table' => 'acme_job_executions'])->setup(); @@ -83,6 +85,20 @@ public function testCreateCustomTable(): void ); } + public function testSetupPreserveOtherTables(): void + { + $schemaManager = $this->connection->createSchemaManager(); + $table = new Table('user'); + $table->addColumn('username', Types::STRING); + $schemaManager->createTable($table); + + self::assertTrue($schemaManager->tablesExist(['user'])); + self::assertFalse($schemaManager->tablesExist(['yokai_batch_job_execution'])); + $this->createStorage()->setup(); + self::assertTrue($schemaManager->tablesExist(['user'])); + self::assertTrue($schemaManager->tablesExist(['yokai_batch_job_execution'])); + } + public function testStoreInsert(): void { $storage = $this->createStorage(); @@ -345,7 +361,7 @@ public function queries(): Generator public function testCreateSchemaDeprecated(): void { - $schemaManager = $this->connection->getSchemaManager(); + $schemaManager = $this->connection->createSchemaManager(); self::assertFalse($schemaManager->tablesExist(['yokai_batch_job_execution'])); $this->createStorage()->createSchema(); self::assertTrue($schemaManager->tablesExist(['yokai_batch_job_execution']));