migration : 데이터베이스에서 다른종류의 데이터베이스로 옮기는 형태를 말합니다. 영어 단어 그대로의 뜻은 '이주'로 데이터베이스 뿐만 아니라 운영체제 간 이동하는 것도 포함하고 있습니다.
데이터베이스에서는 데이터를 수정할 때 큰 위험이 따릅니다. 그래서 update, delete, insert를 했을 때 back up의 필요성을 느껴 특정 시점으로 돌아가능 기능이 있는데 python에서는 alembic을 활용하여 migration합니다.
alembic init <migration dir name>
위의 코드를 실행하면 아래의 파일들이 생성됩니다.
├── alembic.ini
└── "migration dir name"
├── README
├── env.py
├── env.pyc
├── script.py.mako
└── versions
alembic history
revision은
base - revison - revision - head 이며
revision은 시간 순으로 생성됩니다.
가장 초기 상태를 base
가장 최근 상태를 head라고 합니다.
alembic revision -m <revision title>
alembic upgrade head
alembic downgrade <revision>
alembic upgrade <revision>
alembic upgrade +1
alembic upgrade -1
위와 같이 현재 상태에서 정수형으로 이동할 수 있다.