Skip to content

Instantly share code, notes, and snippets.

@sandeepkv93
Created September 12, 2018 18:44
Show Gist options
  • Save sandeepkv93/86184ab3174c21c7af76bac633cc52d6 to your computer and use it in GitHub Desktop.
Save sandeepkv93/86184ab3174c21c7af76bac633cc52d6 to your computer and use it in GitHub Desktop.
Alembic Usage Guide

Initialize

alembic init alembic

Setup

1. Set sqlalchemy.url in alembic.ini
2. Set target_metadata to proper models.py's model in env.py

To import models from previous directory

import os, sys
parent_dir = os.path.abspath(os.getcwd())
sys.path.append(parent_dir)

Generate first revision

alembic revision -m "baseline"

Update the db

alembic upgrade head

Generate autogenerate revision

alembic revision --autogenerate -m "Message"
alembic upgrade head

requirements.txt

alembic==0.8.6
SQLAlchemy==1.0.13
psycopg2-binary==2.7.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment