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:
parent
84c7aeb1a5
commit
82c0279f45
2 changed files with 11 additions and 4 deletions
|
|
@ -16,6 +16,11 @@ async def get_graph_engine() -> GraphDBInterface:
|
||||||
|
|
||||||
# Async functions can't be cached. After creating and caching the graph engine
|
# Async functions can't be cached. After creating and caching the graph engine
|
||||||
# handle all necessary async operations for different graph types bellow.
|
# handle all necessary async operations for different graph types bellow.
|
||||||
|
|
||||||
|
# Run any adapter‐specific async initialization
|
||||||
|
if hasattr(graph_client, "initialize"):
|
||||||
|
await graph_client.initialize()
|
||||||
|
|
||||||
# Handle loading of graph for NetworkX
|
# Handle loading of graph for NetworkX
|
||||||
if config["graph_database_provider"].lower() == "networkx" and graph_client.graph is None:
|
if config["graph_database_provider"].lower() == "networkx" and graph_client.graph is None:
|
||||||
await graph_client.load_graph_from_file()
|
await graph_client.load_graph_from_file()
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
#
|
|
||||||
|
|
||||||
"""Neo4j Adapter for Graph Database"""
|
"""Neo4j Adapter for Graph Database"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
@ -52,8 +50,12 @@ class Neo4jAdapter(GraphDBInterface):
|
||||||
max_connection_lifetime=120,
|
max_connection_lifetime=120,
|
||||||
notifications_min_severity="OFF",
|
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;")
|
(f"CREATE CONSTRAINT IF NOT EXISTS FOR (n:`{BASE_LABEL}`) REQUIRE n.id IS UNIQUE;")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue