Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mx 1524 create db purge script #74

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- db purge script

### Changes

### Deprecated
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ optional-dependencies.dev = [

[project.scripts]
backend = "mex.backend.main:main"
purge-db = "scripts.purge:purge_db"

[tool.cruft]
template = "https://github.com/robert-koch-institut/mex-template"
Expand Down
25 changes: 25 additions & 0 deletions scripts/purge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import click
from neo4j import GraphDatabase

from mex.backend.settings import BackendSettings


def purge_db() -> None:
"""Purge graph db."""
settings = BackendSettings.get()
if click.confirm(f'Purging graph db "{settings.graph_db}", Continue?:'):
click.echo("Purging...")
with GraphDatabase.driver(
settings.graph_url,
auth=(
settings.graph_user.get_secret_value(),
settings.graph_password.get_secret_value(),
),
database=settings.graph_db,
) as driver:
driver.execute_query("MATCH (n) DETACH DELETE n;")
for row in driver.execute_query("SHOW ALL CONSTRAINTS;").records:
driver.execute_query(f"DROP CONSTRAINT {row['name']};")
for row in driver.execute_query("SHOW ALL INDEXES;").records:
driver.execute_query(f"DROP INDEX {row['name']};")
click.echo("Done")