Skip to content

Commit

Permalink
Preserve other tables during dbal storage setup (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
yann-eugone authored Dec 7, 2023
1 parent 9fe827c commit 9c5a049
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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']));
Expand Down

0 comments on commit 9c5a049

Please sign in to comment.