Show recent forum threads on the front page. Sucks, but.
[zzz-spline-forum.git] / migration / versions / 001_Create_basic_forum_tables.py
1 from sqlalchemy import *
2 from migrate import *
3
4 from sqlalchemy.ext.declarative import declarative_base
5 TableBase = declarative_base()
6
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)
11
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)
17
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)
24
25
26 def upgrade(migrate_engine):
27 TableBase.bind = migrate_engine
28 Forum.__table__.create()
29 Thread.__table__.create()
30 Post.__table__.create()
31
32 def downgrade(migrate_engine):
33 TableBase.bind = migrate_engine
34 Post.__table__.drop()
35 Thread.__table__.drop()
36 Forum.__table__.drop()