How to use the extensions.db function in extensions

To help you get started, we’ve selected a few extensions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dlapiduz / govcode.org / models.py View on Github external
username = db.Column(db.String(50), unique=True)
    slug = db.Column(db.String(100), unique=True)
    ignore = db.Column(db.Boolean, default=False)

    def __repr__(self):
        return '' % self.name

class Repository(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    gh_id = db.Column(db.Integer)
    name = db.Column(db.String(100))
    forks = db.Column(db.Integer)
    watchers = db.Column(db.Integer)
    size = db.Column(db.Integer)
    open_issues = db.Column(db.Integer)
    description = db.Column(db.Text)
    organization_id = db.Column(db.Integer, db.ForeignKey('organization.id'))
    organization = db.relationship('Organization',
        backref=db.backref('repositories', lazy='dynamic'))
    users = db.relationship("User", secondary="commit", backref="repositories")
    slug = db.Column(db.String(100), unique=True)
    last_commit_date = db.Column(db.DateTime)

    @hybrid_property
    def last_commit(self):
        return self.commits.order_by(desc(Commit.date)).first()

    def __repr__(self):
        return '' % self.name

class Commit(db.Model):
    id = db.Column(db.Integer, primary_key=True)
github pycook / cmdb / models / ci_type.py View on Github external
__tablename__ = "ci_types"

    type_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    type_name = db.Column(db.String(32))
    type_alias = db.Column(db.String(32))
    uniq_id = db.Column(db.Integer,
                        db.ForeignKey("ci_attributes.attr_id"),
                        nullable=False)
    uniq_key = db.relationship("CIAttribute", backref="ci_types")
    enabled = db.Column(db.Boolean, default=True, nullable=False)
    is_attached = db.Column(db.Boolean, default=False, nullable=False)
    icon_url = db.Column(db.String(256))
    order = db.Column(db.SmallInteger, default=0, nullable=False)


class CITypeAttribute(db.Model):
    __tablename__ = "type_attributes"

    type_id = db.Column(db.Integer,
                        db.ForeignKey("ci_types.type_id"),
                        primary_key=True)
    attr_id = db.Column(db.Integer,
                        db.ForeignKey("ci_attributes.attr_id"),
                        primary_key=True)
    is_required = db.Column(db.Boolean, default=False)
    order = db.Column(db.Integer, default=0)

    __table_args__ = (db.UniqueConstraint("type_id", "attr_id",
                                          name="type_attr_uniq"), )


class CITypeCache(object):
github pycook / cmdb / models / ci_relation.py View on Github external
# -*- coding:utf-8 -*- 


from extensions import db


class CIRelation(db.Model):
    __tablename__ = "ci_relations"
    cr_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    first_ci_id = db.Column(db.Integer,
                            db.ForeignKey("cis.ci_id"),
                            primary_key=True)
    second_ci_id = db.Column(db.Integer,
                             db.ForeignKey("cis.ci_id"),
                             primary_key=True)
    first_ci = db.relationship("CI",
                               primaryjoin="CI.ci_id==CIRelation.first_ci_id")
    second_ci = db.relationship(
        "CI", primaryjoin="CI.ci_id==CIRelation.second_ci_id")
    relation_type = db.Column(
        db.Enum("connect", "deploy", "install", "contain",
                name="relation_type"), nullable=False)
    more = db.Column(db.Integer, db.ForeignKey("cis.ci_id"))
github imwilsonxu / fbone / fbone / app.py View on Github external
def initdb():
        db.drop_all()
        db.create_all()
github pycook / cmdb / models / ci_type_relation.py View on Github external
parent_id = db.Column(db.Integer,
                          db.ForeignKey("ci_types.type_id"),
                          primary_key=True)
    parent = db.relationship(
        "CIType", primaryjoin="CIType.type_id==CITypeRelation.parent_id")
    child_id = db.Column(db.Integer,
                         db.ForeignKey("ci_types.type_id"),
                         primary_key=True)
    child = db.relationship(
        "CIType", primaryjoin="CIType.type_id==CITypeRelation.child_id")
    relation_type = db.Column(
        db.Enum("contain", "connect", "deploy", "install",
                name="relation_type"),
        default="contain")

    __table_args__ = (db.UniqueConstraint("parent_id", "child_id",
                                          name="parent_child_uniq"), )
github pycook / cmdb / models / ci_type.py View on Github external
enabled = db.Column(db.Boolean, default=True, nullable=False)
    is_attached = db.Column(db.Boolean, default=False, nullable=False)
    icon_url = db.Column(db.String(256))
    order = db.Column(db.SmallInteger, default=0, nullable=False)


class CITypeAttribute(db.Model):
    __tablename__ = "type_attributes"

    type_id = db.Column(db.Integer,
                        db.ForeignKey("ci_types.type_id"),
                        primary_key=True)
    attr_id = db.Column(db.Integer,
                        db.ForeignKey("ci_attributes.attr_id"),
                        primary_key=True)
    is_required = db.Column(db.Boolean, default=False)
    order = db.Column(db.Integer, default=0)

    __table_args__ = (db.UniqueConstraint("type_id", "attr_id",
                                          name="type_attr_uniq"), )


class CITypeCache(object):
    @classmethod
    def get(cls, key):
        if key is None:
            return
        ct = cache.get("CIType::ID::%s" % key) or \
            cache.get("CIType::Name::%s" % key)
        if ct is None:
            ct = db.session.query(CIType).filter(
                CIType.type_name == key).first() or \
github pycook / cmdb / models / ci_type.py View on Github external
nullable=False)
    uniq_key = db.relationship("CIAttribute", backref="ci_types")
    enabled = db.Column(db.Boolean, default=True, nullable=False)
    is_attached = db.Column(db.Boolean, default=False, nullable=False)
    icon_url = db.Column(db.String(256))
    order = db.Column(db.SmallInteger, default=0, nullable=False)


