broke currently

This commit is contained in:
2025-06-22 16:11:29 -05:00
parent e7a0f5b1be
commit 2bb7a29141
77 changed files with 1748 additions and 2298 deletions

View File

@ -1,30 +1,90 @@
from datetime import datetime
from app import db
from plugins.plant.models import Plant
class GrowLog(db.Model):
__tablename__ = 'grow_logs'
__table_args__ = {'extend_existing': True}
__tablename__ = "grow_logs"
__table_args__ = {"extend_existing": True}
id = db.Column(db.Integer, primary_key=True)
plant_id = db.Column(db.Integer, db.ForeignKey('plant.id'), nullable=False)
title = db.Column(db.String(255), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
id = db.Column(db.Integer, primary_key=True)
plant_id = db.Column(db.Integer, db.ForeignKey("plant.id"), nullable=False)
title = db.Column(db.String(255), nullable=True)
notes = db.Column(db.Text, nullable=True)
is_public = db.Column(db.Boolean, default=False, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
updated_at = db.Column(
db.DateTime,
default=datetime.utcnow,
onupdate=datetime.utcnow,
nullable=False
)
updates = db.relationship('PlantUpdate', backref='grow_log', lazy=True)
# ↔ images uploaded directly to this GrowLog
media_items = db.relationship(
"plugins.media.models.Media",
back_populates="growlog",
foreign_keys="plugins.media.models.Media.growlog_id",
lazy="dynamic",
cascade="all, delete-orphan",
)
# ↔ child updates
updates = db.relationship(
"plugins.growlog.models.PlantUpdate",
back_populates="growlog",
foreign_keys="plugins.growlog.models.PlantUpdate.growlog_id",
lazy="dynamic",
cascade="all, delete-orphan",
)
class PlantUpdate(db.Model):
__tablename__ = 'plant_updates'
__table_args__ = {'extend_existing': True}
__tablename__ = "plant_updates"
__table_args__ = {"extend_existing": True}
id = db.Column(db.Integer, primary_key=True)
plant_id = db.Column(db.Integer, db.ForeignKey('plant.id'), nullable=False)
growlog_id = db.Column(db.Integer, db.ForeignKey('grow_logs.id'), nullable=True)
update_type = db.Column(db.String(50), nullable=False)
description = db.Column(db.Text, nullable=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
id = db.Column(db.Integer, primary_key=True)
growlog_id = db.Column(db.Integer, db.ForeignKey("grow_logs.id"), nullable=False)
description = db.Column(db.Text, nullable=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
# Link to Media.update_id (must match the FK defined there)
media_items = db.relationship('Media', back_populates='update', lazy=True)
# ↔ parent GrowLog.updates
growlog = db.relationship(
"plugins.growlog.models.GrowLog",
back_populates="updates",
foreign_keys=[growlog_id],
lazy="joined",
)
# ↔ images attached via UpdateImage join table
media_items = db.relationship(
"plugins.growlog.models.UpdateImage",
back_populates="update",
foreign_keys="plugins.growlog.models.UpdateImage.update_id",
lazy="dynamic",
cascade="all, delete-orphan",
)
class UpdateImage(db.Model):
__tablename__ = "update_images"
__table_args__ = {"extend_existing": True}
id = db.Column(db.Integer, primary_key=True)
update_id = db.Column(db.Integer, db.ForeignKey("plant_updates.id"), nullable=False)
media_id = db.Column(db.Integer, db.ForeignKey("media.id"), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
# ↔ PlantUpdate.media_items
update = db.relationship(
"plugins.growlog.models.PlantUpdate",
back_populates="media_items",
foreign_keys=[update_id],
lazy="joined",
)
# ↔ the actual Media record
media = db.relationship(
"plugins.media.models.Media",
backref=db.backref("update_images", lazy="dynamic"),
foreign_keys=[media_id],
lazy="joined",
)