Пример #1
0
class HstDOCUMENT(db.Model):
    """Represent a HstDOCUMENT record."""

    __tablename__ = 'hstDOCUMENT'
    id = db.Column(db.Integer(15, unsigned=True),
                   primary_key=True,
                   nullable=False,
                   autoincrement=True)
    id_bibdoc = db.Column(db.MediumInteger(9, unsigned=True),
                          db.ForeignKey(Bibdoc.id),
                          primary_key=True,
                          nullable=False,
                          autoincrement=False)
    docname = db.Column(db.String(250), nullable=False, index=True)
    docformat = db.Column(db.String(50), nullable=False, index=True)
    docversion = db.Column(db.TinyInteger(4, unsigned=True), nullable=False)
    docsize = db.Column(db.BigInteger(15, unsigned=True), nullable=False)
    docchecksum = db.Column(db.Char(32), nullable=False)
    doctimestamp = db.Column(db.DateTime, nullable=False, index=True)
    action = db.Column(db.String(50), nullable=False, index=True)
    job_id = db.Column(db.MediumInteger(15, unsigned=True),
                       nullable=True,
                       index=True)
    job_name = db.Column(db.String(255), nullable=True, index=True)
    job_person = db.Column(db.String(255), nullable=True, index=True)
    job_date = db.Column(db.DateTime, nullable=True, index=True)
    job_details = db.Column(db.iBinary, nullable=True)
Пример #2
0
class Bibdocfsinfo(db.Model):
    """Represents a Bibdocfsinfo record."""
    __tablename__ = 'bibdocfsinfo'

    id_bibdoc = db.Column(db.MediumInteger(9, unsigned=True),
                          db.ForeignKey(Bibdoc.id),
                          primary_key=True,
                          nullable=False,
                          autoincrement=False)
    version = db.Column(db.TinyInteger(4, unsigned=True),
                        primary_key=True,
                        nullable=False,
                        autoincrement=False)
    format = db.Column(db.String(50),
                       primary_key=True,
                       nullable=False,
                       index=True)
    last_version = db.Column(db.Boolean, nullable=False, index=True)
    cd = db.Column(db.DateTime, nullable=False, index=True)
    md = db.Column(db.DateTime, nullable=False, index=True)
    checksum = db.Column(db.Char(32), nullable=False)
    filesize = db.Column(db.BigInteger(15, unsigned=True),
                         nullable=False,
                         index=True)
    mime = db.Column(db.String(100), nullable=False, index=True)
    master_format = db.Column(db.String(50))
Пример #3
0
class RnkRECORDSCACHE(db.Model):
    """Represent a RnkRECORDSCACHE record."""

    __tablename__ = 'rnkRECORDSCACHE'
    id_bibrec = db.Column(db.MediumInteger(8, unsigned=True),
                          db.ForeignKey(Bibrec.id),
                          nullable=True,
                          primary_key=True)
    authorid = db.Column(db.BigInteger(10), primary_key=True, nullable=False)
Пример #4
0
class RnkEXTENDEDAUTHORS(db.Model):
    """Represent a RnkEXTENDEDAUTHORS record."""

    __tablename__ = 'rnkEXTENDEDAUTHORS'
    id = db.Column(db.Integer(10, unsigned=True),
                   primary_key=True,
                   nullable=False,
                   autoincrement=False)
    authorid = db.Column(db.BigInteger(10),
                         primary_key=True,
                         nullable=False,
                         autoincrement=False)
def do_upgrade():
    """Implement your upgrades here."""
    op.create_table('quotaUSAGE',
    db.Column('id', db.Integer(display_width=15), nullable=False),
    db.Column('object_type', db.String(length=40), nullable=True),
    db.Column('object_id', db.String(length=250), nullable=True),
    db.Column('metric', db.String(length=40), nullable=True),
    db.Column('value', db.BigInteger(), nullable=False),
    db.Column('modified', db.DateTime(), nullable=False),
    db.PrimaryKeyConstraint('id'),
    db.UniqueConstraint('object_type', 'object_id', 'metric'),
    mysql_charset='utf8',
    mysql_engine='MyISAM'
    )
    op.create_index(op.f('ix_quotaUSAGE_object_id'), 'quotaUSAGE', ['object_id'], unique=False)
    op.create_index(op.f('ix_quotaUSAGE_object_type'), 'quotaUSAGE', ['object_type'], unique=False)
Пример #6
0
class ResourceUsage(db.Model):
    """Usage of a specific.

    Note: Model is not suitable to store metrics with high granularity.
    """

    __tablename__ = 'quotaUSAGE'

    __table_args__ = (
        # Requires object_type, object_id and metric combined to be less than
        # ~333 chars due to MyISAM constraint.
        db.UniqueConstraint('object_type', 'object_id', 'metric'),
        db.Model.__table_args__)

    id = db.Column(db.Integer(15, unsigned=True),
                   nullable=False,
                   primary_key=True,
                   autoincrement=True)

    object_type = db.Column(db.String(40), index=True)
    """Generic relationship to an object type."""

    object_id = db.Column(db.String(250), index=True)
    """Generic relationship to an object."""

    metric = db.Column(db.String(40))
    """Metric."""

    value = db.Column(db.BigInteger(), nullable=False, default=0)

    modified = db.Column(db.DateTime,
                         nullable=False,
                         default=datetime.now,
                         onupdate=datetime.now)
    """Modification timestamp."""
    @classmethod
    def create(cls, object_type, object_id, metric, value):
        """Update or create a new value of a metric."""
        m = cls(object_type=object_type,
                object_id=object_id,
                metric=metric,
                value=value)
        db.session.add(m)
        db.session.commit()
        return m

    @classmethod
    def update_or_create(cls, object_type, object_id, metric, value):
        """Update or create a new value of a metric."""
        m = cls.get(object_type, object_id, metric)

        if m is None:
            m = cls.create(object_type, object_id, metric, value)

            resource_usage_updated.send(metric,
                                        object_type=object_type,
                                        object_id=object_id,
                                        value=value,
                                        old_value=None)
        else:
            old_value = m.value
            m.value = value
            db.session.commit()

            resource_usage_updated.send(metric,
                                        object_type=object_type,
                                        object_id=object_id,
                                        value=value,
                                        old_value=old_value)
        return m

    @classmethod
    def get(cls, object_type, object_id, metric):
        """Get specific metric."""
        try:
            return cls.query.filter_by(object_type=object_type,
                                       object_id=object_id,
                                       metric=metric).one()
        except NoResultFound:
            return None