Fix: adds and invokes Neo4jAdapter initialize for schema setup (#933)

<!-- .github/pull_request_template.md -->

## Description
adds and invokes Neo4jAdapter initialize for schema setup

## DCO Affirmation
I affirm that all code in every commit of this pull request conforms to
the terms of the Topoteretes Developer Certificate of Origin.
This commit is contained in:
hajdul88 2025-06-09 13:40:30 +02:00 committed by GitHub
parent 84c7aeb1a5
commit 82c0279f45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View file

@ -16,6 +16,11 @@ async def get_graph_engine() -> GraphDBInterface:
# Async functions can't be cached. After creating and caching the graph engine
# handle all necessary async operations for different graph types bellow.
# Run any adapterspecific async initialization
if hasattr(graph_client, "initialize"):
await graph_client.initialize()
# Handle loading of graph for NetworkX
if config["graph_database_provider"].lower() == "networkx" and graph_client.graph is None:
await graph_client.load_graph_from_file()

View file

@ -1,5 +1,3 @@
#
"""Neo4j Adapter for Graph Database"""
import json
@ -52,8 +50,12 @@ class Neo4jAdapter(GraphDBInterface):
max_connection_lifetime=120,
notifications_min_severity="OFF",
)
# Create contraint/index
self.query(
async def initialize(self) -> None:
"""
Initializes the database: adds uniqueness constraint on id and performs indexing
"""
await self.query(
(f"CREATE CONSTRAINT IF NOT EXISTS FOR (n:`{BASE_LABEL}`) REQUIRE n.id IS UNIQUE;")
)