+ user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
+
+
+# Permissions stuff
+class Role(TableBase):
+ __tablename__ = 'roles'
+ id = Column(Integer, primary_key=True, nullable=False)
+ name = Column(Unicode(64), nullable=False)
+ icon = Column(Unicode(64), nullable=False)
+
+class UserRole(TableBase):
+ __tablename__ = 'user_roles'
+ user_id = Column(Integer, ForeignKey('users.id'), primary_key=True, nullable=False, autoincrement=False)
+ role_id = Column(Integer, ForeignKey('roles.id'), primary_key=True, nullable=False, autoincrement=False)
+
+class RolePermission(TableBase):
+ __tablename__ = 'role_permissions'
+ id = Column(Integer, nullable=False, primary_key=True)
+ role_id = Column(Integer, ForeignKey('roles.id'), nullable=True)
+ permission = Column(Unicode(64), nullable=False)
+
+
+### Relations
+OpenID.user = relation(User, lazy=False, backref='openids')
+
+Role.role_permissions = relation(RolePermission, backref='role')
+
+User.roles = relation(Role, secondary=UserRole.__table__, backref='users')
+User.role_permissions = relation(RolePermission,
+ primaryjoin=User.id==UserRole.user_id,
+ secondary=UserRole.__table__,
+ secondaryjoin=UserRole.role_id==RolePermission.role_id,
+ foreign_keys=[UserRole.user_id, RolePermission.role_id],
+)
+User.permissions = association_proxy('role_permissions', 'permission')
+
+UserRole.user = relation(User)
+UserRole.role = relation(Role)