-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
misc: Migrate to SQLAlchemy declarative models #954
misc: Migrate to SQLAlchemy declarative models #954
Conversation
from sqlalchemy import BigInteger, DateTime, ForeignKey, String, func | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
if TYPE_CHECKING: |
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.
AAAAHHH I forgot you can do this 😫
|
||
|
||
class Save(RomAsset): | ||
__tablename__ = "saves" | ||
__table_args__ = {"extend_existing": True} | ||
|
||
emulator = Column(String(length=50), nullable=True) | ||
emulator: Mapped[str | None] = mapped_column(String(length=50)) |
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.
don't we have to mark this nullable=True
?
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.
We don't! The typehint takes care of that, as explained in step four, so Mapped[str]
implicitly sets nullable=False
, while Mapped[str | None]
sets nullable=True
.
This change applies the guided migration process recommended by SQLAlchemy [1], up to step 4, to have declarative ORM models that better support Python typing. The change was tested by running `alembic check`, which does not find any schema changes. Errors reported by `mypy` go down to 170, from the original 223 in the current `master` commit. [1] https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html#migrating-an-existing-mapping
66ccd38
to
b99eded
Compare
@adamantike If you happen to be in the discord, give me (arcaneasada) a ping in #open-development. And if not, feel free to join. We do all of our dev planning on there, and if you have more PRs in mind I'd love to hear what you have planned. https://discord.gg/ThzzNYq9 |
This change applies the guided migration process recommended by SQLAlchemy [1], up to step 4, to have declarative ORM models that better support Python typing.
The change was tested by running
alembic check
, which does not find any schema changes.Errors reported by
mypy
go down to 170, from the original 223 in the currentmaster
commit.[1] https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html#migrating-an-existing-mapping