4949fe1ef30e974dffdf8c8664a1eda14f410135
[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(bind=migrate_engine)
6
7
8 class Forum(TableBase):
9 __tablename__ = 'forums'
10 id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
11 name = Column(Unicode(133), nullable=False)
12
13 class Thread(TableBase):
14 __tablename__ = 'threads'
15 id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
16 forum_id = Column(Integer, ForeignKey('forums.id'), nullable=False)
17 subject = Column(Unicode(133), nullable=False)
18
19 class Post(TableBase):
20 __tablename__ = 'posts'
21 id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
22 thread_id = Column(Integer, ForeignKey('threads.id'), nullable=False)
23 posted_time = Column(DateTime, nullable=False)
24 content = Column(Unicode(5120), nullable=False)
25
26
27 def upgrade():
28 Forum.__table__.create()
29 Thread.__table__.create()
30 Post.__table__.create()
31
32 def downgrade():
33 Post.__table__.drop()
34 Thread.__table__.drop()
35 Forum.__table__.drop()