Skip to content

Refactor graph persistence structure and update CLI command syntax#29

Open
Orio77 wants to merge 2 commits into
Solvro:mainfrom
Orio77:feat/graph-state-snapshot
Open

Refactor graph persistence structure and update CLI command syntax#29
Orio77 wants to merge 2 commits into
Solvro:mainfrom
Orio77:feat/graph-state-snapshot

Conversation

@Orio77

@Orio77 Orio77 commented Apr 29, 2026

Copy link
Copy Markdown
Member

Rozwiązane błędy ścieżek przy zapisie, mała reorganizacja, poprawiony syntax komendy pipeline

This pull request refactors and enhances the Neo4j graph dump and restore functionality in the data pipeline. It moves related code into a new persistence module, improves configuration flexibility, and makes the import/export process more robust and compatible across environments (including Neo4j Desktop and Docker). It also updates documentation and scripts to reflect these changes.

Refactoring and code organization:

  • Moved the graph dump/restore logic from src/data_pipeline/graph_dump.py to a new module src/data_pipeline/persistence/graph_dump.py, and updated all imports and CLI entrypoints accordingly. The CLI code was moved from src/data_pipeline/cli.py to src/data_pipeline/persistence/cli.py. [1] [2] [3]

Improvements to graph dump/restore process:

  • Enhanced import/export logic to better detect and handle file paths for both Neo4j Desktop and Docker setups, including new helpers like _neo4j_import_rel_path, _project_root, and _copy_dump_to_repo_if_needed. Added a check for non-empty dump files before restoring (host_nonempty_dump_exists).
  • Changed the restore process to use apoc.cypher.runMany for better compatibility, and improved error handling for missing APOC procedures.
  • Updated the pipeline and CLI logic to check for non-empty dump files before restoring, preventing attempts to load from missing or placeholder dumps. [1] [2] [3]

Configuration and documentation updates:

  • Updated .env.example with clearer explanations and new options for dump file paths, import directory, and backup locations. [1] [2]
  • Updated documentation and developer scripts (e.g., CLAUDE.md, debugging guides) to use the new prefect-pipeline command and reflect the new module structure. [1] [2]

Testing improvements:

  • Updated tests to use the new host_nonempty_dump_exists helper for mocking dump file existence.

Orio77 added 2 commits April 29, 2026 17:03
…I commands

- Made persistence logic more robust
- Moved graph dump functions to a new persistence module for better structure.
- Updated CLI commands to reflect new module paths.
- Enhanced .env.example with additional comments for clarity on Neo4j import paths.
- Changed 'prefect_pipeline' to 'prefect-pipeline' in multiple documentation files to ensure uniformity in command usage.
@Orio77
Orio77 requested a review from jgilewicz April 29, 2026 15:33
@jgilewicz
jgilewicz requested review from Irahan2 and removed request for jgilewicz May 16, 2026 10:34

@Irahan2 Irahan2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice direction overall. I left a few suggestions.

Comment thread .env.example
# Optional. Path *inside Neo4j’s import folder* for APOC export/import (not your repo path).
# Unset = graph_export.cypher at import root (typical for Neo4j Desktop).
# Docker stack: use dumps/graph_export.cypher so it matches import/dumps -> ../dumps in compose.
# NEO4J_IMPORT_REL_PATH=dumps/graph_export.cypher

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should not stay commented for the Docker setup, or Docker needs a different default. with the current default, the code writes graph_export.cypher to Neo4j import root, but Docker only mounts ../dumps to /var/lib/neo4j/import/dumps. So dump-graph may finish, but the dump will not appear in the repo dumps/ folder. Maybe we should set this in Docker env by default, or make the default path Docker-safe and document the Desktop override.


def _copy_dump_to_repo_if_needed(out: Path, rel: str) -> None:
"""If APOC wrote under Neo4j's import tree, copy the file into the repo ``dumps/`` path."""
if out.is_file():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can leave an old dump in place. If dumps/graph_export.cypher already exists, we return here and never copy the newly exported file from Neo4j's import dir. So after a fresh export, the repo dump can still be stale.

I think we should overwrite/copy after every successful export, or at least compare the source file and timestamp before skipping.



def _import_directory_from_server(session) -> Path | None:
"""Resolve the DBMS import directory (absolute on the server host; same as this machine for Desktop)."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay in here small CI thing: uv run ruff check src fails here and also ı beleive around lines 127 and 194 because these docstrings are over the 100 char limit. Could you wrap these lines so the lint check passes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants