This repository attempts to replicate best practices in FastAPI from this repository.
- Navigate to your project directory, and generate alembic files by running the ff. command on your terminal:
alembic init alembic
- Navigate to
alembic.ini
on the project's root folder, and changesqlalchemy.url
to your database url. - Update alembic/env.py
- Import the
Base
variable fromsrc/database/database.py
- Change the
target_metadata
variable toBase.metadata
- Import the
- Update alembic/script.py.mako
- Add
import sqlmodel
under the imports section
- Add
- Alembic Commands
alembic revision --autogenerate -m <message>
This will generate a Python script to handle migrations.alembic upgrade head
This will run the upgrade function and apply the changes inmodels.py
into the database.alembic downgrade -1
This will downgrade the database to the previous version