Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DZDPythonModules
neo4j-meta-tracker
Commits
9a346546
Commit
9a346546
authored
Apr 12, 2022
by
Tim Bleimehl
🤸🏼
Browse files
fix schema diff vis
parent
26204463
Pipeline
#1649
passed with stage
in 1 minute and 4 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
NeoMetaLogger/graph_scheme.py
View file @
9a346546
...
...
@@ -37,11 +37,14 @@ class GraphSchema(py2neo.Subgraph):
schema_graph
:
GraphSchema
=
cls
()
if
not
parent_capture_point
.
parent_logger
.
all_schema_nodes
:
parent_capture_point
.
parent_logger
.
all_schema_nodes
=
{}
if
not
parent_capture_point
.
parent_logger
.
all_schema_rels
:
parent_capture_point
.
parent_logger
.
all_schema_rels
=
{}
if
not
extra_props
:
extra_props
=
{}
extra_props
=
extra_props
|
{
"__neo_meta_logger_node"
:
True
}
for
rel
in
neo4j_schema_vis_data
[
"relationships"
]:
rel_nodes
=
[
None
,
None
]
for
node
in
neo4j_schema_vis_data
[
"nodes"
]:
if
rel_nodes
[
0
]
and
rel_nodes
[
1
]:
...
...
@@ -58,12 +61,22 @@ class GraphSchema(py2neo.Subgraph):
rel_nodes
[
0
]
=
clean_rel_node
elif
node
.
identity
==
rel
.
end_node
.
identity
:
rel_nodes
[
1
]
=
clean_rel_node
clean_rel
=
py2neo
.
Relationship
(
rel_nodes
[
0
],
type
(
rel
).
__name__
,
rel_nodes
[
1
],
**
extra_props
,
rel_ident
=
(
f
"
{
list
(
rel_nodes
[
0
])[
0
]
}
_
{
type
(
rel
).
__name__
}
_
{
list
(
rel_nodes
[
1
])[
0
]
}
"
)
if
rel_ident
in
parent_capture_point
.
parent_logger
.
all_schema_rels
:
clean_rel
=
parent_capture_point
.
parent_logger
.
all_schema_rels
[
rel_ident
]
else
:
parent_capture_point
.
parent_logger
.
all_schema_rels
[
rel_ident
]
=
clean_rel
=
py2neo
.
Relationship
(
rel_nodes
[
0
],
type
(
rel
).
__name__
,
rel_nodes
[
1
],
**
extra_props
,
)
schema_graph
=
schema_graph
|
clean_rel
# atm we ignored any nodes without any relation.
...
...
NeoMetaLogger/neo_meta_logger.py
View file @
9a346546
...
...
@@ -10,6 +10,7 @@ class NeoMetaLogger:
def
__init__
(
self
,
connection
:
Union
[
py2neo
.
Graph
,
Dict
]):
self
.
capture_points
:
List
[
CapturePoint
]
=
[]
self
.
all_schema_nodes
:
Dict
[
tuple
,
py2neo
.
Node
]
=
None
self
.
all_schema_rels
:
Dict
[
str
,
py2neo
.
Relationship
]
=
None
if
isinstance
(
connection
,
dict
):
self
.
graph
:
py2neo
.
Graph
=
py2neo
.
Graph
(
**
connection
)
elif
isinstance
(
connection
,
py2neo
.
Graph
):
...
...
@@ -105,7 +106,7 @@ class NeoMetaLogger:
# hardcoded class name in subgraph. we need to workaround this. can be removed with https://github.com/py2neo-org/py2neo/issues/940 merged
# original line: return from_capture.schema - to_capture.schema
# workaround:
sb
:
py2neo
.
Subgraph
=
from
_capture
.
schema
-
to
_capture
.
schema
sb
:
py2neo
.
Subgraph
=
to
_capture
.
schema
-
from
_capture
.
schema
return
GraphSchema
(
nodes
=
sb
.
nodes
,
relationships
=
sb
.
relationships
)
def
get_numeric_last_changes
(
self
)
->
Dict
[
str
,
Dict
[
str
,
int
]]:
...
...
NeoMetaLogger/visualizer/graphiz_visualizer.py
View file @
9a346546
...
...
@@ -27,14 +27,16 @@ class GraphvizVisualizer(BaseVisualizer):
py2neo_subgraph
:
Subgraph
,
)
->
pgv
.
AGraph
:
# https://pygraphviz.github.io/documentation/stable/tutorial.html#graphs
graph
:
pgv
.
AGraph
=
pgv
.
AGraph
(
strict
=
False
,
directed
=
True
)
graph
:
pgv
.
AGraph
=
pgv
.
AGraph
(
strict
=
False
,
directed
=
True
,
landscape
=
False
)
for
node
in
py2neo_subgraph
.
nodes
:
graph
.
add_node
(
node
[
"__label_name"
],
**
dict
(
node
))
for
rel
in
py2neo_subgraph
.
relationships
:
graph
.
add_edge
(
rel
.
start_node
[
"__label_name"
],
rel
.
end_node
[
"__label_name"
],
key
=
type
(
rel
).
__name__
,
**
dict
(
rel
),
fontsize
=
8
,
minlen
=
2
,
# key=type(rel).__name__,
label
=
type
(
rel
).
__name__
,
)
return
graph
tests/smoketest.py
View file @
9a346546
...
...
@@ -18,12 +18,13 @@ from NeoMetaLogger.visualizer import GraphvizVisualizer
NEO4J
:
Dict
=
json
.
loads
(
os
.
getenv
(
"NEO4J"
,
"{}"
))
wait_for_db_boot
(
NEO4J
)
graph
=
py2neo
.
Graph
(
**
NEO4J
)
graph
.
run
(
"CREATE OR REPLACE DATABASE schematest"
)
graph
.
run
(
"CREATE OR REPLACE DATABASE test"
)
#
test_graph = py2neo.Graph(**(NEO4J | {"name": "test"}))
test_graph
=
py2neo
.
Graph
(
**
(
NEO4J
))
test_graph
=
py2neo
.
Graph
(
**
(
NEO4J
|
{
"name"
:
"test"
}))
#
test_graph = py2neo.Graph(**(NEO4J))
mlog
=
NeoMetaLogger
(
test_graph
)
test_graph
.
run
(
"CREATE p = (:Human{name:'Amina Okujewa'})-[:LIVES_ON]->(:World {name: 'Earth'})"
...
...
@@ -39,12 +40,17 @@ test_graph.run(
"MATCH (wI:World{name:'Internet'}),(wE:World{name:'Earth'}) CREATE (as:Human{name:'Aaron Swartz'})-[:LIVES_ON]->(wI), (as)-[:LIVES_ON]->(wE)"
)
mlog
.
capture
()
print
(
mlog
.
get_numeric_last_changes
())
print
(
mlog
.
get_schemagraph_last_changes
())
print
(
"##########"
)
print
(
mlog
.
capture_points
[
-
1
].
schema
.
visualize
(
GraphvizVisualizer
))
print
(
"##########2"
)
test_graph
.
run
(
"CREATE (wH:World{name:'House'})"
)
test_graph
.
run
(
"MATCH (wH:World{name:'House'}),(wE:World{name:'Earth'}) CREATE (wH)-[:EXISTS_ON]->(wE)"
)
mlog
.
capture
()
print
(
"###get_numeric_last_changes###
\n
"
,
mlog
.
get_numeric_last_changes
())
print
(
"###get_schemagraph_last_changes###
\n
"
,
mlog
.
get_schemagraph_last_changes
())
print
(
"###schema.visualize(GraphvizVisualizer)###
\n
"
,
mlog
.
capture_points
[
-
1
].
schema
.
visualize
(
GraphvizVisualizer
),
)
print
(
mlog
.
get_schemagraph_last_changes
().
visualize
(
GraphvizVisualizer
,
to_file
=
"file.dot"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment