3 from sqlalchemy
import *
5 import migrate
.changeset
# monkeypatches Column
7 from sqlalchemy
import orm
8 from sqlalchemy
.ext
.declarative
import declarative_base
9 TableBase
= declarative_base(bind
=migrate_engine
)
12 class User(TableBase
):
13 __tablename__
= 'users'
14 id = Column(Integer
, primary_key
=True)
15 name
= Column(Unicode(length
=20), nullable
=False)
16 unique_identifier
= Column(Unicode(length
=32), nullable
=False)
19 session
= orm
.scoped_session(
20 orm
.sessionmaker(autoflush
=True, autocommit
=False, bind
=migrate_engine
))
23 User
.__table__
.c
.unique_identifier
.create()
25 for user
in session
.query(User
):
26 ident
= u
''.join(random
.choice(u
'0123456789abcdef') for _
in range(32))
27 user
.unique_identifier
= ident
33 User
.__table__
.c
.unique_identifier
.drop()