New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: skip resetDatabase when migrations are up-to-date #552
base: 1.x
Are you sure you want to change the base?
Conversation
This statement is not true when using dama when we encounter a Afterwards, if using dama, we never reset the schema, thanks to this condition: Nonetheless, I do think your PR improves the perfs, but it also breaks the promise of the
I think this is also problematic: dama is enabled from |
Hi @nikophil,
I'm sorry for my ambiguous language. I was trying to say it's reset once if the suite encounters a TestCase with set DatabaseTrait. I made the And I truncate all registered tables in case there are any leftover entries. In my project, this takes about 0.8s now. Thinking about introducing a flag to opt-in skipping the truncation part in a follow-up PR.
Disabling the truncate results in performances around 0.08s. |
Hey @haase-fabian this is just an idea, but do you think we could somehow leverage the proposal here? and manage what you want to achieve is userland based on an event system? |
Yes, I would definitely appreciate extensibility of any kind of bundle. However, I also think, that bundles should provide reasonable default behavior to be as close to zero-configuration as possible. In regard to an event based system: A rough idea:
The interface gets passed a context variable: interface DatabaseResetterInterface
{
public function resetDatabase(array $context): void;
public function resetSchema(array $context): void;
} Then the stack itself could look similar to this: stack:
- DamaDatabaseResetter::class //adds ["isDAMADoctrineTestBundleEnabled" => true|false] to $context
- KernelProvider::class // adds ["kernel" => $kernel, ...$configuration], maybe also ["application" => $app]
- ChainResetter::class // delegates to both ORMDatabaseResetter and ODMDatabaseResetter if available
-
- MigrationDatabaseResetter::class
- ORMDatabaseResetter::class // holds actual reset logic
- ODMDatabaseResetter::class // holds actual reset logic And in user land, one can easily override specific behavior: #[When(env: 'test')]
#[AsDecorator(ORMDatabaseResetter::class)]
class ViewResetter implements DatabaseResetterInterface
{
public function __construct(#[AutowireDecorated] private object $inner, private ManagerRegistry $registry, ...)
{
}
public function resetDatabase(array $context): void {
if($this->shouldReset()){
//install postgres extensions
$this->inner->resetDatabase($context);
//add missing views
}
}
...
} |
I use the DamaDoctrineTestBundle in combination with
database_resetter.orm.reset_mode: migrate
.Everytime the test suite is run, when there is a TestCase using the
ResetDatabase
trait, the database is reset.This change skips the step when there are no new migrations and no unregistered migrations in the database.
This eliminates about 10s of initialization time to 0s for every test suit run in my case.
This assumes, that when DamaDoctrineTestBundle is installed, it is also used and correctly configured.
I use ddev for my projects, so I haven't locally tested the changes as I don't have php locally installed.