From: Eevee Date: Thu, 3 Jun 2010 02:25:26 +0000 (-0700) Subject: Fix migration to work with sqlalchemy-migrate trunk, maybe. :V X-Git-Tag: veekun-promotions/2010060502^0 X-Git-Url: http://git.veekun.com/zzz-spline-forum.git/commitdiff_plain/032e2a68113050308307f3a36832ee47290f7dbe Fix migration to work with sqlalchemy-migrate trunk, maybe. :V --- diff --git a/migration/versions/001_Create_basic_forum_tables.py b/migration/versions/001_Create_basic_forum_tables.py index 4949fe1..47b0cc7 100644 --- a/migration/versions/001_Create_basic_forum_tables.py +++ b/migration/versions/001_Create_basic_forum_tables.py @@ -2,8 +2,7 @@ from sqlalchemy import * from migrate import * from sqlalchemy.ext.declarative import declarative_base -TableBase = declarative_base(bind=migrate_engine) - +TableBase = declarative_base() class Forum(TableBase): __tablename__ = 'forums' @@ -24,12 +23,14 @@ class Post(TableBase): content = Column(Unicode(5120), nullable=False) -def upgrade(): +def upgrade(migrate_engine): + TableBase.bind = migrate_engine Forum.__table__.create() Thread.__table__.create() Post.__table__.create() -def downgrade(): +def downgrade(migrate_engine): + TableBase.bind = migrate_engine Post.__table__.drop() Thread.__table__.drop() Forum.__table__.drop() diff --git a/migration/versions/002_Flesh_out_core_tables.py b/migration/versions/002_Flesh_out_core_tables.py index 49c495f..1c7b3d8 100644 --- a/migration/versions/002_Flesh_out_core_tables.py +++ b/migration/versions/002_Flesh_out_core_tables.py @@ -4,7 +4,7 @@ from migrate import * import migrate.changeset from sqlalchemy.ext.declarative import declarative_base -TableBase = declarative_base(bind=migrate_engine) +TableBase = declarative_base() class User(TableBase): @@ -39,20 +39,24 @@ thread_position_idx = Index('thread_position', Post.thread_id, Post.position, un posted_time_idx = Index('ix_posts_posted_time', Post.posted_time) -objects = [ - Thread.__table__.c.icon, - Thread.__table__.c.post_count, - thread_post_count_idx, - Post.__table__.c.position, - Post.__table__.c.author_user_id, - thread_position_idx, - posted_time_idx, -] +def upgrade(migrate_engine): + TableBase.metadata.bind = migrate_engine -def upgrade(): - for obj in objects: - obj.create() + Thread.__table__.c.icon.create() + Thread.__table__.c.post_count.create() + thread_post_count_idx.create(bind=migrate_engine) + Post.__table__.c.position.create() + Post.__table__.c.author_user_id.create() + thread_position_idx.create(bind=migrate_engine) + posted_time_idx.create(bind=migrate_engine) -def downgrade(): - for obj in reversed(objects): - obj.drop() +def downgrade(migrate_engine): + TableBase.metadata.bind = migrate_engine + + posted_time_idx.drop(bind=migrate_engine) + thread_position_idx.drop(bind=migrate_engine) + Post.__table__.c.author_user_id.drop() + Post.__table__.c.position.drop() + thread_post_count_idx.drop(bind=migrate_engine) + Thread.__table__.c.post_count.drop() + Thread.__table__.c.icon.drop()