Show recent forum threads on the front page. Sucks, but.
[zzz-spline-forum.git] / migration / versions / 005_Added_markup_support.py
1 from sqlalchemy import *
2 from migrate import *
3 import migrate.changeset
4
5 from sqlalchemy.ext.declarative import declarative_base
6 TableBase = declarative_base()
7
8 class Post(TableBase):
9 __tablename__ = 'posts'
10 id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
11 raw_content = Column(Unicode(5120), nullable=False, server_default=u'')
12 content = Column(Unicode(5120), nullable=False)
13
14
15 def upgrade(migrate_engine):
16 TableBase.metadata.bind = migrate_engine
17 conn = migrate_engine.connect()
18
19 # Create the column with an empty-string default, copy the old column's
20 # contents to the new one then remove the default
21 Post.__table__.c.raw_content.create(connection=conn)
22 conn.execute(
23 update(Post.__table__,
24 values={ Post.__table__.c.raw_content: Post.__table__.c.content },
25 )
26 )
27 Post.__table__.c.raw_content.alter(server_default=None, connection=conn)
28
29 def downgrade(migrate_engine):
30 TableBase.metadata.bind = migrate_engine
31
32 Post.__table__.c.raw_content.drop()