johndpjr / AgTern

20 stars 5 forks source link

Migrate models and schemas to SQLModels #136

Open JeremyEastham opened 1 year ago

JeremyEastham commented 1 year ago

SQLModel is a library written by the creator of FastAPI that streamlines the process of working with SQLAlchemy models and Pydantic models. Currently our code contains both an internship model (SQLAlchemy model) and an internship schema (Pydantic model). It also contains functions to convert between the two, which have been the source of bugs (year and period issues).

SQLModel adds a class called SQLModel that is both a SQLAlchemy model and a Pydantic model. This eliminates the need for duplicate models/schemas and functions to convert between the two. This will become especially important when we add more database tables for users, tags, companies, etc.

Migration should be relatively straightforward. The most difficult part will be removing the conversion functions and seeing what breaks. Hopefully, we should be able to just ignore conversion and continue.

johndpjr commented 9 months ago

Context

@Oshruti see above for context and below for some actionable steps. LMK if you need help / more detail.

TODO

Notes

This may not be possible to complete this sprint, but do your best!

johndpjr commented 9 months ago

Due to some versioning issues seen below, it seems that implementing this right now is not best. We were already planning on upgrading Pydantic and SQLAlchemy. I'll reopen this when SQLModel gets updated (which I heard on the internet that an update was planned). @Oshruti I'll find another issue for you to work this week

# sqlmodel/pyproject.toml
[tool.poetry.dependencies]
python = "^3.7"
SQLAlchemy = ">=1.4.17,<=1.4.41"
pydantic = "^1.8.2"
sqlalchemy2-stubs = {version = "*", allow-prereleases = true}
JeremyEastham commented 8 months ago

SQLModel has gained support for our currently outdated versions of Pydantic and SQLAlchemy (See roadmap). It should be discussed whether we should migrate to SQLModel before we migrate Pydantic and SQLAlchemy. The roadmap has no timeline, so we should evaluate which dependency update would add the most value to our project.