def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine change_log = Table( 'change_log', meta, Column('created_at', DATETIME), Column('updated_at', DATETIME), Column('deleted_at', DATETIME), Column('deleted', INTEGER(display_width=11)), Column('key', VARCHAR(length=128)), Column('id', INTEGER(display_width=11), primary_key=True, nullable=False), Column('object_id', INTEGER(display_width=11), nullable=False), Column('type', VARCHAR(length=32), nullable=False), Column('old', TEXT), Column('new', TEXT), ) try: change_log.create() except Exception: LOG.info(repr(change_log)) LOG.exception('Exception while creating table.') raise indexes = [ Index('change_log_object_id_idx', change_log.c.object_id), Index('change_log_type_idx', change_log.c.type) ] for index in indexes: index.create(migrate_engine)
def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine port = Table( 'port', meta, Column('created_at', DATETIME), Column('updated_at', DATETIME), Column('deleted_at', DATETIME), Column('deleted', INTEGER(display_width=11)), Column('key', VARCHAR(length=128)), Column('id', INTEGER(display_width=11), primary_key=True, nullable=False), Column('device_id', VARCHAR(length=32), nullable=False), Column('rack_name', VARCHAR(length=32), nullable=False), Column('vlan_tag', INTEGER(display_width=11), nullable=False), Column('ip', VARCHAR(length=15)), Column('mac', VARCHAR(length=31)), ) try: port.create() except Exception: LOG.info(repr(port)) LOG.exception('Exception while creating table.') raise indexes = [ Index('port_vlan_tag_idx', port.c.vlan_tag), Index('port_rack_name_idx', port.c.rack_name) ] for index in indexes: index.create(migrate_engine)
class Path(Base): ''' Provides the ACL path mapping. ''' __tablename__ = 'acl_path' __table_args__ = dict(mysql_engine='InnoDB') id = Column('id', INTEGER(unsigned=True), primary_key=True) path = Column('path', String(255), nullable=False, unique=True) priority = Column('priority', INTEGER(unsigned=True))
class ArticleCtxMapped(Base, ArticleCtx): ''' Mapping for Article entity ''' __tablename__ = 'article_ctx_demo' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Article = Column('fk_article_id', ForeignKey(ArticleMapped.Id), nullable=False) Content = Column('content', Text) Type = Column('type', INTEGER(unsigned=True))
class EntryMapped(Base, WithSignature, Entry): ''' Provides the ACL access entry mapping. ''' __tablename__ = 'acl_access_entry' __table_args__ = (UniqueConstraint('fk_access_id', 'position', name='uix_acl_access_entry'), dict(mysql_engine='InnoDB')) Position = Column('position', INTEGER(unsigned=True)) Shadowing = Column('shadowing_position', INTEGER(unsigned=True)) Shadowed = Column('shadowed_position', INTEGER(unsigned=True)) Signature = WithSignature.createSignature() # Non REST model attribute -------------------------------------- id = Column('id', INTEGER(unsigned=True), primary_key=True) accessId = Column('fk_access_id', ForeignKey(AccessMapped.Id, ondelete='CASCADE'), nullable=False)
class PersonMapped(Base, Person): ''' Provides the mapping for Person entity. ''' __tablename__ = 'person' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) FirstName = Column('first_name', String(255)) LastName = Column('last_name', String(255)) Address = Column('address', String(255)) EMail = Column('email', String(255)) PhoneNumber = Column('phone_number', String(255), nullable=True, unique=True) @hybrid_property def FullName(self): if self.FirstName is None: return self.LastName if self.LastName is None: return self.FirstName return self.FirstName + ' ' + self.LastName # Expression for hybrid ------------------------------------ FullName.expression = lambda cls: case( [(cls.FirstName == None, cls.LastName)], else_=case([(cls.LastName == None, cls.FirstName)], else_=cls.FirstName + ' ' + cls.LastName))
class ArticleMapped(Base, Article): ''' Provides the mapping for Article. ''' __tablename__ = 'article' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Item = Column('fk_item_id', ForeignKey(ItemMapped.GUId, ondelete='RESTRICT'), nullable=False) Creator = Column('fk_creator_id', ForeignKey(UserMapped.Id, ondelete='RESTRICT'), nullable=False) Author = Column('fk_author_id', ForeignKey(PersonMapped.Id, ondelete='RESTRICT'), nullable=False) Content = Column('content', TEXT, nullable=False) PublishedOn = Column('published_on', DateTime) @hybrid_property def IsPublished(self): return self.PublishedOn is not None # Expression for hybrid ------------------------------------ IsPublished.expression(lambda cls: cls.PublishedOn != None)
class BlogMapped(Base, Blog): ''' Provides the mapping for Blog. ''' __tablename__ = 'livedesk_blog' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Type = Column('fk_blog_type', ForeignKey(BlogTypeMapped.Id), nullable=False) Language = Column('fk_language_id', ForeignKey(LanguageEntity.Id), nullable=False) Creator = Column('fk_creator_id', ForeignKey(UserMapped.Id), nullable=False) Title = Column('title', String(255), nullable=False) Description = Column('description', Text) OutputLink = Column('output_link', Text) EmbedConfig = Column('embed_config', Text) CreatedOn = Column('created_on', DateTime, nullable=False) LiveOn = Column('live_on', DateTime) ClosedOn = Column('closed_on', DateTime) @hybrid_property def IsLive(self): return self.LiveOn is not None and self.ClosedOn is None # Expression for hybrid ------------------------------------ @classmethod @IsLive.expression def _IsLive(cls): return case([((cls.LiveOn != None) & (cls.ClosedOn == None), True)], else_=False)
class CollaboratorMapped(Base, Collaborator): ''' Provides the mapping for Collaborator. ''' __tablename__ = 'collaborator' __table_args__ = (UniqueConstraint('fk_person_id', 'fk_source_id', name='uix_1'), dict(mysql_engine='InnoDB')) Id = Column('id', INTEGER(unsigned=True), primary_key=True) Person = Column('fk_person_id', ForeignKey(PersonMapped.Id, ondelete='CASCADE')) Source = Column('fk_source_id', ForeignKey(SourceMapped.Id, ondelete='RESTRICT'), nullable=False) @hybrid_property def Name(self): if self.Person is None: return self.source.Name return self.person.FullName # Non REST model attributes -------------------------------------- person = relationship(PersonMapped, uselist=False, lazy='joined') source = relationship(SourceMapped, uselist=False, lazy='joined') # Expression for hybrid ------------------------------------ Name.expression(lambda cls: case([(cls.Person == None, SourceMapped.Name)], else_=PersonMapped.FirstName))
class Rbac(Base): ''' Provides the mapping for base Rbac. ''' __tablename__ = 'rbac' __table_args__ = dict(mysql_engine='InnoDB') id = Column('id', INTEGER(unsigned=True), primary_key=True)
class Signature(Base): ''' Provides the ACL type signature mapping. ''' __tablename__ = 'acl_signature' __table_args__ = dict(mysql_engine='InnoDB') id = Column('id', INTEGER(unsigned=True), primary_key=True) name = Column('name', String(255), nullable=False, unique=True)
class UserMapped(Base, User): __tablename__ = 'user' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Name = Column('name', String(20), nullable=False) Type = Column('fk_user_type', ForeignKey(UserTypeMapped.Id, ondelete='RESTRICT'), nullable=False)
class MetaTypeMapped(Base, MetaType): ''' Provides the mapping for MetaType. ''' __tablename__ = 'archive_meta_type' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Type = Column('type', String(50), nullable=False, unique=True)
class Method(Base): ''' Provides the ACL method mapping. ''' __tablename__ = 'acl_method' __table_args__ = dict(mysql_engine='InnoDB') id = Column('id', INTEGER(unsigned=True), primary_key=True) name = Column('name', String(20), nullable=False, unique=True)
class BlogSyncMapped(Base, BlogSync): ''' Provides the mapping for BlogCollaborator definition. ''' __tablename__ = 'livedesk_blog_sync' __table_args__ = (UniqueConstraint('fk_blog_id', 'fk_source_id', name='uix_sync_blog_source'), dict(mysql_engine='InnoDB', mysql_charset='utf8')) Id = Column('id', INTEGER(unsigned=True), primary_key=True) Blog = Column('fk_blog_id', ForeignKey(BlogMapped.Id), nullable=False) Source = Column('fk_source_id', ForeignKey(SourceMapped.Id), nullable=False) CId = Column('id_change', INTEGER(unsigned=True)) LastActivity = Column('last_activity', DateTime) Auto = Column('auto', Boolean, nullable=False)
class BlogTypeMapped(Base, BlogType): ''' Provides the mapping for Blog. ''' __tablename__ = 'livedesk_blog_type' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Name = Column('name', String(255), nullable=False)
class RightTypeMapped(Base, RightType): ''' Provides the mapping for RightType. ''' __tablename__ = 'security_right_type' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Name = Column('name', String(100), nullable=False, unique=True) Description = Column('description', String(255))
class PostTypeMapped(Base, PostType): ''' Provides the mapping for PostType. ''' __tablename__ = 'post_type' __table_args__ = dict(mysql_engine='InnoDB') Key = Column('key', String(100), nullable=False, unique=True) # None REST model attribute -------------------------------------- id = Column('id', INTEGER(unsigned=True), primary_key=True)
class ArticleFileMapped(Base, ArticleFile): ''' Provides the mapping for ArticleFile. ''' __tablename__ = 'article_file' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Article = Column('fk_article_id', ForeignKey(ArticleMapped.Id, ondelete='CASCADE'), nullable=False) MetaData = Column('fk_metadata_id', ForeignKey(MetaDataMapped.Id, ondelete='CASCADE'), nullable=False)
class BlogThemeMapped(Base, BlogTheme): ''' Provides the mapping for BlogTheme. ''' __tablename__ = 'livedesk_blog_theme' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Name = Column('name', String(190), unique=True, nullable=False) URL = Column('url', String(1024), nullable=False)
class VerificationStatusMapped(Base, VerificationStatus): ''' Provides the mapping for PostType. ''' __tablename__ = 'verification_status' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Key = Column('key', String(100), nullable=False, unique=True) # None REST model attribute -------------------------------------- id = Column('id', INTEGER(unsigned=True), primary_key=True)
class ArticleMapped(Base, Article): ''' Mapping for Article entity ''' __tablename__ = 'article_demo' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) CreatedOn = Column('created_on', DateTime, nullable=False) Slug = Column('slug', String(255))
class BlogCollaboratorTypeMapped(Base, BlogCollaboratorType): ''' Provides the mapping for BlogCollaboratorType definition. ''' __tablename__ = 'livedesk_collaborator_type' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Name = Column('name', String(190), nullable=False, unique=True) # Non REST model attribute -------------------------------------- id = Column('id', INTEGER(unsigned=True), primary_key=True)
class FilterMapped(Base, WithPath, WithSignature, Filter): ''' Provides the ACL filter mapping. ''' __tablename__ = 'acl_filter' __table_args__ = dict(mysql_engine='InnoDB') Name = Column('name', String(255), nullable=False, unique=True) Signature = WithSignature.createSignature() # Non REST model attribute -------------------------------------- id = Column('id', INTEGER(unsigned=True), primary_key=True)
class RoleNode(Base): ''' Provides the mapping for roles hierarchy. ''' __tablename__ = 'rbac_role_node' __table_args__ = dict(mysql_engine='InnoDB') id = Column('id', INTEGER(unsigned=True), primary_key=True) role = Column('fk_role_id', ForeignKey(RoleMapped.Id)) left = Column('lft', INTEGER, nullable=False) right = Column('rgt', INTEGER, nullable=False)
class GeneralSettingMapped(Base, GeneralSetting): ''' Provides the mapping for PostType. ''' __tablename__ = 'general_setting' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Key = Column('key', String(100), nullable=False, unique=True) Group = Column('group', String(100)) Value = Column('value', String(100)) # None REST model attribute -------------------------------------- id = Column('id', INTEGER(unsigned=True), primary_key=True)
class BlogCollaboratorGroupMapped(Base, BlogCollaboratorGroup): ''' Provides the mapping for BlogCollaboratorGroup definition. ''' __tablename__ = 'livedesk_collaborator_group' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Blog = Column('fk_blog_id', ForeignKey(BlogMapped.Id, ondelete='CASCADE'), nullable=False) LastAccessOn = Column('last_access_on', DateTime, nullable=False)
class PropertyMapped(Base, WithSignature, Property): ''' Provides the ACL access property mapping. ''' __tablename__ = 'acl_access_property' __table_args__ = (UniqueConstraint('fk_access_id', 'name', name='uix_acl_access_property'), dict(mysql_engine='InnoDB')) Name = Column('name', String(255)) Signature = WithSignature.createSignature() # Non REST model attribute -------------------------------------- id = Column('id', INTEGER(unsigned=True), primary_key=True) accessId = Column('fk_access_id', ForeignKey(AccessMapped.Id, ondelete='CASCADE'), nullable=False)
class PostMapped(Base, Post): ''' Provides the mapping for Post. ''' __tablename__ = 'post' __table_args__ = dict(mysql_engine='InnoDB', mysql_charset='utf8') Id = Column('id', INTEGER(unsigned=True), primary_key=True) Uuid = Column('uuid', String(32)) Type = association_proxy('type', 'Key') Creator = Column('fk_creator_id', ForeignKey(UserMapped.Id, ondelete='RESTRICT'), nullable=False) Author = Column('fk_author_id', ForeignKey(CollaboratorMapped.Id, ondelete='RESTRICT')) Feed = Column('fk_feed_id', ForeignKey(SourceMapped.Id, ondelete='RESTRICT')) Meta = Column('meta', TEXT) ContentPlain = Column('content_plain', TEXT) Content = Column('content', TEXT) CreatedOn = Column('created_on', DateTime, nullable=False) PublishedOn = Column('published_on', DateTime) WasPublished = Column('was_published', Boolean) UpdatedOn = Column('updated_on', DateTime) DeletedOn = Column('deleted_on', DateTime) @hybrid_property def IsModified(self): return self.UpdatedOn is not None @hybrid_property def IsPublished(self): return self.PublishedOn is not None @hybrid_property def AuthorName(self): if self.Author is None: if self.creator is None: return None else: return self.creator.Name return self.author.Name # Non REST model attributes -------------------------------------- typeId = Column('fk_type_id', ForeignKey(PostTypeMapped.id, ondelete='RESTRICT'), nullable=False) type = relationship(PostTypeMapped, uselist=False, lazy='joined') author = relationship(CollaboratorMapped, uselist=False, lazy='joined') creator = relationship(UserMapped, uselist=False, lazy='joined') # Expression for hybrid ------------------------------------ @classmethod @IsModified.expression def _IsModified(cls): return case([(cls.UpdatedOn != None, True)], else_=False) @classmethod @IsPublished.expression def _IsPublished(cls): return case([(cls.PublishedOn != None, True)], else_=False) @classmethod @AuthorName.expression def _AuthorName(cls): return case([(cls.Author == None, UserMapped.Name)], else_=CollaboratorMapped.Name)
class AccessMapped(Base, WithPath, WithMethod, WithSignature, Access): ''' Provides the ACL access mapping. ''' __tablename__ = 'acl_access' __table_args__ = (UniqueConstraint('fk_path_id', 'fk_method_id', name='uix_acl_access'), dict(mysql_engine='InnoDB')) Id = Column('id', INTEGER(unsigned=True), autoincrement=False, primary_key=True) Priority = association_proxy('path', 'priority') Shadowing = Column('fk_shadowing_id', ForeignKey('acl_access.id', ondelete='CASCADE')) Shadowed = Column('fk_shadowed_id', ForeignKey('acl_access.id', ondelete='CASCADE')) Output = WithSignature.createSignature() Hash = Column('hash', String(50), nullable=False, unique=True)