Skip to content

Instantly share code, notes, and snippets.

View ibrahim12's full-sized avatar

Ibrahim Rashid ibrahim12

View GitHub Profile
@ibrahim12
ibrahim12 / migrate.py
Created November 18, 2020 15:44 — forked from jmuhlich/migrate.py
Alembic migration to rename primary and foreign key constraints along with a table rename
from alembic import op
from alembic.operations.ops import CreatePrimaryKeyOp, CreateForeignKeyOp
import sqlalchemy as sa
def upgrade():
conn = op.get_bind()
ctx = op.get_context()
existing_metadata = sa.schema.MetaData()
target_metadata = ctx.opts['target_metadata']