Ensure colorbars can't escape their containers. #352
[zzz-spline-users.git] / migration / versions / 002_Add_User_unique_identifier.py
1 import random
2
3 from sqlalchemy import *
4 from migrate import *
5 import migrate.changeset # monkeypatches Column
6
7 from sqlalchemy import orm
8 from sqlalchemy.ext.declarative import declarative_base
9 TableBase = declarative_base(bind=migrate_engine)
10
11
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)
17
18
19 session = orm.scoped_session(
20 orm.sessionmaker(autoflush=True, autocommit=False, bind=migrate_engine))
21
22 def upgrade():
23 User.__table__.c.unique_identifier.create()
24
25 for user in session.query(User):
26 ident = u''.join(random.choice(u'0123456789abcdef') for _ in range(32))
27 user.unique_identifier = ident
28 session.add(user)
29
30 session.commit()
31
32 def downgrade():
33 User.__table__.c.unique_identifier.drop()