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

fix: add missing drop schema when dropping database #6576

Open
wants to merge 2 commits into
base: 4.2.x
Choose a base branch
from

Conversation

nikophil
Copy link
Contributor

Q A
Type bug
Fixed issues doctrine/orm#11701

Summary

fixes doctrine/orm#11701 which was actually a dbal issue.

When we'll be OK with the implementation, I'll provide another PR to fix this in dbal 3

Comment on lines 70 to 74
if ($namespace === 'public') {
continue;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what to do with the "main" public schema, I don't know if this is specific to PG or not.

In PG, this schema is automatically created when the db is created, so I don't think we should drop it with doctrine:schema:drop

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Schemas can have different permissions in newer PostgreSQL versions and removing the defult public would also remove those with it, as it would with the custom schemas. I guess I'd expect it to be removed too when I want to drop schemas. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I've removed the exception for the public schema

Copy link
Contributor Author

@nikophil nikophil Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I have removed the exception for public schema, I got an error in PostgreSQLSchemaManagerTest::testDropWithAutoincrement():

Doctrine\DBAL\Driver\PgSQL\Exception: cannot drop schema public because other objects depend on it

in PostgreSQLSchemaManagerTest.php:364

And given this comment, I think we will have problems dropping schemas which contains views, and schema "that need to be quoted".

I'm wondering if we can mitigate these problems:

  • schema which contains view: shouldn't we drop views as well in DropSchemaObjectsSQLBuilder (because we don't refer to views in \Doctrine\DBAL\Schema\Schema, this seems a little bit complicated, but we can pass a list of the views to DropSchemaObjectsSQLBuilder)
  • schemas that need to be quoted: in AbstractAsset::getQuotedName(), maybe we can also check if the asset's name starts with an integer? Or if this rule is dependent of the current platform, we could add a method for this in AbstractPlatform?

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @SenseException @greg0ire , any chance to have some insights about this please? thanks! 🙏 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like in order to correctly drop the schemas containing views, we need to implement introspection of the views in the schema.

The following is not by design, it was just never implemented.

* 2. The schema returned by {@see AbstractSchemaManager::introspectSchema()} doesn't contain views, so
* {@see AbstractSchemaManager::dropSchemaObjects()} cannot drop the tables that have dependent views
* (@see testListTablesExcludesViews()).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* 1. The DBAL currently doesn't properly drop tables in the namespaces that need to be quoted
* (@see testListTableDetailsWhenCurrentSchemaNameQuoted()).

I don't remember what exactly the problem is. Quoting names that start with a digit is a workaround. I don't think it's a strict requirement if your code will be unable to drop such schemas as long as it doesn't introduce new problems. The issues with quoted names need to be fixed separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I was planning to fix both problems in separate PRs, thanks for your hints!

Copy link
Contributor Author

@nikophil nikophil Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morozov I wanted this PR to be a fix, but implementing introspection of the views in the schema feels like a total new feature... WDYT? (For now I've made it here, but I can move it in another PR)

@nikophil nikophil force-pushed the fix/add-missing-drop-schema branch from 841f800 to 1944fff Compare October 27, 2024 16:36
Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that codecov found some uncovered code paths that need to be addressed in separate tests.

@nikophil nikophil force-pushed the fix/add-missing-drop-schema branch 3 times, most recently from bc07845 to ad2a79f Compare October 30, 2024 07:39
@nikophil
Copy link
Contributor Author

nikophil commented Oct 30, 2024

Hi @SenseException, thanks for your review

It seems that codecov found some uncovered code paths that need to be addressed in separate tests.

super weird, the places where codcov has added annotations are covered by the new test 🤔

If I add dumps in the code, when running this command, I can see it is covered

vendor/bin/phpunit --filter testDropWithSchema -c pgsql.phpunit.xml

@greg0ire
Copy link
Member

greg0ire commented Oct 30, 2024

I believe this is caused by codecov/codecov-action#1580
Right now, we get coverage data, but only based on appveyor and not Github 😢

I'm assuming that @SenseException was refering to a passing build, because the codecov upload job does not even run when one of the github job fails like it's the case right now.

@nikophil nikophil force-pushed the fix/add-missing-drop-schema branch from 0a07800 to 154bb61 Compare December 18, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

doctrine:schema:drop does not remove custom schema in PostgreSQL
4 participants