Skip to content

Commit

Permalink
Fix problem with database names using hyphens
Browse files Browse the repository at this point in the history
This will fix an issue while trying to drop/create a database having hyphens:
E.g. `event-store-db`
  • Loading branch information
icanhazstring authored and Andreas Frömer committed Jul 29, 2022
1 parent c9f84a9 commit f256b2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Console/DoctrineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ public function hasDatabase(Connection $connection, string $databaseName): bool

public function createDatabase(Connection $connection, string $databaseName): void
{
$connection->createSchemaManager()->createDatabase($databaseName);
$connection->createSchemaManager()->createDatabase(
$connection->getDatabasePlatform()->quoteSingleIdentifier($databaseName)
);
}

public function dropDatabase(Connection $connection, string $databaseName): void
{
$connection->createSchemaManager()->dropDatabase($databaseName);
$connection->createSchemaManager()->dropDatabase(
$connection->getDatabasePlatform()->quoteSingleIdentifier($databaseName)
);
}
}
7 changes: 5 additions & 2 deletions tests/Unit/Console/DoctrineHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Patchlevel\EventSourcing\Tests\Unit\Console;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use InvalidArgumentException;
use Patchlevel\EventSourcing\Console\DoctrineHelper;
Expand Down Expand Up @@ -66,9 +67,10 @@ public function testCreateDatabase(): void
$helper = new DoctrineHelper();

$schemaManager = $this->prophesize(AbstractSchemaManager::class);
$schemaManager->createDatabase('test')->shouldBeCalled();
$schemaManager->createDatabase('`test`')->shouldBeCalled();

$connection = $this->prophesize(Connection::class);
$connection->getDatabasePlatform()->willReturn(new MySQLPlatform());
$connection->createSchemaManager()->willReturn($schemaManager);

$helper->createDatabase($connection->reveal(), 'test');
Expand All @@ -79,9 +81,10 @@ public function testDropDatabase(): void
$helper = new DoctrineHelper();

$schemaManager = $this->prophesize(AbstractSchemaManager::class);
$schemaManager->dropDatabase('test')->shouldBeCalled();
$schemaManager->dropDatabase('`test`')->shouldBeCalled();

$connection = $this->prophesize(Connection::class);
$connection->getDatabasePlatform()->willReturn(new MySQLPlatform());
$connection->createSchemaManager()->willReturn($schemaManager);

$helper->dropDatabase($connection->reveal(), 'test');
Expand Down

0 comments on commit f256b2c

Please sign in to comment.