diff --git a/.env.example b/.env.example index aef1722..fb8019c 100644 --- a/.env.example +++ b/.env.example @@ -13,3 +13,7 @@ MYSQL_USER=plant_user MYSQL_PASSWORD=plant_pass MYSQL_ROOT_PASSWORD=supersecret + +NEO4J_URI=bolt://neo4j:7687 +NEO4J_USER=neo4j +NEO4J_PASSWORD=your_secure_password diff --git a/app/config.py b/app/config.py index 4a37c40..aa16cfd 100644 --- a/app/config.py +++ b/app/config.py @@ -24,3 +24,7 @@ class Config: # Optional toggles ENABLE_DB_SEEDING = os.environ.get('ENABLE_DB_SEEDING', '0') == '1' DOCKER_ENV = os.environ.get('FLASK_ENV', 'production') + + NEO4J_URI = os.getenv('NEO4J_URI', 'bolt://neo4j:7687') + NEO4J_USER = os.getenv('NEO4J_USER', 'neo4j') + NEO4J_PASSWORD = os.getenv('NEO4J_PASSWORD', 'your_secure_password') diff --git a/app/neo4j_utils.py b/app/neo4j_utils.py new file mode 100644 index 0000000..defc7c8 --- /dev/null +++ b/app/neo4j_utils.py @@ -0,0 +1,32 @@ + +from neo4j import GraphDatabase +from flask import current_app + +class Neo4jHandler: + def __init__(self, uri, user, password): + self.driver = GraphDatabase.driver(uri, auth=(user, password)) + + def close(self): + self.driver.close() + + def create_plant_node(self, uuid, name): + with self.driver.session() as session: + session.run( + "MERGE (p:Plant {uuid: $uuid}) " + "SET p.name = $name", + uuid=uuid, name=name + ) + + def create_lineage(self, child_uuid, parent_uuid): + with self.driver.session() as session: + session.run( + "MATCH (child:Plant {uuid: $child_uuid}), (parent:Plant {uuid: $parent_uuid}) " + "MERGE (parent)-[:PARENT_OF]->(child)", + child_uuid=child_uuid, parent_uuid=parent_uuid + ) + +def get_neo4j_handler(): + uri = current_app.config['NEO4J_URI'] + user = current_app.config['NEO4J_USER'] + password = current_app.config['NEO4J_PASSWORD'] + return Neo4jHandler(uri, user, password) diff --git a/docker-compose.yml b/docker-compose.yml index b64cabe..b971469 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,5 +54,17 @@ services: depends_on: - db + neo4j: + image: neo4j:5.18 + container_name: nip_neo4j + ports: + - '7474:7474' + - '7687:7687' + environment: + - NEO4J_AUTH=neo4j/your_secure_password + volumes: + - neo4j_data:/data + volumes: plant_price_tracker_mysql_data: + neo4j_data: diff --git a/main.zip b/main.zip index fc737e0..f045fce 100644 Binary files a/main.zip and b/main.zip differ diff --git a/plugins/auth/models.py b/plugins/auth/models.py index c8dfc82..6570644 100644 --- a/plugins/auth/models.py +++ b/plugins/auth/models.py @@ -5,6 +5,7 @@ from app import db class User(db.Model, UserMixin): __tablename__ = 'users' + __table_args__ = {'extend_existing': True} id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(120), unique=True, nullable=False) diff --git a/plugins/core_ui/templates/core_ui/base.html b/plugins/core_ui/templates/core_ui/base.html index f970cd2..7f32fac 100644 --- a/plugins/core_ui/templates/core_ui/base.html +++ b/plugins/core_ui/templates/core_ui/base.html @@ -31,7 +31,7 @@