1 from sqlalchemy
import *
4 from sqlalchemy
.ext
.declarative
import declarative_base
5 TableBase
= declarative_base()
7 class Forum(TableBase
):
8 __tablename__
= 'forums'
9 id = Column(Integer
, primary_key
=True, autoincrement
=True, nullable
=False)
10 name
= Column(Unicode(133), nullable
=False)
12 class Thread(TableBase
):
13 __tablename__
= 'threads'
14 id = Column(Integer
, primary_key
=True, autoincrement
=True, nullable
=False)
15 forum_id
= Column(Integer
, ForeignKey('forums.id'), nullable
=False)
16 subject
= Column(Unicode(133), nullable
=False)
18 class Post(TableBase
):
19 __tablename__
= 'posts'
20 id = Column(Integer
, primary_key
=True, autoincrement
=True, nullable
=False)
21 thread_id
= Column(Integer
, ForeignKey('threads.id'), nullable
=False)
22 posted_time
= Column(DateTime
, nullable
=False)
23 content
= Column(Unicode(5120), nullable
=False)
26 def upgrade(migrate_engine
):
27 TableBase
.bind
= migrate_engine
28 Forum
.__table__
.create()
29 Thread
.__table__
.create()
30 Post
.__table__
.create()
32 def downgrade(migrate_engine
):
33 TableBase
.bind
= migrate_engine
35 Thread
.__table__
.drop()
36 Forum
.__table__
.drop()