class Order(db.Model): __tablename__ = 'orders' id = db.Column('orderid', db.Integer, db.Sequence('orders_orderid_seq'), primary_key=True, server_default=db.FetchedValue()) orderdate = db.Column(db.Date, nullable=False) customerid = db.Column(db.ForeignKey('customers.customerid', ondelete='SET NULL'), index=True) netamount = db.Column(db.Numeric(12, 2), nullable=False) tax = db.Column(db.Numeric(12, 2), nullable=False) totalamount = db.Column(db.Numeric(12, 2), nullable=False) customer = db.relationship('Customer', primaryjoin='Order.customerid == Customer.id', backref='orders') def _asdict(self): return { "id": self.id, "orderdate": self.orderdate, "customerid": self.customerid, "netamount": self.netamount, "tax": self.tax, "totalamount": self.totalamount, "positions": self.positions }
class Order(db.Model): __tablename__ = 'orders' orderid = db.Column(db.Integer, primary_key=True, server_default=db.FetchedValue()) orderdate = db.Column(db.Date, nullable=False) customerid = db.Column(db.ForeignKey('customers.customerid', ondelete='SET NULL'), index=True) netamount = db.Column(db.Numeric(12, 2), nullable=False) tax = db.Column(db.Numeric(12, 2), nullable=False) totalamount = db.Column(db.Numeric(12, 2), nullable=False) customer = db.relationship( 'Customer', primaryjoin='Order.customerid == Customer.customerid', backref='orders') items = db.relationship('Product', secondary=t_orderlines, backref="orderid") def _asdict(self): return { "orderid": self.orderid, "orderdate": self.orderdate, "customerid": self.customerid, "netamount": self.netamount, "tax": self.tax, "totalamount": self.totalamount, "items": self.items }
class Score(db.Model): """ Schema for score submission for a given match. """ __tablename__ = 'records' __table_args__ = {'extend_existing': True} id = db.Column(db.Integer, primary_key=True) # Player id's. player_1 = db.Column(db.String()) player_2 = db.Column(db.String()) player_3 = db.Column(db.String()) player_4 = db.Column(db.String()) # Team scores. score_12 = db.Column(db.Integer) score_34 = db.Column(db.Integer) # Timestamp for the match. timestamp = db.Column(db.Integer) # Rank per player (BEFORE the match). elo_1 = db.Column(db.Numeric(7, 3), default=1000) elo_2 = db.Column(db.Numeric(7, 3), default=1000) elo_3 = db.Column(db.Numeric(7, 3), default=1000) elo_4 = db.Column(db.Numeric(7, 3), default=1000) def __init__(self, player_1, player_2, player_3, player_4, score_12, score_34, timestamp, elo_1, elo_2, elo_3, elo_4): self.player_1 = player_1 self.player_2 = player_2 self.player_3 = player_3 self.player_4 = player_4 self.timestamp = timestamp self.score_12 = score_12 self.score_34 = score_34 self.elo_1 = elo_1 self.elo_2 = elo_2 self.elo_3 = elo_3 self.elo_4 = elo_4 def __repr__(self): return ( f"<id {self.id} | {self.player_1.split(' ')[0]} | {self.player_2.split(' ')[0]}" f" | {self.player_3.split(' ')[0]} | {self.player_4.split(' ')[0]} | " f"{self.score_12} | {self.score_34} | " f"{self.elo_1} | {self.elo_2} | {self.elo_3} | {self.elo_4}") def __team_of_two(self, team): """ Will be used when database supports 1 v. 1 matches. """ return isinstance(team, list) or isinstance(team, tuple)
class Event(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(200), nullable=False) description = db.Column(db.String(2000)) photo = db.Column(db.String(2000)) funding_start_date = db.Column(db.DateTime(), nullable=False) funding_end_date = db.Column(db.DateTime(), nullable=False) creation_date = db.Column(db.DateTime(), nullable=False) goal = db.Column(db.Float) long = db.Column(db.Numeric(11, 8)) lat = db.Column(db.Numeric(11, 8)) stars = db.Column(db.Float) event_start_date = db.Column(db.DateTime(), nullable=False) event_end_date = db.Column(db.DateTime()) location = db.Column(db.String(200), nullable=False) user_creator = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) tags = db.relationship('Tag', secondary=tags, lazy='subquery', backref=db.backref('tags', lazy=True)) watchers = db.relationship("User", secondary=watchers, backref="watching") backers = db.relationship("Funded", back_populates="backers") votes = db.relationship("VotedTest", back_populates="votes") def __init__(self, name, description, funding_start_date, funding_end_date, goal, event_start_date, event_end_date, location, user_creator, lat, long, photo): self.name = name self.description = description self.funding_start_date = funding_start_date self.funding_end_date = funding_end_date self.creation_date = datetime.datetime.now() self.goal = goal self.event_start_date = event_start_date self.event_end_date = event_end_date self.location = location self.user_creator = user_creator self.lat = lat self.long = long self.photo = photo def __repr__(self): return '<Event %r>' % self.name
class Identity(db.Model): eth_address = db.Column(db.Numeric(precision=50, scale=0), primary_key=True) phone = db.Column(db.String(20), index=True) verified = db.Column(db.Boolean()) created_at = db.Column(db.DateTime(timezone=True), server_default=func.now()) updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
class VerificationCode(db.Model): eth_address = db.Column(db.Numeric(precision=50, scale=0), primary_key=True) phone = db.Column(db.String(20), index=True) code = db.Column(db.String(10)) expires_at = db.Column(db.DateTime(timezone=True)) created_at = db.Column(db.DateTime(timezone=True), server_default=func.now()) updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
class Product(db.Model): __tablename__ = 'products' id = db.Column(db.String(36), primary_key=True, default=lambda: str(uuid4())) name = db.Column(db.String(36), unique=True) cost_values = db.Column(db.Float(20)) unit_per_box = db.Column(db.Numeric(6)) weight_per_unit = db.Column(db.String(10)) measure_unit = db.Column(db.String(10), nullable=False) shelf_life = db.Column(db.String(10)) sku = db.Column(db.String(10), unique=True) description = db.Column(db.String(70)) created_at = db.Column(db.DateTime(timezone=True), default=func.now()) updated_at = db.Column(db.DateTime(timezone=True), onupdate=func.now()) deleted_at = db.Column(db.DateTime(timezone=True), default=None) is_active = db.Column(db.Boolean(10), default=True) id_product_line = db.Column( db.String(36), db.ForeignKey('product_line.id') ) def __init__(self, **kwargs): super().__init__(**kwargs) for keys in kwargs: if kwargs[keys] is None or kwargs[keys] == '': raise NullValueException(f'The field {keys} can not be null') def serialize(self): return { "id": self.id, "name": self.name, "cost_values": self.cost_values, "unit_per_box": int(self.unit_per_box), "weight_per_unit": self.weight_per_unit, 'measure_unit': self.measure_unit, "shelf_life": self.shelf_life, "sku": self.sku, "description": self.description, "id_product_line": self.id_product_line, "is_active": self.is_active, "created_at": self.created_at, "updated_at": self.updated_at, "deleted_at": self.deleted_at }
class Product(db.Model): __tablename__ = 'products' prod_id = db.Column(db.Integer, primary_key=True, server_default=db.FetchedValue()) category = db.Column(db.Integer, nullable=False, index=True) title = db.Column(db.String(50), nullable=False) actor = db.Column(db.String(50), nullable=False) price = db.Column(db.Numeric(12, 2), nullable=False) special = db.Column(db.SmallInteger, index=True) common_prod_id = db.Column(db.Integer, nullable=False) def _asdict(self): return { "prod_id": self.prod_id, "category": self.category, "title": self.title, "actor": self.actor, "price": self.price, "special": self.special, "common_prod_id": self.common_prod_id }
class Product(db.Model): __tablename__ = 'products' id = db.Column('prod_id', db.Integer, db.Sequence('products_prod_id_seq'), primary_key=True, server_default=db.FetchedValue()) category = db.Column(db.Integer, nullable=False, index=True) title = db.Column(db.String(50), nullable=False) actor = db.Column(db.String(50), nullable=False) price = db.Column(db.Numeric(12, 2), nullable=False) special = db.Column(db.SmallInteger, index=True) common_prod_id = db.Column(db.Integer, nullable=False) orders = db.relationship('Orderline', primaryjoin="Orderline.prod_id == Product.id", backref="product") inventory = db.relationship('Inventory', primaryjoin="Inventory.prod_id == Product.id", foreign_keys=id) categorytitle = db.relationship( 'Category', primaryjoin="Category.id == Product.category", foreign_keys=category) def _asdict(self): return { "id": self.id, "category": self.category, "categorytitle": str(self.categorytitle), "title": self.title, "actor": self.actor, "price": self.price, "special": self.special, "common_prod_id": self.common_prod_id, "inventory": self.inventory._asdict() }
class Stats(db.Model): """ Schema for people and rankings. """ __tablename__ = 'stats' __table_args__ = {'extend_existing': True} id = db.Column(db.Integer, primary_key=True) # Player information. player_id = db.Column(db.String()) name = db.Column(db.String()) elo = db.Column(db.Numeric(7, 3, asdecimal=False), default=1000) # Career stats. games = db.Column(db.Integer, default=0) wins = db.Column(db.Integer, default=0) losses = db.Column(db.Integer, default=0) def __init__(self, player_id, name): self.player_id = player_id self.name = name def __repr__(self): return (f"{self.name} | {self.elo} | {self.wins} | " f"{self.losses} | {self.games}")
class Change(db.Model): id = db.Column(db.Integer, primary_key=True) moment = db.Column(db.Date, nullable=False, index=True) value = db.Column(db.Numeric(10, 5), nullable=False) variable_id = db.Column(db.Integer, db.ForeignKey('variable.id'))