Last active
January 17, 2023 11:04
-
-
Save simonthompson99/df0615d25534f8da952792519b16d4ff to your computer and use it in GitHub Desktop.
[Alembic Cheatsheet] Some basic commands for Alembic #python #database #alembic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# initiate alembic in project | |
alembic init alembic | |
##################################### | |
# need to edit alembic/env.py so that gets connection string from settings/local_config python module | |
# add in below around about line 17 | |
# add parent project to sys path | |
import sys, os | |
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | |
# source db uri | |
import <settings/config_module> as my_config | |
config.set_main_option('sqlalchemy.url', my_config.<whatever the connection string object is called>) | |
# get SQLalchemy model declarative base | |
from models import Base | |
target_metadata = Base.metadata | |
##################################### | |
# run below to create the alembic_version table so we can start tracking revisions (version) | |
alembic stamp head | |
# run below when making revisions | |
alembic revision --autogenerate -m "<revision message>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding to this
https://stackoverflow.com/questions/52121596/creating-zero-state-migration-for-existing-db-with-sqlalchemy-alembic-and-fak