-
Notifications
You must be signed in to change notification settings - Fork 192
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
PsqlDosMigrator
: Remove hardcoding of table name in database reset
#5781
PsqlDosMigrator
: Remove hardcoding of table name in database reset
#5781
Conversation
e90fb59
to
5c31ef4
Compare
44217d3
to
28e60df
Compare
@ltalirz this is ready for review |
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.
thank you @sphuber !
just a few final questions
with self.transaction() as session: | ||
|
||
# Close the session otherwise the ``delete_tables`` call will hang as there will be an open connection | ||
# to the PostgreSQL server and it will block the deletion and the command will hang. |
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 understand this measure prevents connections opened by this particular process from interfering, but I guess there could be other connections open to the DB (daemon / REST API / verdi shell / ...)?
Is there a way we could detect this and exit with an error message instead of hanging?
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.
Not sure to be honest. Not sure if sqlalchemy provides an API to get all open connection to a database, even those that are managed by it. I doubt it. We would probably have to go straight to psycopg
and directly execute a postgres command. Anyway, for now, this method is only being called during unit testing, so it is not that likely.
The `PsqlDosMigrator.reset_database` and `PsqlDosBackend._clear` methods both deleted (almost) all database tables. The tables to delete were hard-coded in a list by each method. The `delete_tables` method is added to the `PsqlDosMigrator` class which will delete all tables of the schema which are determined dynamically by reflecting the metadata schema. The `exclude_tables` argument can be used to define table names to exclude. The new method is used by both classes in order to remove the hard-coding of table names.
28e60df
to
ad1250c
Compare
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.
thanks, all good!
Fixes #5769
The
PsqlDosMigrator.reset_database
andPsqlDosBackend._clear
methodsboth deleted (almost) all database tables. The tables to delete were
hard-coded in a list by each method.
The
delete_tables
method is added to thePsqlDosMigrator
class whichwill delete all tables of the schema which are determined dynamically by
reflecting the metadata schema. The
exclude_tables
argument can beused to define table names to exclude.
The new method is used by both classes in order to remove the
hard-coding of table names.