tons of fun

This commit is contained in:
2025-06-04 01:40:12 -05:00
parent e8acd6bb20
commit c885ede8af
18 changed files with 206 additions and 209 deletions

View File

@ -1,59 +1,84 @@
from flask_sqlalchemy import SQLAlchemy
import uuid as uuid_lib
from datetime import datetime
from app import db
from plugins.search.models import Tag, plant_tags
from plugins.growlog.models import PlantUpdate
class PlantCommonName(db.Model):
__tablename__ = 'plants_common'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(120), unique=True, nullable=False)
# Association table for tags
plant_tags = db.Table(
'plant_tags',
db.metadata,
db.Column('plant_id', db.Integer, db.ForeignKey('plant.id'), primary_key=True),
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True),
extend_existing=True
)
class PlantScientificName(db.Model):
__tablename__ = 'plants_scientific'
class Tag(db.Model):
__tablename__ = 'tag'
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), unique=True, nullable=False)
class PlantCommonName(db.Model):
__tablename__ = 'plant_common_name'
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), unique=True, nullable=False)
class PlantScientificName(db.Model):
__tablename__ = 'plant_scientific_name'
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), unique=True, nullable=False)
common_id = db.Column(db.Integer, db.ForeignKey('plant_common_name.id'), nullable=False)
class PlantLineage(db.Model):
__tablename__ = 'plant_lineage'
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
parent_plant_id = db.Column(db.Integer, db.ForeignKey('plants.id'), nullable=False)
child_plant_id = db.Column(db.Integer, db.ForeignKey('plants.id'), nullable=False)
child_plant_id = db.Column(db.Integer, db.ForeignKey('plant.id'), nullable=False)
parent_plant_id = db.Column(db.Integer, db.ForeignKey('plant.id'), nullable=False)
type = db.Column(db.String(50), nullable=False) # cutting, seed, division
class PlantOwnershipLog(db.Model):
__tablename__ = 'plant_ownership_log'
id = db.Column(db.Integer, primary_key=True)
plant_id = db.Column(db.Integer, db.ForeignKey('plants.id'), nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
date_acquired = db.Column(db.DateTime, default=datetime.utcnow)
date_relinquished = db.Column(db.DateTime, nullable=True)
class Plant(db.Model):
__tablename__ = 'plants'
id = db.Column(db.Integer, primary_key=True)
common_name_id = db.Column(db.Integer, db.ForeignKey('plants_common.id'))
scientific_name_id = db.Column(db.Integer, db.ForeignKey('plants_scientific.id'))
parent_id = db.Column(db.Integer, db.ForeignKey('plants.id'), nullable=True)
is_dead = db.Column(db.Boolean, default=False)
date_added = db.Column(db.DateTime, default=datetime.utcnow)
created_by_user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
__table_args__ = {'extend_existing': True}
class Plant(db.Model):
id = db.Column(db.Integer, primary_key=True)
uuid = db.Column(db.String(36), unique=True, nullable=False, default=lambda: str(uuid4()))
mother_uuid = db.Column(db.String(36), nullable=True) # Optional parent reference
name_id = db.Column(db.Integer, db.ForeignKey("plant_common_name.id"), nullable=True)
scientific_name_id = db.Column(db.Integer, db.ForeignKey("plant_scientific_name.id"), nullable=True)
plant_type = db.Column(db.String(50), nullable=False)
status = db.Column(db.String(50), nullable=False)
notes = db.Column(db.Text)
plant_id = db.Column(db.Integer, db.ForeignKey('plant.id'), nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
start_time = db.Column(db.DateTime, nullable=False)
end_time = db.Column(db.DateTime, nullable=True)
transfer_note = db.Column(db.Text, nullable=True)
class Plant(db.Model):
__tablename__ = 'plant'
__table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True)
uuid = db.Column(db.String(36), default=lambda: str(uuid_lib.uuid4()), unique=True, nullable=False)
custom_slug = db.Column(db.String(255), unique=True, nullable=True)
owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
common_id = db.Column(db.Integer, db.ForeignKey('plant_common_name.id'), nullable=False)
scientific_id = db.Column(db.Integer, db.ForeignKey('plant_scientific_name.id'), nullable=False)
plant_type = db.Column(db.String(50), nullable=False)
status = db.Column(db.String(50), nullable=False, default='active')
notes = db.Column(db.Text, nullable=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
transferred = db.Column(db.Boolean, default=False)
graph_node_id = db.Column(db.String(255), nullable=True)
# Relationships
updates = db.relationship('PlantUpdate', backref='growlog', lazy=True)
lineage = db.relationship('PlantLineage', backref='child', lazy=True, foreign_keys='PlantLineage.child_plant_id')
tags = db.relationship('Tag', secondary=plant_tags, backref='plants')
# → relationships so we can pull in the actual names:
common_name = db.relationship(
'PlantCommonName',
backref=db.backref('plants', lazy='dynamic'),
@ -63,4 +88,7 @@ class Plant(db.Model):
'PlantScientificName',
backref=db.backref('plants', lazy='dynamic'),
lazy=True
)
)
PlantCommon = PlantCommonName
PlantScientific = PlantScientificName