Skip to content

Instantly share code, notes, and snippets.

@iuridiniz
Created January 7, 2017 21:08
Show Gist options
  • Save iuridiniz/68586ab9009554f6c23fea7db4163818 to your computer and use it in GitHub Desktop.
Save iuridiniz/68586ab9009554f6c23fea7db4163818 to your computer and use it in GitHub Desktop.
from sqlalchemy import create_engine, Column, types
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
Base = declarative_base()
class User(Base):
__tablename__ = "user"
id = Column(types.Integer, primary_key=True)
engine = create_engine('mysql:///test?unix_socket=/tmp/mysql/socket', echo=True)
session = scoped_session(sessionmaker(bind=engine))
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
from alembic.migration import MigrationContext
from alembic.operations import Operations
ctx = MigrationContext.configure(engine)
op = Operations(ctx)
with op.batch_alter_table("user") as batch_op:
batch_op.add_column(Column('foo', types.Integer))
batch_op.add_column(Column('bar', types.Integer))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment