Fix migration to work with sqlalchemy-migrate trunk, maybe. :V veekun-promotions/2010060502
authorEevee <git@veekun.com>
Thu, 3 Jun 2010 02:25:26 +0000 (19:25 -0700)
committerEevee <git@veekun.com>
Thu, 3 Jun 2010 02:25:26 +0000 (19:25 -0700)
migration/versions/001_Create_basic_forum_tables.py
migration/versions/002_Flesh_out_core_tables.py

index 4949fe1..47b0cc7 100644 (file)
@@ -2,8 +2,7 @@ from sqlalchemy import *
 from migrate import *
 
 from sqlalchemy.ext.declarative import declarative_base
 from migrate import *
 
 from sqlalchemy.ext.declarative import declarative_base
-TableBase = declarative_base(bind=migrate_engine)
-
+TableBase = declarative_base()
 
 class Forum(TableBase):
     __tablename__ = 'forums'
 
 class Forum(TableBase):
     __tablename__ = 'forums'
@@ -24,12 +23,14 @@ class Post(TableBase):
     content = Column(Unicode(5120), nullable=False)
 
 
     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()
 
     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()
     Post.__table__.drop()
     Thread.__table__.drop()
     Forum.__table__.drop()
index 49c495f..1c7b3d8 100644 (file)
@@ -4,7 +4,7 @@ from migrate import *
 import migrate.changeset
 
 from sqlalchemy.ext.declarative import declarative_base
 import migrate.changeset
 
 from sqlalchemy.ext.declarative import declarative_base
-TableBase = declarative_base(bind=migrate_engine)
+TableBase = declarative_base()
 
 
 class User(TableBase):
 
 
 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)
 
 
 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()