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

Refactor the code dealing with database into BackendManager #3582

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Nov 27, 2019

Fixes #3530 and fixes #3584

The code that acts directly with the database, outside of the ORM, for
example to check the database schema generation and version, or to get
data from the DbSettings table has been refactored. The ORM requires
the database environment to be loaded, but to do that the database
schema needs to be verified which also requires accessing the database.
This functionality was implemented mostly in free-standing functions and
separately for both backends. This is reorganized into a BackendManager
abstract class and implemented for Django and SqlAlchemy. This
centralizes the functionality required to verify database schema and
perform the migrations thereof.

@sphuber
Copy link
Contributor Author

sphuber commented Nov 27, 2019

This is the refactoring work that I originally implemented in combination with the reset of the database schema generation. However, having been convinced to postpone this, I still think the refactoring of the backend utilities should go in now. All the groundwork for the schema reset for v2.0.0 will then already be laid and all 1.0.* versions will have the correct messaging.

@ltalirz
Copy link
Member

ltalirz commented Nov 27, 2019

I'll leave this review to @giovannipizzi if that's ok

@sphuber sphuber force-pushed the fix_3530_refactor_backend_manager branch 3 times, most recently from 9b28013 to 1f07d8d Compare November 27, 2019 19:12
The code that acts directly with the database, outside of the ORM, for
example to check the database schema generation and version, or to get
data from the `DbSettings` table has been refactored. The ORM requires
the database environment to be loaded, but to do that the database
schema needs to be verified which also requires accessing the database.
This functionality was implemented mostly in free-standing functions and
separately for both backends. This is reorganized into a `BackendManager`
abstract class and implemented for Django and SqlAlchemy. This
centralizes the functionality required to verify database schema and
perform the migrations thereof.
@sphuber sphuber force-pushed the fix_3530_refactor_backend_manager branch from 1f07d8d to 952a5e9 Compare November 29, 2019 09:49
Copy link
Member

@giovannipizzi giovannipizzi left a comment

Choose a reason for hiding this comment

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

Thanks! I think the refactoring is good - As there are many changes I hope I didn't miss anything bad.

I added a comment, but it's more a question and in case can be addressed in a different issue.

Maybe before merging it would be good to have a small wiki page explaining the concept of schema revisions and how we intend to use it in the future (as a quick note for now, we might convert to an AEP when actually implementing it), and then link it from this PR

closure_table_name,
closure_table_parent_field,
closure_table_child_field):
def get_pg_tc(
Copy link
Member

Choose a reason for hiding this comment

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

Why do we still have transitive-closure code in our codebase?

Copy link
Contributor Author

@sphuber sphuber Dec 1, 2019

Choose a reason for hiding this comment

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

Because this is part of the original database schema and so is installed in the initial migration and then subsequently dropped in one of the following migrations. One of the reasons I want to reset the schema at some point :) so we can get rid of code like this

@sphuber sphuber merged commit cdcfb4f into aiidateam:develop Dec 1, 2019
@sphuber sphuber deleted the fix_3530_refactor_backend_manager branch December 1, 2019 21:55
chrisjsewell added a commit to chrisjsewell/aiida_core that referenced this pull request Dec 14, 2021
In aiidateam#3582, SQLA migrations were broken,
by starting a top-level transaction,
instead of letting alembic open per-migration transaction.
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.

Unable to migrate database Refactor and abstract a database backend manager class
3 participants