Ensure colorbars can't escape their containers. #352
[zzz-spline-users.git] / migration / versions / 003_Add_permission_tables.py
1 from sqlalchemy import *
2 from migrate import *
3 import migrate.changeset # monkeypatches Column
4
5 from sqlalchemy import orm
6 from sqlalchemy.ext.declarative import declarative_base
7 TableBase = declarative_base()
8
9
10 class User(TableBase):
11 __tablename__ = 'users'
12 id = Column(Integer, primary_key=True)
13
14
15 class Role(TableBase):
16 __tablename__ = 'roles'
17 id = Column(Integer, primary_key=True, nullable=False)
18 name = Column(Unicode(64), nullable=False)
19 icon = Column(Unicode(64), nullable=False)
20
21 class UserRole(TableBase):
22 __tablename__ = 'user_roles'
23 user_id = Column(Integer, ForeignKey('users.id'), primary_key=True, nullable=False, autoincrement=False)
24 role_id = Column(Integer, ForeignKey('roles.id'), primary_key=True, nullable=False, autoincrement=False)
25
26 class RolePermission(TableBase):
27 __tablename__ = 'role_permissions'
28 id = Column(Integer, nullable=False, primary_key=True)
29 role_id = Column(Integer, ForeignKey('roles.id'), nullable=True)
30 permission = Column(Unicode(64), nullable=False)
31
32
33 def upgrade(migrate_engine):
34 TableBase.metadata.bind = migrate_engine
35 Role.__table__.create()
36 UserRole.__table__.create()
37 RolePermission.__table__.create()
38
39 def downgrade(migrate_engine):
40 TableBase.metadata.bind = migrate_engine
41 RolePermission.__table__.drop()
42 UserRole.__table__.drop()
43 Role.__table__.drop()