class CITypeAttribute(db.Model):
    __tablename__ = "type_attributes"

    type_id = db.Column(db.Integer,
                        db.ForeignKey("ci_types.type_id"),
                        primary_key=True)
    attr_id = db.Column(db.Integer,
                        db.ForeignKey("ci_attributes.attr_id"),
                        primary_key=True)
    is_required = db.Column(db.Boolean, default=False)
    order = db.Column(db.Integer, default=0)

    __table_args__ = (db.UniqueConstraint("type_id", "attr_id",
                                          name="type_attr_uniq"), )


class CITypeCache(object):
    @classmethod
    def get(cls, key):
        if key is None:
            return
        ct = cache.get("CIType::ID::%s" % key) or \
            cache.get("CIType::Name::%s" % key)
        if ct is None:
github pycook / cmdb / models / ci_type.py View on Github external
# -*- coding:utf-8 -*- 

from extensions import db
from extensions import cache


class CIType(db.Model):
    __tablename__ = "ci_types"

    type_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    type_name = db.Column(db.String(32))
    type_alias = db.Column(db.String(32))
    uniq_id = db.Column(db.Integer,
                        db.ForeignKey("ci_attributes.attr_id"),
                        nullable=False)
    uniq_key = db.relationship("CIAttribute", backref="ci_types")
    enabled = db.Column(db.Boolean, default=True, nullable=False)
    is_attached = db.Column(db.Boolean, default=False, nullable=False)
    icon_url = db.Column(db.String(256))
    order = db.Column(db.SmallInteger, default=0, nullable=False)


class CITypeAttribute(db.Model):
    __tablename__ = "type_attributes"

    type_id = db.Column(db.Integer,
                        db.ForeignKey("ci_types.type_id"),
github pycook / cmdb / models / ci.py View on Github external
import datetime

from extensions import db


class CI(db.Model):
    __tablename__ = "cis"

    ci_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    uuid = db.Column(db.String(32), nullable=False)
    type_id = db.Column(db.Integer,
                        db.ForeignKey("ci_types.type_id"),
                        nullable=False)
    ci_type = db.relationship("CIType", backref="cis")
    status = db.Column(db.Enum("review", "validate", name="status"))
    created_time = db.Column(db.DateTime, default=datetime.datetime.now())
    heartbeat = db.Column(db.DateTime, default=datetime.datetime.now())