コード例 #1
0
class Namespaces(base.Base, db.Model):
    """Namespaces model."""
    __tablename__ = 'namespaces'

    namespace_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode(length=45), nullable=False, unique=True)
    display_name = db.Column(db.Unicode(length=255), nullable=False)
コード例 #2
0
ファイル: attributes.py プロジェクト: sepatus88/ggrc-core
class Attributes(base.Base, db.Model):
  """Attributes model."""
  __tablename__ = 'attributes'

  attribute_id = db.Column(db.Integer, primary_key=True)
  # object id should eventually be a foreign key to objects table
  object_id = db.Column(db.Integer)
  object_type = db.Column(db.Unicode(250))
  attribute_definition_id = db.Column(
      db.Integer,
      db.ForeignKey('attribute_definitions.attribute_definition_id')
  )
  attribute_template_id = db.Column(
      db.Integer,
      db.ForeignKey('attribute_templates.attribute_template_id')
  )

  value_string = db.Column(db.UnicodeText)
  value_integer = db.Column(db.Integer)
  value_datetime = db.Column(db.DateTime)

  # ggrc specific code, needs to be added back to DP.
  source_type = db.Column(db.Unicode(250))
  source_id = db.Column(db.Integer)
  source_attr = db.Column(db.Unicode(250))

  namespace_id = db.Column(
      db.Integer, db.ForeignKey('namespaces.namespace_id'), nullable=True)

  deleted = db.Column(db.Boolean, default=False)
  version = db.Column(db.Integer)

  attribute_definition = orm.relationship(
      "AttributeDefinitions",
      backref="attributes"
  )
  attribute_template = orm.relationship(
      "AttributeTemplates",
      backref="attributes"
  )

  namespace = orm.relationship("Namespaces", backref="attributes")

  @declared_attr
  def __table_args__(cls):  # pylint: disable=no-self-argument
    return (
        db.Index("ix_source", "source_type", "source_id", "source_attr"),
        # db.Index("value_string"), not needed yet
        db.Index("ix_value_integer", "value_integer"),
        db.Index("ix_value_datetime", "value_datetime"),
        db.UniqueConstraint(
            "object_id",
            "object_type",
            "attribute_definition_id",
            "attribute_template_id",
            name="uq_attributes",
        ),
    )
コード例 #3
0
class AttributeTypes(base.Base, db.Model):
    """Attribute types model."""
    __tablename__ = 'attribute_types'

    attribute_type_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode(length=255), nullable=False)
    field_type = db.Column(db.Unicode(length=255), nullable=False)
    db_column_name = db.Column(db.Unicode(length=50), nullable=False)
    computed = db.Column(db.Boolean, nullable=False, default=False)
    aggregate_function = db.Column(db.UnicodeText())

    namespace_id = db.Column(db.Integer,
                             db.ForeignKey('namespaces.namespace_id'),
                             nullable=True)

    namespace = orm.relationship("Namespaces", backref="attribute_types")
コード例 #4
0
class AttributeDefinitions(base.Base, db.Model):
    """Attribute Definition model."""
    __tablename__ = 'attribute_definitions'

    attribute_definition_id = db.Column(db.Integer, primary_key=True)
    attribute_type_id = db.Column(
        db.Integer, db.ForeignKey('attribute_types.attribute_type_id'))
    name = db.Column(db.Unicode(length=255), nullable=False)
    display_name = db.Column(db.Unicode(length=255), nullable=False)
    namespace_id = db.Column(db.Integer,
                             db.ForeignKey('namespaces.namespace_id'),
                             nullable=True)

    attribute_type = orm.relationship("AttributeTypes",
                                      backref="attribute_definitions")
    namespace = orm.relationship("Namespaces", backref="attribute_definitions")
コード例 #5
0
class ObjectTemplates(base.Base, db.Model):
    """Object Templates model."""
    __tablename__ = 'object_templates'

    object_template_id = db.Column(db.Integer, primary_key=True)
    object_type_id = db.Column(db.Integer,
                               db.ForeignKey('object_types.object_type_id'))
    name = db.Column(db.Unicode(length=255), nullable=False)
    display_name = db.Column(db.Unicode(length=255), nullable=False)

    namespace_id = db.Column(db.Integer,
                             db.ForeignKey('namespaces.namespace_id'),
                             nullable=True)

    object_type = orm.relationship("ObjectTypes", backref="object_templates")

    namespace = orm.relationship("Namespaces", backref="object_templates")
コード例 #6
0
class ObjectTypes(base.Base, db.Model):
    """Object types model."""
    __tablename__ = 'object_types'

    object_type_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode(length=255), nullable=False)
    display_name = db.Column(db.Unicode(length=255), nullable=False)

    namespace_id = db.Column(db.Integer,
                             db.ForeignKey('namespaces.namespace_id'),
                             nullable=True)
    parent_object_type_id = db.Column(
        db.Integer, db.ForeignKey('object_types.object_type_id'))

    namespace = orm.relationship("Namespaces", backref="object_types")
    parent_object_type = orm.relationship(
        "ObjectTypes",
        backref="child_object_types",
        remote_side='ObjectTypes.object_type_id')

    @declared_attr
    def __table_args__(cls):  # pylint: disable=no-self-argument
        return (db.UniqueConstraint("name", "namespace_id"), )