sqlmodel icon indicating copy to clipboard operation
sqlmodel copied to clipboard

📝 Add migrations section

Open ezeparziale opened this issue 2 years ago • 14 comments

I added the migrations section to use SQLModel with alembic.

  • [X] Initial example
  • [X] Step by step
  • [X] Example codes

ezeparziale avatar Dec 15 '22 01:12 ezeparziale

📝 Docs preview for commit eb3ca5e95edd4d98392b1130afeece8b4dedaa09 at: https://639a800274ad247dd834e997--sqlmodel.netlify.app

github-actions[bot] avatar Dec 15 '22 02:12 github-actions[bot]

📝 Docs preview for commit 3cf251f15043dd168e75caa878343a4d867d9059 at: https://639a88d88095c57f0274e6fd--sqlmodel.netlify.app

github-actions[bot] avatar Dec 15 '22 02:12 github-actions[bot]

📝 Docs preview for commit feea75f42fa29599179f7d717fe1ef121afd88fa at: https://639a8a3c2fbcf011a10ebd78--sqlmodel.netlify.app

github-actions[bot] avatar Dec 15 '22 02:12 github-actions[bot]

📝 Docs preview for commit 51d83a666c9e48b45b0d105b90865fdd2b1eca6f at: https://639cdd9a18290c00b4ff5209--sqlmodel.netlify.app

github-actions[bot] avatar Dec 16 '22 21:12 github-actions[bot]

📝 Docs preview for commit 3437837fbae77e03ef39c5bbf7f30042cc07da54 at: https://639e7f62ce461c1a81789517--sqlmodel.netlify.app

github-actions[bot] avatar Dec 18 '22 02:12 github-actions[bot]

Hello, is this the recommended approach now? Alembic is a little intimidating to me, so I'd prefer to be ensured that Alembic is the migration tool of choice, and to have a tutorial from SQLModel. The previews are a little scuffed with the code blocks ^^

(@tiangolo)

locomoco28 avatar Apr 20 '23 11:04 locomoco28

Hey, it would be nice to have this in the docs. I am trying to get this to work on my project, and there is barely any documentation on how to use Alembic with SQLModel. I've been trying to read it from the CI, but the code examples are omitted.

@locomoco28 Do you know of any other tool to manage migrations? I could not find an alternative, and Alembic seems to be well integrated with sqlalchemy

I found only this: https://www.youtube.com/watch?v=gekC1ESLxPs

guysoft avatar Apr 24 '23 18:04 guysoft

I unfortunately do not have any experience with any other migration tooling as I'm coming from the NodeJS world and wanted to use SQLModel for pretty much my first Python project at work.

Thank you for the resource, I'll look into it in the coming days as we're prioritizing a first running beta for now only :)

locomoco28 avatar Apr 24 '23 18:04 locomoco28

I unfortunately do not have any experience with any other migration tooling as I'm coming from the NodeJS world and wanted to use SQLModel for pretty much my first Python project at work.

Thank you for the resource, I'll look into it in the coming days as we're prioritizing a first running beta for now only :)

Hello! see my example in https://github.com/ezeparziale/fastapi-sqlmodel The secret is config the env.py from alembic, then is only run alembic revision --autogenerate - m "my_message", and finally alembic upgrade head

ezeparziale avatar Apr 24 '23 21:04 ezeparziale

Hey, thank you both for the resources. It really was easy to set up. I'm using asyncpg (with create_async_engine from sqlalchemy) so my connection uri is postgresql+asyncpg:// which required me to run initialize Alembic using the -t async flag according to this cookbook I found: https://alembic.sqlalchemy.org/en/latest/cookbook.html#using-asyncio-with-alembic

Appreciate your help!

locomoco28 avatar Apr 26 '23 12:04 locomoco28

alembic seems like not work well with sqllite, because that sqllite does not support alter method.

sparklog avatar May 10 '24 13:05 sparklog

alembic seems like not work well with sqllite, because that sqllite does not support alter method.

https://sqlite.org/lang_altertable.html it does?

Diegovsky avatar May 22 '24 21:05 Diegovsky

alembic seems like not work well with sqllite, because that sqllite does not support alter method.

https://alembic.sqlalchemy.org/en/latest/batch.html

ezeparziale avatar May 22 '24 21:05 ezeparziale