Skip to content
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

aerich cannot generate migrations #133

Closed
b-rowan opened this issue Sep 10, 2024 · 7 comments
Closed

aerich cannot generate migrations #133

b-rowan opened this issue Sep 10, 2024 · 7 comments

Comments

@b-rowan
Copy link
Contributor

b-rowan commented Sep 10, 2024

Attempting to generate DB migrations for #132 fails to find any difference. I am starting to wonder if aerich is even worth using, or if there are any better options. Looking at the github page, it is not in a good state, the top issue currently is users wondering if the project is even being maintained anymore.

Would like to start discussion here about other possible options or workarounds for this.

@b-rowan
Copy link
Contributor Author

b-rowan commented Sep 10, 2024

I think there are 2 main options here if we decide to move away from tortoise-ORM due to lack of migration support.

  1. Piccolo - https://piccolo-orm.readthedocs.io/en/latest/piccolo/getting_started/index.html
  2. SQLAlchemy - https://docs.sqlalchemy.org/en/20/index.html

I am more familiar with SQLAlchemy personally, but piccolo also looks good (with the added benefit of built in migrations). My only concern with SQLAlchemy is I am very unfamiliar with the async capabilities of it.

@easybe
Copy link
Collaborator

easybe commented Sep 11, 2024

The following works for me:

git switch master
git clean -f goosebit/db/migrations/models
rm -f db.sqlite3
poetry run aerich upgrade

git switch dev_rauc_support
poetry run aerich migrate --name add_image_format
Success migrate 1_20240911082808_add_image_format.py

cat goosebit/db/migrations/models/1_20240911082808_add_image_format.py
from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE "software" ADD "image_format" SMALLINT NOT NULL  DEFAULT 0 /* SWU: 0\nRAUC: 1 */;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE "software" DROP COLUMN "image_format";"""

aerich seems fine to me. I actually like Tortoise ORM because I like the Django ORM 🤷‍♂️

@tsagadar
Copy link
Collaborator

@easybe was two minutes faster than I was... The following Aerich issue hinted for this approach: tortoise/aerich#270

Annoying - but not sure if other frameworks are that much better. I'd propose to gain some more experience with this first.

@easybe
Copy link
Collaborator

easybe commented Sep 11, 2024

@easybe was two minutes faster than I was... The following Aerich issue hinted for this approach: tortoise/aerich#270

Annoying - but not sure if other frameworks are that much better. I'd propose to gain some more experience with this first.

To me this is completely natural 🤷‍♂️

@b-rowan
Copy link
Contributor Author

b-rowan commented Sep 11, 2024

aerich seems fine to me. I actually like Tortoise ORM because I like the Django ORM 🤷‍♂️

I also really like Tortoise ORM, but the apparent lack of maintenance or fixes on Aerich makes it a bit annoying to do the DB migrations. At least this works, maybe should add a bit to the documentation about it.

@b-rowan b-rowan closed this as completed Sep 11, 2024
@b-rowan
Copy link
Contributor Author

b-rowan commented Sep 25, 2024

Re-opening this to bring discussion to a couple other options I've come across recently. It is still relatively early with this project, so swapping ORM's now is much easier than later.

Option 1: SQLModel
Pros:

  • Written by the creator of FastAPI, so support directly with FastAPI is very good.
  • Similar API to tortoise, with a few small differences.
  • SQLAlchemy under the hood, so could be used with alembic, which is much more stable and supported.
  • FastAPI has a template for using this as part of a stack - https://github.com/fastapi/full-stack-fastapi-template
  • Very good type checking, uses pydantic, and will allow for a lot of flexibility directly in models.
    Cons:
  • No async documentation

Option 2: ormar
Pros:

  • Designed for FastAPI
  • SQLAlchemy under the hood, so could be used with alembic, which is much more stable and supported.
  • Similar API to tortoise, with a few small differences.
  • Very good type checking, uses pydantic, and will allow for a lot of flexibility directly in models.
  • Decent documentation, designed with async in mind.

Overall I think both of these might be better options than tortoiseORM, and I lean towards SQLModel. If we decide we want to look into either of these, I could create a branch illustrating the differences.

@b-rowan b-rowan reopened this Sep 25, 2024
@easybe
Copy link
Collaborator

easybe commented Sep 26, 2024

Overall I think both of these might be better options than tortoiseORM, and I lean towards SQLModel. If we decide we want to look into either of these, I could create a branch illustrating the differences.

I only had a quick glance, but, SQLModel seems like a good option to me. Switching to something that has a wider user base, is based on proven technology, and fits nicely into the FastAPI ecosystems sounds reasonable to me.

@b-rowan b-rowan closed this as completed Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants