Skip to content

Commit 0765c47

Browse files
committed
Adding "USE" statement when resetting database for MySQL.
This allows reusing the connection as soon as DB is created.
1 parent c47654a commit 0765c47

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Mouf/Database/Patcher/AbstractDatabasePatch.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected function saveDbSchema()
154154
{
155155
$schema = $this->patchConnection->getConnection()->getSchemaManager()->createSchema();
156156
file_put_contents(__DIR__.'/../../../../generated/schema', serialize($schema));
157-
chmod(__DIR__.'/../../../../generated/schema', 0664);
157+
@chmod(__DIR__.'/../../../../generated/schema', 0664);
158158
}
159159

160160
/**

src/Mouf/Database/Patcher/PatchConnection.php

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace Mouf\Database\Patcher;
2222

2323
use Doctrine\DBAL\Connection;
24+
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
2425
use Mouf\Utils\Patcher\PatchListenerInterface;
2526

2627

@@ -102,5 +103,9 @@ public function onReset(): void
102103
// Let's drop and recreate the database from 0!
103104
$dbName = $this->dbalConnection->getDatabase();
104105
$this->dbalRootConnection->getSchemaManager()->dropAndCreateDatabase($dbName);
106+
107+
if ($this->dbalRootConnection->getDriver() instanceof AbstractMySQLDriver) {
108+
$this->dbalRootConnection->exec('USE '.$dbName);
109+
}
105110
}
106111
}

0 commit comments

Comments
 (0)