Skip to content
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

SQLite and ResetDatabase trait: deletion of SQL database file fails #783

Open
Louisonix opened this issue Jan 8, 2025 · 7 comments
Open
Labels
bug Something isn't working

Comments

@Louisonix
Copy link

I'm using the ResetDatabase with Doctrine/SQLite backend.

Because ResetDatabase did not seem to do anything, I found this code to be executed in BaseOrmResetter while debugging:

if (DoctrineOrmVersionGuesser::isOrmV3() && $dbPath && $fs->exists($dbPath)) {
    (new Filesystem())->remove($dbPath);
}

Remove is never called, because DoctrineOrmVersionGuesser::isOrmV3() returns false.

Code for isOrmV3:

public static function isOrmV3(): bool
{
        return \class_exists(FieldMapping::class);
}

What can I do, to make it work? Is it some kind of bug or is it an configuration error?

@nikophil
Copy link
Member

nikophil commented Jan 8, 2025

Hi @Louisonix

are you trying to reset with schema or migrations ?

@Louisonix
Copy link
Author

Resetting via default mechanism, without any further configuration, so I guess via schema, because that's the default.

@nikophil
Copy link
Member

nikophil commented Jan 8, 2025

What is the problem you're facing?
The drop schema step with sqlite is usually enough. The line you're talking about have been added to fix a problem with migrations

@Louisonix
Copy link
Author

Louisonix commented Jan 8, 2025

What is the problem you're facing?

The SQL Database is neiter truncated nor deleted and recreated. No database reset is done. (new Filesystem())->remove($dbPath); is never called.

The line you're talking about have been added to fix a problem with migrations

Then maybe something like:

if ((DoctrineOrmVersionGuesser::isOrmV3() || $this->isUsingSchemaReset()) && $dbPath && $fs->exists($dbPath)) {
    (new Filesystem())->remove($dbPath);
}

would relax the condition a bit, so that (new Filesystem())->remove($dbPath); is called like it should.

@nikophil
Copy link
Member

nikophil commented Jan 8, 2025

The SQL Database is neiter truncated nor deleted and recreated. No database reset is done. (new Filesystem())->remove($dbPath); is never called.

the line (new Filesystem())->remove($dbPath); should not be needed when using "schema" reset strategy. It is only useful for the migration. And it was buggy with orm 2, hence the condition.

Isn't the doctrine:schema:drop I pointed earlier enough? Can you test that this code is called? By the way, do you use dama doctrine test bundle?

@Louisonix
Copy link
Author

Louisonix commented Jan 8, 2025

Isn't the doctrine:schema:drop I pointed earlier enough? Can you test this code is called? By the way, do you use dama doctrine test bundle?

Don't know if I understand you correctly. No, that doesn't work, because resetBeforeEachTest quickly returns without action for the first test - probably it's expecting that resetBeforeFirstTest already did the required reset/work.

No, not using dama bundle.

@nikophil
Copy link
Member

nikophil commented Jan 8, 2025

resetBeforeEachTest quickly returns without action for the first test

yeah ok I see the problem now, indeed, this condition might be problematic. It was mainly there for performance, but this does not work with sqlite + orm v2

I'll have to remove it or see what was the problem with doctrine/orm v2

@nikophil nikophil added the bug Something isn't working label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants