python-discord / api

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

Alembic project setup #7

Closed jchristgit closed 2 years ago

jchristgit commented 3 years ago

Set up the Alembic project for migrating the database, and create an initial migration to bootstrap the database based on the current API database schema.

SebastiaanZ commented 3 years ago

I'm unassigning myself for now. It should not be a lot of work, but I'm not sure how soon I'll have time.

D0rs4n commented 3 years ago

If it's up for grabs I would love to help. If not.. I'll just leave my suggestion here anyways

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. (That's just a suggestion that I found to be convenient)

SebastiaanZ commented 3 years ago

That's a good approach. In in favour.

From what I remember, the package does sometimes produce table classes instead of models (for non-trivial situations). Still, it should get us 90% of the way there, and we probably convert those tables manually.

The end goal was always to have a solid base migration that we can then use as the basis for future migrations. This means that @jb3 doesn't have to be our human migration manager.

D0rs4n commented 3 years ago

I'm glad! 👍 Shall I open a new issue to keep things consistent?

D0rs4n commented 3 years ago

Here's the issue #16