Refactor: Change the DeclarativeBase sqlalchemy style#748
Refactor: Change the DeclarativeBase sqlalchemy style#748aldbr merged 8 commits intoDIRACGrid:mainfrom
Conversation
|
All the steps under https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html#migrating-an-existing-mapping should be followed before closing #612 substituting |
ryuwd
left a comment
There was a problem hiding this comment.
Thanks for working on this! Next steps:
Columntomapped_column(see diff comment example injob_logging/schema.py)- Add
Mapped[...]annotations for all schema files - Remove
cast(__table__, Table)everywhere
7c3dfb0 to
c258093
Compare
Documentation build overview
Show files changed (2 files in total): 📝 2 modified | ➕ 0 added | ➖ 0 deleted
|
ryuwd
left a comment
There was a problem hiding this comment.
This is looking great! I only have small questions remaining
|
|
||
| Column: partial[RawColumn] = partial(RawColumn, nullable=False) | ||
| NullColumn: partial[RawColumn] = partial(RawColumn, nullable=True) | ||
| DateNowColumn = partial(Column, type_=DateTime(timezone=True), server_default=utcnow()) |
There was a problem hiding this comment.
I kept them for compatibility reasons, in case other extensions or modules use them. Once it's confirmed that no other code uses them, they can be removed.
There was a problem hiding this comment.
These helpers aren’t used by diracx itself, but I can’t tell whether external or private extensions rely on them. Should I remove them anyway?
There was a problem hiding this comment.
Yes, please remove them. Extensions should update to be consistent with us.
There was a problem hiding this comment.
Theoretically we should avoid to remove them in one go because there are explicitly part of the public API that extensions can use (see https://github.com/DIRACGrid/diracx/pull/748/changes#diff-f2cfd457649455e1dbe7583fcd08cbd9524ed972d423b420d10a526b5083dd7eL6-L8). Extensions already relying on it could then be broken.
It's a breaking change, so ideally, it should be first deprecated and then removed in a major release.
In practice, there are not a lot of extensions in production (only LHCb? May be CTAO?).
As a good practice, you can first add a deprecation warning if one tries to use one of these types, open an issue to explain that you want to remove them. Then we can briefly discuss about that during a Dops meeting, just to make sure no one is using them. And then make another PR based on the issue you opened to remove them.
There was a problem hiding this comment.
(The process is heavy, and this is why we should be very careful in what we want to make public through the __all__ keywords)
87d433c to
09ba1cc
Compare
88dfb6e to
559a912
Compare
ryuwd
left a comment
There was a problem hiding this comment.
Thank you for the hard work! I'm happy with how you've migrated the tables, there are just a couple more old utility functions we should try to get rid of if possible (see comments)
A TODO for the future - we should keep track with tests and test fixtures how these schema definitions change the DB schema expected by SQLAlchemy
559a912 to
8868d09
Compare
|
I checked the schema changes using a script that extracts the DDL from the SQLAlchemy metadata. |
8868d09 to
61fe079
Compare
|
LGTM ! |
aldbr
left a comment
There was a problem hiding this comment.
I just have one last minor comment. The issue was initially opened for that specific comment: #608 (comment)
Basically to change Any in search and summary I guess:
Do you think we can have something better now?
|
Very last comment, sorry 😅 |
61fe079 to
69868b4
Compare
closed: #612
Changes:
Questions:
There is other new styles in SQLAlchemy, for example the declarative use of Column is replaced by mapped_column.
Should this be applied as well?
In the Bookkeeping schema, this has been done, but the other changes haven’t been applied. Is there a reason for that?