1 from sqlalchemy
import *
3 import migrate
.changeset
5 from sqlalchemy
.ext
.declarative
import declarative_base
6 TableBase
= declarative_base()
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)
15 def upgrade(migrate_engine
):
16 TableBase
.metadata
.bind
= migrate_engine
17 conn
= migrate_engine
.connect()
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
)
23 update(Post
.__table__
,
24 values
={ Post
.__table__
.c
.raw_content
: Post
.__table__
.c
.content
},
27 Post
.__table__
.c
.raw_content
.alter(server_default
=None, connection
=conn
)
29 def downgrade(migrate_engine
):
30 TableBase
.metadata
.bind
= migrate_engine
32 Post
.__table__
.c
.raw_content
.drop()