Skip to main content

Lightweight Liquibase-style XML changelog executor for Neo4j/MDB updates

Project description

mdb-changelog-runner

Lightweight Python execution for Liquibase-style Neo4j/MDB changelog XML.

This package parses ordered <changeSet> entries and executes their <neo4j:cypher> queries in a single Neo4j transaction. It does not require Java, the JDK, Liquibase, or the Liquibase Neo4j extension at runtime.

Install

uv add mdb-changelog-runner

For local development:

uv sync
uv run pytest

XML format

Existing Liquibase Neo4j changelogs are supported:

<databaseChangeLog
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
  xmlns:neo4j="http://www.liquibase.org/xml/ns/dbchangelog-ext"
  xmlns:mdb="https://cbiit.github.io/mdb/changelog">
  <changeSet id="1" author="MDB-runner">
    <neo4j:cypher>CREATE (n:test {handle:'TEST'})</neo4j:cypher>
  </changeSet>
</databaseChangeLog>

Parameterized Cypher can use MDB JSON params:

<changeSet id="2" author="MDB-runner">
  <neo4j:cypher>
    MERGE (n:term {handle: $handle, value: $value})
  </neo4j:cypher>
  <mdb:params>{"handle": "C123", "value": "Example"}</mdb:params>
</changeSet>

Usage

import logging

from neo4j import GraphDatabase
from mdb_changelog_runner import ChangelogExecutor

driver = GraphDatabase.driver(uri, auth=(user, password))
logger = logging.getLogger("mdb_changelog_runner")

executor = ChangelogExecutor(driver, logger=logger)
result = executor.execute(
    "local_changelog.xml",
    "s3://my-bucket/model_changelogs/CTDC/local_changelog.xml",
    # Optional changelog_scope
    changelog_scope="model",
    # Optional changelog_scope_path
    changelog_scope_path="model_changelogs/CTDC",
    # Optional schema_mode=True for schema-only changelogs
)

print(result.changesets_executed)

execute() opens a session when given a Neo4j driver. It can also accept an already-open session-like object that provides begin_transaction().

Behavior

  • Each <changeSet> must have an id, author, and <neo4j:cypher> element.
  • Changesets run in XML order.
  • All changesets run inside one transaction unless schema_mode=True is used.
  • In schema mode, each changeSet is committed separately.
  • After all changesets succeed, one _changelog metadata node is written. In single-transaction mode it is written in the same transaction; in schema mode it is written in a final transaction. It records the run timestamp, changelog S3 location, optional scope values, number of executed changesets, unique authors, and a deprecate_after timestamp.
  • The new _changelog node links to the previous matching run with :prev_changelog. Matching uses scope values when provided, otherwise location.
  • Empty changelogs do not write _changelog metadata.
  • If any changeset fails, the transaction is rolled back and ChangelogExecutionError is raised. No metadata is written for failed runs.
  • dry_run=True parses the changelog and returns a summary without executing Cypher.
  • By default, deprecate_after is 6 months after the run timestamp. Pass a datetime.timedelta as ChangelogExecutor(..., deprecate_after=...) to override it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdb_changelog_runner-1.0.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdb_changelog_runner-1.0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file mdb_changelog_runner-1.0.1.tar.gz.

File metadata

  • Download URL: mdb_changelog_runner-1.0.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mdb_changelog_runner-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0376df9514874fcb50579fef4f7f188b3a31b1eabe06664687ebe8a069733f52
MD5 8035edd183c9bdd08711c5e670a39d7a
BLAKE2b-256 b87eb99e2b6b035309fc61743b518cb4809da1c5a46f25b4b9856460bfee2ff1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdb_changelog_runner-1.0.1.tar.gz:

Publisher: publish.yml on CBIIT/MDB-Changelog-Runner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mdb_changelog_runner-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mdb_changelog_runner-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e20c5ba13ad8251b782c0739c05d5a60f8a51f7eff09753e7a8bed5ad154e352
MD5 5819a5f1b6c6d5eb4756794c213702f3
BLAKE2b-256 1e95d1758e017f911435ff8136f892f0b05ab619e2255e7009c70f0267935170

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdb_changelog_runner-1.0.1-py3-none-any.whl:

Publisher: publish.yml on CBIIT/MDB-Changelog-Runner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page