microblog/db_repository/versions/003_migration.py

33 lines
1.0 KiB
Python
Raw Normal View History

2012-12-16 08:31:21 +00:00
from sqlalchemy import *
from migrate import *
from migrate.changeset import schema
pre_meta = MetaData()
post_meta = MetaData()
user = Table('user', post_meta,
Column('id', Integer, primary_key=True, nullable=False),
Column('nickname', String(length=64)),
Column('email', String(length=120)),
Column('role', SmallInteger, default=ColumnDefault(0)),
Column('about_me', String(length=140)),
Column('last_seen', DateTime),
)
def upgrade(migrate_engine):
# Upgrade operations go here. Don't create your own engine; bind
# migrate_engine to your metadata
pre_meta.bind = migrate_engine
post_meta.bind = migrate_engine
post_meta.tables['user'].columns['about_me'].create()
post_meta.tables['user'].columns['last_seen'].create()
def downgrade(migrate_engine):
# Operations to reverse the above upgrade go here.
pre_meta.bind = migrate_engine
post_meta.bind = migrate_engine
post_meta.tables['user'].columns['about_me'].drop()
post_meta.tables['user'].columns['last_seen'].drop()