-
Notifications
You must be signed in to change notification settings - Fork 66
Modify schema update to now simply delete the whole db #197
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Knp\FriendlyContexts\Context; | ||
|
||
use Behat\Gherkin\Node\TableNode; | ||
use Doctrine\Common\DataFixtures\Purger\ORMPurger; | ||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\Tools\SchemaTool; | ||
use Symfony\Component\PropertyAccess\PropertyAccess; | ||
|
@@ -189,14 +190,12 @@ public function beforeScenario($event) | |
$this->storeTags($event); | ||
|
||
if ($this->hasTags([ 'reset-schema', '~not-reset-schema' ])) { | ||
foreach ($this->getEntityManagers() as $entityManager) { | ||
$metadata = $this->getMetadata($entityManager); | ||
$purger = new ORMPurger(); | ||
$purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE); | ||
|
||
if (!empty($metadata)) { | ||
$tool = new SchemaTool($entityManager); | ||
$tool->dropSchema($metadata); | ||
$tool->createSchema($metadata); | ||
} | ||
foreach ($this->getEntityManagers() as $entityManager) { | ||
$purger->setEntityManager($entityManager); | ||
$purger->purge(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This purger requires to build schema manually before running tests. To prevent this, you can reset schema once, maybe something like: /**
* @var bool
*/
private $databaseReady = false;
// ...
if (!$this->databaseReady) {
$metadata = $entityManager->getMetadataFactory()->getAllMetadata();
$tool = new SchemaTool($this->entityManager);
$tool->dropSchema($metadata);
$tool->createSchema($metadata);
$this->databaseReady = true;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand it's a bcbreak. But IMO the good thing to do is to build schema in a different task than purging the database. It's possible the database is already good when you run your tests on your computer. In this case rebuilding the database is not desired. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note also that your change is a bc break too as it suggest the database is build only once, and if the test needs a real schema reset the second time, it will not be executed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK so in that case, please remove useless |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR, we could keep it like that. But it could be interesting to add a new PR to enable
PURGE_MODE_TRUNCATE
depending on database system, it's more performant :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed performance issue using truncate with mysql. I guess it depends on the schema ! But well, it should be at least configurable. You're right.