-
Notifications
You must be signed in to change notification settings - Fork 3
SQLAlchemy 1.6 to 2.0 run.py #35
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
Conversation
|
codegen-bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
| files_modified = 0 | ||
| functions_modified = 0 | ||
|
|
||
| print("\nStarting SQLAlchemy 1.6 to 2.0 migration...") |
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.
maybe this type of logging can happen as part of the function wrapper in the CLI.
| # Step 3: Convert Column Definitions to Type Annotations | ||
| for cls in file.classes: | ||
| for attr in cls.attributes: | ||
| if "Column(" in attr.source: |
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.
might want to make sure Column( is the beginning of the assignment
| if "Column(" in attr.source: | ||
| original_attr = attr.source | ||
| new_attr = original_attr.replace("Column", "mapped_column") | ||
| type_hint = "Mapped" + original_attr.split("= Column")[1] |
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'm confused by this here.
a = Column(Integer) should become
a: Mapped[int] = mapped_column()
I'm actually not sure what this new type hint would be based on this logic..
a: Mapped[(Integer)] ?
| chain = chain.parent | ||
|
|
||
| original_code = chain.source | ||
| new_query = chain.source.replace("query(", "select(") |
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.
sqlalchemy 2.0 conventions are to use from sqlalchemy import select for everything right?
Wasn't 1.6 syntax more like
Model.query.filter()
session.query(Model)
and both of these should change to
session.scalars(select(Model).where(...))
or session.scalar(select(Modle).where(...))
and in cases where you're not querying the whole ORM object it would have to be
session.execute(select(Model.a, Model.b))
i believe filter_by is still valid too on the new select
No description provided.