class FileMetadata(db.Model, Timestamp): """Represent a record metadata. The FileMetadata object contains a ``created`` and a ``updated`` properties that are automatically updated. """ # Enables SQLAlchemy-Continuum versioning __versioned__ = {} __tablename__ = 'file_metadata' id = db.Column(db.Integer(), autoincrement=True, primary_key=True) pid = db.Column(db.Integer()) """Record identifier.""" # uid = db.Column( # UUIDType, # default=uuid.uuid4 # ) contents = db.Column(LargeBinary, nullable=True) json = db.Column(db.JSON().with_variant( postgresql.JSONB(none_as_null=True), 'postgresql', ).with_variant( JSONType(), 'sqlite', ).with_variant( JSONType(), 'mysql', ), default=lambda: dict(), nullable=True) """Store metadata in JSON format. When you create a new ``Record`` the ``json`` field value should never be ``NULL``. Default value is an empty dict. ``NULL`` value means that the record metadata has been deleted. """ version_id = db.Column(db.Integer, nullable=False) """Used by SQLAlchemy for optimistic concurrency control.""" __mapper_args__ = {'version_id_col': version_id}
class UserIdentity(db.Model, Timestamp): """Represent a UserIdentity record.""" __tablename__ = "accounts_useridentity" id = db.Column(db.String(255), primary_key=True, nullable=False) method = db.Column(db.String(255), primary_key=True, nullable=False) id_user = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=False) user = db.relationship(User, backref="external_identifiers") __table_args__ = (db.Index("accounts_useridentity_id_user_method", id_user, method, unique=True), ) @classmethod def get_user(cls, method, external_id): """Get the user for a given identity.""" identity = cls.query.filter_by(id=external_id, method=method).one_or_none() if identity is not None: return identity.user return None @classmethod def create(cls, user, method, external_id): """Link a user to an external id. :param user: A :class:`invenio_accounts.models.User` instance. :param method: The identity source (e.g. orcid, github) :param method: The external identifier. :raises AlreadyLinkedError: Raised if already exists a link. """ try: with db.session.begin_nested(): db.session.add( cls(id=external_id, method=method, id_user=user.id)) except IntegrityError: raise AlreadyLinkedError( # dict used for backward compatibility (came from oauthclient) user, { "id": external_id, "method": method }, ) @classmethod def delete_by_external_id(cls, method, external_id): """Unlink a user from an external id.""" with db.session.begin_nested(): cls.query.filter_by(id=external_id, method=method).delete() @classmethod def delete_by_user(cls, method, user): """Unlink a user from an external id.""" with db.session.begin_nested(): cls.query.filter_by(id_user=user.id, method=method).delete()
class Workflow(db.Model): """Represents a workflow instance storing the state of the workflow.""" __tablename__ = "workflows_workflow" uuid = db.Column(UUIDType, primary_key=True, nullable=False, default=uuid.uuid4()) name = db.Column(db.String(255), default="Default workflow", nullable=False) created = db.Column(db.DateTime, default=datetime.now, nullable=False) modified = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now, nullable=False) id_user = db.Column(db.Integer, default=0, nullable=False) extra_data = db.Column(JSONType().with_variant( postgresql.JSON(none_as_null=True), 'postgresql', ), default=lambda: dict(), nullable=False) status = db.Column(ChoiceType(WorkflowStatus, impl=db.Integer()), default=WorkflowStatus.NEW, nullable=False) objects = db.relationship("WorkflowObjectModel", backref='workflows_workflow', cascade="all, delete-orphan") def __repr__(self): """Represent a Workflow instance.""" return "<Workflow(name: %s, cre: %s, mod: %s," \ "id_user: %s, status: %s)>" % \ (str(self.name), str(self.created), str(self.modified), str(self.id_user), str(self.status)) def __str__(self): """Represent a Workflow instance.""" return self.__repr__() @classmethod def delete(cls, uuid): """Delete a workflow.""" to_delete = Workflow.query.get(uuid) db.session.delete(to_delete) def save(self, status=None): """Save object to persistent storage.""" with db.session.begin_nested(): self.modified = datetime.now() if status is not None: self.status = status if self.extra_data is None: self.extra_data = dict() flag_modified(self, 'extra_data') db.session.merge(self)
class ActionIdentifier(db.Model, TimestampMixin): """Define action identifier info.""" __tablename__ = 'workflow_action_identifier' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """Activity_Action identifier.""" activity_id = db.Column(db.String(24), nullable=False, unique=False, index=True) """Activity id of Activity Action.""" action_id = db.Column(db.Integer(), db.ForeignKey(Action.id), nullable=True, unique=False) """Action id.""" action_identifier_select = db.Column(db.Integer, nullable=True, default=0) """Action identifier grant.""" action_identifier_jalc_doi = db.Column(db.String(255), nullable=True, default="") """Action identifier grant jalc doi input.""" action_identifier_jalc_cr_doi = db.Column(db.String(255), nullable=True, default="") """Action identifier grant jalc crossref doi input.""" action_identifier_jalc_dc_doi = db.Column(db.String(255), nullable=True, default="") """Action identifier grant jalc datacite doi input.""" action_identifier_ndl_jalc_doi = db.Column(db.String(255), nullable=True, default="") """Action identifier grant ndl jalc doi input."""
def do_upgrade(): """Implement your upgrades here.""" if not op.has_table('remoteACCOUNT'): op.create_table('remoteACCOUNT', db.Column('id', db.Integer(display_width=15), nullable=False), db.Column('user_id', db.Integer(display_width=15), nullable=False), db.Column('client_id', db.String(length=255), nullable=False), db.Column('extra_data', db.JSON, nullable=True), db.ForeignKeyConstraint( ['user_id'], ['user.id'], ), db.PrimaryKeyConstraint('id'), db.UniqueConstraint('user_id', 'client_id'), mysql_charset='utf8', mysql_engine='MyISAM') else: warnings.warn("*** Creation of table 'remoteACCOUNT table skipped!'") if not op.has_table('remoteTOKEN'): op.create_table('remoteTOKEN', db.Column('id_remote_account', db.Integer(display_width=15), nullable=False), db.Column('token_type', db.String(length=40), nullable=False), db.Column('access_token', db.Text(), nullable=False), db.Column('secret', db.Text(), nullable=False), db.ForeignKeyConstraint( ['id_remote_account'], ['remoteACCOUNT.id'], ), db.PrimaryKeyConstraint('id_remote_account', 'token_type'), mysql_charset='utf8', mysql_engine='MyISAM') else: warnings.warn("*** Creation of table 'remoteTOKEN' skipped!'")
class WorkFlow(db.Model, TimestampMixin): """Define WorkFlow.""" __tablename__ = 'workflow_workflow' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """Flows identifier.""" flows_id = db.Column(UUIDType, nullable=False, unique=True, index=True, default=uuid.uuid4()) """the id of flows.""" flows_name = db.Column(db.String(255), nullable=True, unique=False, index=False) """the name of flows.""" itemtype_id = db.Column(db.Integer(), db.ForeignKey(ItemType.id), nullable=False, unique=False) """the id of itemtype.""" itemtype = db.relationship(ItemType, backref=db.backref( 'workflow', lazy='dynamic', order_by=desc('item_type.tag'))) flow_id = db.Column(db.Integer(), db.ForeignKey(FlowDefine.id), nullable=False, unique=False) """the id of flow.""" flow_define = db.relationship(FlowDefine, backref=db.backref('workflow', lazy='dynamic'))
class Role(db.Model, RoleMixin): """Role data model.""" __tablename__ = "accounts_role" id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255))
class OAIRecord(db.Model): __tablename__ = "oarepo_oai_record" id = db.Column( UUIDType, ForeignKey('records_metadata.id'), primary_key=True, default=uuid.uuid4, ) oai_identifier = db.Column( db.String(2048), unique=True, ) pid = db.Column(db.String(), unique=True, nullable=False) last_sync_id = db.Column(db.Integer(), ForeignKey('oarepo_oai_sync.id'), nullable=True) modification_sync_id = db.Column(db.Integer(), ForeignKey('oarepo_oai_sync.id'), nullable=True) creation_sync_id = db.Column(db.Integer(), ForeignKey('oarepo_oai_sync.id'), nullable=True) timestamp = db.Column(db.TIMESTAMP, nullable=False) metadata_record = relationship("RecordMetadata", backref=backref("oarepo_oai_record", uselist=False)) oai_identifiers = relationship("OAIIdentifier", backref=backref("oarepo_oai_record")) def __repr__(self): return f"OAIRecord(id={self.id}, oai_identifier={self.oai_identifier}, pid={self.pid}, " \ f"last_sync_id={self.last_sync_id}, modification_s" \ f"ync_id={self.modification_sync_id}, creation_sync_id={self.creation_sync_id}, " \ f"timestamp={self.timestamp})" @classmethod def get_record(cls, oai_identifier): oai_identifier = OAIIdentifier.query.filter_by( oai_identifier=oai_identifier).one_or_none() if not oai_identifier: return None else: return cls.query.get(oai_identifier.oai_record_id)
class ActionStatus(db.Model, TimestampMixin): """define ActionStatus.""" __tablename__ = 'workflow_action_status' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """ActionStatus identifier.""" ACTIONSTATUSPOLICY = [ (ActionStatusPolicy.ACTION_BEGIN, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_BEGIN)), (ActionStatusPolicy.ACTION_DONE, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_DONE)), (ActionStatusPolicy.ACTION_DOING, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_DOING)), (ActionStatusPolicy.ACTION_THROWN_OUT, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_THROWN_OUT)), (ActionStatusPolicy.ACTION_NOT_DONE, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_NOT_DONE)), (ActionStatusPolicy.ACTION_RETRY, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_RETRY)), (ActionStatusPolicy.ACTION_SKIPPED, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_SKIPPED)), (ActionStatusPolicy.ACTION_ERROR, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_ERROR)), (ActionStatusPolicy.ACTION_CANCELED, ActionStatusPolicy.describe(ActionStatusPolicy.ACTION_CANCELED)), ] """Subscription policy choices.""" action_status_id = db.Column(ChoiceType(ACTIONSTATUSPOLICY, impl=db.String(1)), default=ActionStatusPolicy.ACTION_BEGIN, nullable=False, unique=True, index=True) """the id of action status.""" action_status_name = db.Column(db.String(32), nullable=True, unique=False, index=False) """the name of action.""" action_status_desc = db.Column(db.Text, nullable=True) """the description of action.""" action_scopes = db.Column(db.String(64), nullable=True) """the scopes of action status(sys,user).""" action_displays = db.Column(db.Text, nullable=True, unique=False) """the display info of action status."""
class FlowActionRole(db.Model, TimestampMixin): """FlowActionRole list belong to FlowAction. It relates an allowed action with a role or a user """ __tablename__ = 'workflow_flow_action_role' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """FlowAction identifier.""" flow_action_id = db.Column(db.Integer(), db.ForeignKey(FlowAction.id), nullable=False, unique=False, index=True) """the id of flow_action.""" action_role = db.Column(db.Integer(), db.ForeignKey(Role.id), nullable=True, unique=False) action_role_exclude = db.Column(db.Boolean(name='role_exclude'), nullable=False, default=False, server_default='0') """If set to True, deny the action, otherwise allow it.""" action_user = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=True, unique=False) action_user_exclude = db.Column(db.Boolean(name='user_exclude'), nullable=False, default=False, server_default='0') """If set to True, deny the action, otherwise allow it."""
class ActivityHistory(db.Model, TimestampMixin): """Define ActivityHistory.""" __tablename__ = 'workflow_action_history' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """ActivityHistory identifier.""" activity_id = db.Column(db.String(24), nullable=False, unique=False, index=True) """activity id of Activity.""" action_id = db.Column(db.Integer(), nullable=False, unique=False) """action id.""" action_version = db.Column(db.String(24), nullable=True, unique=False) """the used version of action.""" action_status = db.Column(db.String(1), db.ForeignKey(ActionStatus.action_status_id), nullable=True) """the status description of action.""" action_user = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=True) """the user of operate action.""" action_date = db.Column(db.DateTime, nullable=False, default=datetime.now) """the date of operate action.""" action_comment = db.Column(db.Text, nullable=True) """action comment.""" user = db.relationship(User, backref=db.backref('activity_history')) """User relaionship."""
class LogAnalysisRestrictedIpAddress(db.Model): """Represent restricted addresses to be restricted from logging. The SiteLicenseIpAddress object contains a ``created`` and a ``updated`` properties that are automatically updated. """ __tablename__ = 'loganalysis_restricted_ip_address' id = db.Column(db.Integer(), primary_key=True, autoincrement=True) ip_address = db.Column(db.String(16), nullable=False, unique=True) @classmethod def get_all(cls): """Get all Ip Addresses. :return: list. """ try: all = cls.query.all() except Exception as ex: current_app.logger.debug(ex) all = [] raise return all @classmethod def update_table(cls, ip_addresses): """Delete all rows and insert new ones.""" try: with db.session.begin_nested(): all_addresses = [ LogAnalysisRestrictedIpAddress(ip_address=i) for i in ip_addresses ] LogAnalysisRestrictedIpAddress.query.delete() db.session.add_all(all_addresses) db.session.commit() except BaseException as ex: db.session.rollback() current_app.logger.debug(ex) raise return cls def __iter__(self): """TODO: __iter__.""" for name in dir(LogAnalysisRestrictedIpAddress): if not name.startswith('__') and not name.startswith('_'): value = getattr(self, name) if isinstance(value, str): yield (name, value)
class UserIdentity(db.Model, Timestamp): """Represent a UserIdentity record.""" __tablename__ = "accounts_useridentity" id = db.Column(db.String(255), primary_key=True, nullable=False) method = db.Column(db.String(255), primary_key=True, nullable=False) id_user = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=False) user = db.relationship(User, backref="external_identifiers") __table_args__ = ( db.Index("useridentity_id_user_method", id_user, method, unique=True), )
class ItemTypeEditHistory(db.Model, Timestamp): """Represent an item type edit history. The ItemTypeEditHistory object contains a ``created`` and a ``updated`` properties that are automatically updated. """ __tablename__ = 'item_type_edit_history' id = db.Column(db.Integer(), primary_key=True, autoincrement=True) """Identifier of item type edit history.""" item_type_id = db.Column(db.Integer(), db.ForeignKey(ItemType.id), nullable=False) """Identifier for item type.""" user_id = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=False) """Identifier for author of item type.""" notes = db.Column(db.JSON().with_variant( postgresql.JSONB(none_as_null=True), 'postgresql', ).with_variant( JSONType(), 'sqlite', ).with_variant( JSONType(), 'mysql', ), default=lambda: dict(), nullable=True) """Edit notes for item type.""" @classmethod def get_latest_by_item_type_id(cls, item_type_id=0): """Get latest notes for item type.""" pass
class Role(db.Model, RoleMixin): """Role data model.""" __tablename__ = "accounts_role" id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) """Role name.""" description = db.Column(db.String(255)) """Role description.""" def __str__(self): """Return the name and description of the role.""" return '{0.name} - {0.description}'.format(self)
class ActionJournal(db.Model, TimestampMixin): """Define journal info.""" __tablename__ = 'workflow_action_journal' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """Activity_Action identifier.""" activity_id = db.Column(db.String(24), nullable=False, unique=False, index=True) """Activity id of Activity Action.""" action_id = db.Column(db.Integer(), db.ForeignKey(Action.id), nullable=True, unique=False) """Action id.""" action_journal = db.Column(db.JSON().with_variant( postgresql.JSONB(none_as_null=True), 'postgresql', ).with_variant( JSONType(), 'sqlite', ).with_variant( JSONType(), 'mysql', ), default=lambda: dict(), nullable=True) """Action journal info."""
class ItemReference(db.Model, Timestamp): """Model of item reference relations.""" __tablename__ = 'item_reference' src_item_pid = db.Column(db.Integer(), nullable=True, primary_key=True) """PID of source item.""" dst_item_pid = db.Column(db.Integer(), nullable=True, primary_key=True) """PID for destination item.""" reference_type = db.Column(db.String(50), nullable=False) """参照元と参照先のアイテム間の関連内容。""" def __repr__(self): """Text representation of a ItemReference relation.""" return "<ItemReference Relation: (records/{r.src_item_pid}) -> " \ "(records/{r.dst_item_pid}) " \ "(Type: {r.reference_type})>".format(r=self) @classmethod def get_src_references(cls, pid): """Get all relations where given PID is a src.""" return cls.query.filter(cls.src_item_pid == pid) @classmethod def get_dst_references(cls, pid): """Get all relations where given PID is a dst.""" return cls.query.filter(cls.dst_item_pid == pid) @classmethod def relation_exists(cls, src_pid, dst_pid, reference_type): """Determine if given relation already exists.""" return ItemReference.query.filter_by( src_item_pid=src_pid, dst_item_pid=dst_pid, reference_type=reference_type).count() > 0
class ActivityAction(db.Model, TimestampMixin): """define Activety""" __tablename__ = 'workflow_activity_action' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """Activity_Action identifier.""" activity_id = db.Column( db.String(24), nullable=False, unique=False, index=True) """activity id of Activity Action.""" action_id = db.Column( db.Integer(), db.ForeignKey(Action.id), nullable=True, unique=False) """action id.""" action_status = db.Column( db.String(1), db.ForeignKey(ActionStatus.action_status_id), nullable=False, unique=False) """action status.""" action_comment = db.Column(db.Text, nullable=True) """action comment."""
class SiteLicenseIpAddress(db.Model, Timestamp): """Represent a SiteLicenseIpAddress data. The SiteLicenseIpAddress object contains a ``created`` and a ``updated`` properties that are automatically updated. """ __tablename__ = 'sitelicense_ip_address' organization_id = db.Column( db.Integer(), db.ForeignKey(SiteLicenseInfo.organization_id, ondelete='RESTRICT'), primary_key=True ) organization_no = db.Column( db.Integer(), primary_key=True, autoincrement=True ) start_ip_address = db.Column( db.String(16), nullable=False ) finish_ip_address = db.Column( db.String(16), nullable=False ) def __iter__(self): for name in dir(SiteLicenseIpAddress): if not name.startswith('__') and not name.startswith('_'): value = getattr(self, name) if isinstance(value, str): yield (name, value)
class UserIdentity(db.Model): """Represent a UserIdentity record.""" __tablename__ = 'oauthclient_useridentity' id = db.Column(db.String(255), primary_key=True, nullable=False) method = db.Column(db.String(255), primary_key=True, nullable=False) id_user = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=False) user = db.relationship(User, backref='external_identifiers') __table_args__ = (db.Index('useridentity_id_user_method', id_user, method, unique=True), )
class ItemTypeMapping(db.Model, Timestamp): """Represent a record metadata. The ItemTypeMapping object contains a ``created`` and a ``updated`` properties that are automatically updated. """ # Enables SQLAlchemy-Continuum versioning __versioned__ = {} __tablename__ = 'item_type_mapping' id = db.Column( db.Integer(), primary_key=True, autoincrement=True ) """Record identifier.""" item_type_id = db.Column(db.Integer) """ID of item type.""" mapping = db.Column( db.JSON().with_variant( postgresql.JSONB(none_as_null=True), 'postgresql', ).with_variant( JSONType(), 'sqlite', ).with_variant( JSONType(), 'mysql', ), default=lambda: dict(), nullable=True ) """Store mapping in JSON format. When you create a new ``Record`` the ``mapping`` field value should never be ``NULL``. Default value is an empty dict. ``NULL`` value means that the record metadata has been deleted. """ version_id = db.Column(db.Integer, nullable=False) """Used by SQLAlchemy for optimistic concurrency control.""" __mapper_args__ = { 'version_id_col': version_id }
class SiteLicenseInfo(db.Model, Timestamp): """Represent a SiteLicenseInfo data. The SiteLicenseInfo object contains a ``created`` and a ``updated`` properties that are automatically updated. """ __tablename__ = 'sitelicense_info' organization_id = db.Column( db.Integer(), primary_key=True, autoincrement=True ) organization_name = db.Column( db.Text, nullable=False ) domain_name = db.Column( db.Text, nullable=True ) mail_address = db.Column( db.String(255), nullable=True ) # Relationships definitions addresses = db.relationship( 'SiteLicenseIpAddress', backref='SiteLicenseInfo') """Relationship to SiteLicenseIpAddress.""" def __iter__(self): sl = {} for name in dir(SiteLicenseInfo): if not name.startswith('__') and not name.startswith('_'): value = getattr(self, name) if isinstance(value, list): ip_lst = [] for lst in value: if isinstance(lst, SiteLicenseIpAddress): ip_lst.append(dict(lst)) yield (name, ip_lst) elif isinstance(value, str): yield (name, value)
class WidgetDesignPageMultiLangData(db.Model): """Table for widget multiple language data for pages.""" __tablename__ = 'widget_design_page_multi_lang_data' id = db.Column(db.Integer, primary_key=True, nullable=False) widget_design_page_id = db.Column(db.Integer(), db.ForeignKey(WidgetDesignPage.id), nullable=False) # FIXME: Shouldn't this be a foreign key lang_code = db.Column(db.String(3), nullable=False) title = db.Column(db.String(100)) def __init__(self, lang_code, title): """Initialize.""" self.lang_code = lang_code self.title = title @classmethod def get_by_id(cls, id): """Get widget multi language data by id.""" return cls.query.filter_by(id=id).one_or_none() @classmethod def delete_by_page_id(cls, page_id): """Delete widget page multi language by page id. :param page_id: Page model's id :return: True if successful or False """ if page_id: try: with db.session.begin_nested(): cls.query.filter_by(widget_design_page_id=page_id).delete() db.session.commit() return True except Exception as ex: db.session.rollback() current_app.logger.error(ex) raise ex return False
class SIPMetadataType(db.Model): """Type of the metadata added to an SIP. The type describes the type of file along with an eventual schema used to validate the structure of the content. """ __tablename__ = 'sipstore_sipmetadatatype' id = db.Column(db.Integer(), primary_key=True) """ID of the SIPMetadataType object.""" title = db.Column(db.String(255), nullable=False) """The title of type of metadata (i.e. 'Invenio JSON Record v1.0.0').""" name = db.Column(db.String(255), nullable=False, unique=True) """The unique name tag of the metadata type.""" format = db.Column(db.String(255), nullable=False) """The format of the metadata (xml, json, txt...). This is used as the extension of the created file during an export. """ schema = db.Column(db.String(1024), nullable=True, unique=True) """URI to a schema that describes the metadata (json or xml schema).""" @classmethod def get(cls, id): """Return the corresponding SIPMetadataType.""" return cls.query.filter_by(id=id).one() @classmethod def get_from_name(cls, name): """Return the corresponding SIPMetadataType.""" return cls.query.filter_by(name=name).one() @classmethod def get_from_schema(cls, schema): """Return the corresponding SIPMetadataType.""" return cls.query.filter_by(schema=schema).one()
class ActionUsers(ActionNeedMixin, db.Model): """ActionRoles data model. It relates an allowed action with a user. """ __tablename__ = 'access_actionsusers' __table_args__ = (UniqueConstraint('action', 'exclude', 'argument', 'user_id', name='access_actionsusers_unique'), ) user_id = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=True) user = db.relationship("User") @property def need(self): """Return UserNeed instance.""" return UserNeed(self.user_id)
class ActionRoles(ActionNeedMixin, db.Model): """ActionRoles data model. It relates an allowed action with a role. """ __tablename__ = 'access_actionsroles' __table_args__ = (UniqueConstraint('action', 'exclude', 'argument', 'role_id', name='access_actionsroles_unique'), ) role_id = db.Column(db.Integer(), db.ForeignKey(Role.id), nullable=False) role = db.relationship("Role") @property def need(self): """Return RoleNeed instance.""" return RoleNeed(self.role.name)
class Role(db.Model, Timestamp, RoleMixin): """Role data model.""" __tablename__ = "accounts_role" id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) """Role name.""" description = db.Column(db.String(255)) """Role description.""" # Enables SQLAlchemy version counter version_id = db.Column(db.Integer, nullable=False) """Used by SQLAlchemy for optimistic concurrency control.""" __mapper_args__ = {"version_id_col": version_id} def __str__(self): """Return the name and description of the role.""" return '{0.name} - {0.description}'.format(self)
class Action(db.Model, TimestampMixin): """define Action.""" __tablename__ = 'workflow_action' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """Action identifier.""" action_name = db.Column(db.String(255), nullable=True, unique=False, index=False) """the name of action.""" action_desc = db.Column(db.Text, nullable=True) """the description of action.""" action_endpoint = db.Column(db.String(24), nullable=True, index=False) """the endpoint of action""" action_version = db.Column(db.String(64), nullable=True) """the version of action.""" action_makedate = db.Column(db.DateTime, nullable=False, default=datetime.now) """the create date of action.""" action_lastdate = db.Column(db.DateTime, nullable=False, default=datetime.now) """the last update date of action.""" action_is_need_agree = db.Column(db.Boolean, nullable=True, default=False)
class Activity(db.Model, TimestampMixin): """Define Activety.""" __tablename__ = 'workflow_activity' id = db.Column(db.Integer(), nullable=False, primary_key=True, autoincrement=True) """Activity identifier.""" activity_id = db.Column(db.String(24), nullable=False, unique=True, index=True) """activity id of Activity.""" activity_name = db.Column(db.String(255), nullable=True, unique=False, index=False) """activity name of Activity.""" item_id = db.Column(UUIDType, nullable=True, unique=False, index=True) """item id.""" workflow_id = db.Column(db.Integer(), db.ForeignKey(WorkFlow.id), nullable=False, unique=False) """workflow id.""" workflow = db.relationship(WorkFlow, backref=db.backref('activity', lazy='dynamic')) workflow_status = db.Column(db.Integer(), nullable=True, unique=False) """workflow status.""" flow_id = db.Column(db.Integer(), db.ForeignKey(FlowDefine.id), nullable=True, unique=False) """flow id.""" flow_define = db.relationship(FlowDefine, backref=db.backref('activity', lazy='dynamic')) action_id = db.Column(db.Integer(), db.ForeignKey(Action.id), nullable=True, unique=False) """action id.""" action = db.relationship(Action, backref=db.backref('activity', lazy='dynamic')) # action_version = db.Column( # db.String(24), nullable=True, unique=False) # """action version.""" action_status = db.Column(db.String(1), db.ForeignKey(ActionStatus.action_status_id), nullable=True, unique=False) """action status.""" activity_login_user = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=True, unique=False) """the user of create activity.""" activity_update_user = db.Column(db.Integer(), db.ForeignKey(User.id), nullable=True, unique=False) """the user of update activity.""" ACTIVITYSTATUSPOLICY = [ (ActivityStatusPolicy.ACTIVITY_BEGIN, ActivityStatusPolicy.describe(ActivityStatusPolicy.ACTIVITY_BEGIN)), (ActivityStatusPolicy.ACTIVITY_FINALLY, ActivityStatusPolicy.describe(ActivityStatusPolicy.ACTIVITY_FINALLY)), (ActivityStatusPolicy.ACTIVITY_FORCE_END, ActivityStatusPolicy.describe( ActivityStatusPolicy.ACTIVITY_FORCE_END)), (ActivityStatusPolicy.ACTIVITY_CANCEL, ActivityStatusPolicy.describe(ActivityStatusPolicy.ACTIVITY_CANCEL)), (ActivityStatusPolicy.ACTIVITY_MAKING, ActivityStatusPolicy.describe(ActivityStatusPolicy.ACTIVITY_MAKING)), (ActivityStatusPolicy.ACTIVITY_ERROR, ActivityStatusPolicy.describe(ActivityStatusPolicy.ACTIVITY_ERROR)), ] """Subscription policy choices.""" activity_status = db.Column(ChoiceType(ACTIVITYSTATUSPOLICY, impl=db.String(1)), default=ActivityStatusPolicy.ACTIVITY_BEGIN, nullable=True, unique=False, index=False) """activity status.""" activity_start = db.Column(db.DateTime, nullable=False) """activity start date.""" activity_end = db.Column(db.DateTime, nullable=True) """activity end date.""" activity_community_id = db.Column(db.Text, nullable=True) """activity community id"""
class ItemType(db.Model, Timestamp): """Represent an item type. The ItemType object contains a ``created`` and a ``updated`` properties that are automatically updated. """ # Enables SQLAlchemy-Continuum versioning __versioned__ = {} __tablename__ = 'item_type' id = db.Column( db.Integer(), primary_key=True, autoincrement=True ) """Identifier of item type.""" name_id = db.Column( db.Integer(), db.ForeignKey( 'item_type_name.id', name='fk_item_type_name_id' ), nullable=False ) """Name identifier of item type.""" item_type_name = db.relationship( 'ItemTypeName', backref=db.backref('item_type', lazy='dynamic', order_by=desc('item_type.tag')) ) """Name information from ItemTypeName class.""" schema = db.Column( db.JSON().with_variant( postgresql.JSONB(none_as_null=True), 'postgresql', ).with_variant( JSONType(), 'sqlite', ).with_variant( JSONType(), 'mysql', ), default=lambda: dict(), nullable=True ) """Store schema in JSON format. When you create a new ``item type`` the ``schema`` field value should never be ``NULL``. Default value is an empty dict. ``NULL`` value means that the record metadata has been deleted. """ form = db.Column( db.JSON().with_variant( postgresql.JSONB(none_as_null=True), 'postgresql', ).with_variant( JSONType(), 'sqlite', ).with_variant( JSONType(), 'mysql', ), default=lambda: dict(), nullable=True ) """Store schema form in JSON format. When you create a new ``item type`` the ``form`` field value should never be ``NULL``. Default value is an empty dict. ``NULL`` value means that the record metadata has been deleted. """ render = db.Column( db.JSON().with_variant( postgresql.JSONB(none_as_null=True), 'postgresql', ).with_variant( JSONType(), 'sqlite', ).with_variant( JSONType(), 'mysql', ), default=lambda: dict(), nullable=True ) """Store page render information in JSON format. When you create a new ``item type`` the ``render`` field value should never be ``NULL``. Default value is an empty dict. ``NULL`` value means that the record metadata has been deleted. """ tag = db.Column(db.Integer, nullable=False) """Tag of item type.""" version_id = db.Column(db.Integer, nullable=False) """Used by SQLAlchemy for optimistic concurrency control.""" __mapper_args__ = { 'version_id_col': version_id }