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

init

cd yourproject
alembic init alembic

아래와 같이 파일과 폴더가 생성되는 것을 확인할 수 있음.

alembic
├── README
├── env.py
├── script.py.mako
└── versions

show available templates

아래 명령을 통해 생성 가능한 템플릿들을 확인할 수 있다.

alembic list_templates
Available templates:

multidb - Rudimentary multi-database configuration.
pylons - Configuration that reads from a Pylons project environment.
generic - Generic single-database configuration.

Templates are used via the 'init' command, e.g.:

  alembic init --template generic ./scripts

edit alembic.ini

sqlalchemy.url = driver://user:pass@localhost/dbname

create a migration script

alembic revision 명령을 사용하여 마이그레이션 스크립트 생성.

alembic revision -m "create account table"

running the migration

alembic upgrade head

partial revision identifiers

alembic upgrade <REVISION_NUMBER>

show current revision

alembic current

show revision history

alembic history --verbose

downgrading

alembic downgrade base