class User(db.Model): __tablename__ = 'users' uuid = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(256), index=True, unique=True) posts = db.relationship('Post', backref='author') def __repr__(self): return f'<User {self.username}>'
class Post(db.Model): __tablename__ = 'posts' uuid = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(256), index=True) body = db.Column(db.Text) author_id = db.Column(db.Integer, db.ForeignKey('users.uuid')) def __repr__(self): return f'<Post {self.title}>'
class StreamedAggregatePostCount(db.Model): id: int time: int next_time: int sum: int source: str __tablename__ = "streamed_post_counts" __bind_key__ = "aggregate" id = db.Column(db.Integer, primary_key=True) time = db.Column(db.Integer) next_time = db.Column(db.Integer) sum = db.Column(db.Integer) source = db.Column(db.String)
class Order(db.Model): __tablename__ = "orders" id = db.Column(db.Integer, primary_key=True) product = db.Column(db.String(100), nullable=False) customer = db.Column(db.String(100), nullable=False) status = db.Column(db.String(100), nullable=False) date_placed = db.Column(DATETIMEOFFSET, nullable=False) date_processed = db.Column(DATETIMEOFFSET, nullable=True) download = db.Column(db.LargeBinary, nullable=True) def __init__(self, product, customer, date_placed, date_processed, download): self.product = product self.customer = customer self.date_placed = date_placed self.date_processed = date_processed self.status = 'Complete' if self.date_processed else 'Queued' self.download = download def __repr__(self): return f"<Order {self.id}: {self.product}, {self.customer}, {self.date_placed}, {self.date_processed} >" @property def date_placed_local(self): return self.date_placed.astimezone(local_timezone) @property def date_processed_local(self): return self.date_processed.astimezone(local_timezone) def set_as_processed(self): self.date_processed = datetime.now(tz=utc) self.status = COMPLETE
class AggregatePostImpact(db.Model): id: int time: int next_time: int sum: float avg: float source: str __tablename__ = "post_impacts" __bind_key__ = "aggregate" id = db.Column(db.Integer, primary_key=True) time = db.Column(db.Integer) next_time = db.Column(db.Integer) sum = db.Column(db.Float) avg = db.Column(db.Float) source = db.Column(db.String)
class Plant(db.Model): id = db.Column(db.Integer, primary_key=True) greenhouse_id = db.Column(db.Integer(), index=True) name = db.Column(db.String(128), index=True) color = db.Column(db.String(128), index=True)