python-discord / api

A FastAPI-based service that allows our services to communicatie with our database.
MIT License
10 stars 1 forks source link

Migrate models based on the current Database Schema to SQLAlchemy #16

Closed D0rs4n closed 2 years ago

D0rs4n commented 3 years ago

After some research I found a library SQLAcodegen that works just like reflecting the current database in SQLAlchemy, except it actually generates the models. (As an additional bonus, it produces a PEP 8 compliant code). This way the API doesn't have to reflect the database every time the it starts up. Naturally, it would still require a review to make sure everything's generated properly, but it would make a whole lot easier to setup an alembic project and perform the migrations. (as discussed in #7 ) I would be glad to help with that!

Shivansh-007 commented 3 years ago

Hey @D0rs4n,

What's the progress on this issue, #11 has been waiting for this to be completed?

Thanks,

D0rs4n commented 3 years ago

Hey @D0rs4n,

What's the progress on this issue, #11 has been waiting for this to be completed?

Thanks,

Hey! I'm waiting for an official approval!

doublevcodes commented 3 years ago

If we are going FastAPI, there's also SQLModel to consider, just something to think about

Kronifer commented 3 years ago

@doublevcodes SQLModel is in v0.0.4 with unfinished docs, I'd say you should hold off on it until the docs are finished

D0rs4n commented 3 years ago

If we are going FastAPI, there's also SQLModel to consider, just something to think about

I believe SQLAlchemy is the one that is specified in the pyproject file. But that issue meant to solve something different. As of now, the database models are in Django. However, if we were to use SQLAlchemy (or SQLModel if you will) we'll need to migrate those models to SQLAlchemy. SQLAcodegen, grabs the current Database Schema and generates SQLAlchemy models accordingly.

SebastiaanZ commented 2 years ago

Sounds solid. We'll have to review each model, but it's probably going to get us close to what we want. I think it typically struggles with things like Many-to-Many relationships, as I believe SQLAlchemy wants you to explicitly define your through model structure where Django will auto-create one if you don't specify one.