sqlmodel icon indicating copy to clipboard operation
sqlmodel copied to clipboard

Alembic integration and documentation

Open Jufik opened this issue 9 months ago • 12 comments

This is an to integrates Alembic within SqlModel (mentioned in https://github.com/tiangolo/sqlmodel/issues/654)

Implementation is pretty straight forward and lays fundation to provide an extendible sqlmodel CLI through sqlmodel entrypoints. (though about Pluggy be felt like an overkill).

Current CLI structure is:

── sqlmodel
    └── migrations
        ├── init
        ├── revision
        ├── show
        ├── upgrade
        └── downgrade

Command are typed wrappers for the original alembic.command functions, exposed through Typer. Usage and Documentation can be found in the advanced section.

More that glad to get any feedback or suggestions for improvements!

Jufik avatar Oct 31 '23 19:10 Jufik

📝 Docs preview for commit 32afa192caba141896eb5c1d8384264043a175fb at: https://50871b3d.sqlmodel.pages.dev

github-actions[bot] avatar Oct 31 '23 19:10 github-actions[bot]

📝 Docs preview for commit 449882ea625d3f6cbcc7d1c74e773db0654250d4 at: https://f87a6f0c.sqlmodel.pages.dev

github-actions[bot] avatar Oct 31 '23 19:10 github-actions[bot]

📝 Docs preview for commit 0083a168ba6267e5f7577f925e67f072b36b51ef at: https://0f49201d.sqlmodel.pages.dev

github-actions[bot] avatar Oct 31 '23 21:10 github-actions[bot]

📝 Docs preview for commit b5944f033a5805f0924cdbc41fbcba5cba9f27b5 at: https://e4e3fa97.sqlmodel.pages.dev

github-actions[bot] avatar Oct 31 '23 21:10 github-actions[bot]

📝 Docs preview for commit cc42afb3b35a51cbc58cf5de277965b208f84e72 at: https://c12e3a89.sqlmodel.pages.dev

github-actions[bot] avatar Oct 31 '23 21:10 github-actions[bot]

📝 Docs preview for commit 1eb82af4eb003dd7f5352aff8dab16d14aa345c9 at: https://ebd5efa7.sqlmodel.pages.dev

github-actions[bot] avatar Oct 31 '23 21:10 github-actions[bot]

Todo:

  • [ ] Test Alembic methods / migrations for both templates.

One missing piece is around testing Alembic it self. Glad to get any guidance on that.

Looking forward:

I am planning support some method called inside templates' env.py.

Main idea is to get the model from the config's alembic:target_metadata, pass it to a sqlmodel that would dynamically load the metadata.

I'd like some community feedback on such an idea.

Jufik avatar Oct 31 '23 21:10 Jufik

Seems like great work with the template and docs to me.

We've used the Alembic CLI for using Alembic with SQLModel, what benefits does this CLI offer? I'm not sure if it's useful to wrap Alembic to own CLI if it just passes on the calls to be done the same way as the upstream Alembic CLI does. But I did not read carefully what happens there, maybe it's helpful.

antont avatar Nov 01 '23 06:11 antont

Hey @antont,

At the moment not that much TBH 😅 Main idea is to provide the CLI fundations, but we could easily expand it further. That moves FastApi/SqlModel one step closer to Django, and that opens few questions:

  • Does this belong here ? Tiangolo seems to have a vision on this, and IDK how much this should be tied to FastAPI.
  • Where is the limit, how simple should it be easy for developpers, with which restrictions ? (mostly: should cross-apps migration dependencies be handled ?)
  • How opinionated should it be ?

Jufik avatar Nov 01 '23 19:11 Jufik

Hey! Will this be merged soon?

AmgadHasan avatar May 04 '24 01:05 AmgadHasan

@tiangolo documentation in the advanced docs on migrations as well as the incorporation of something like this would be incredibly useful

hitchcock-william avatar Jun 11 '24 14:06 hitchcock-william

Hi @tiangolo is there an update on when this can be merged? 🙏 thank you so much for your work! ✨

alessiamarcolini avatar Jul 19 '24 14:07 alessiamarcolini