{"id":19615681,"url":"https://github.com/booqoffsky/neo4j-python-migrations","last_synced_at":"2025-04-28T02:31:40.263Z","repository":{"id":63859989,"uuid":"557495297","full_name":"booqoffsky/neo4j-python-migrations","owner":"booqoffsky","description":"A database migration tool for Neo4j that allows to apply Cypher-based and arbitrary Python-based migrations.","archived":false,"fork":false,"pushed_at":"2024-06-07T21:09:16.000Z","size":62,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-09T09:48:36.332Z","etag":null,"topics":["migrations","neo4j","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/booqoffsky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-25T19:45:51.000Z","updated_at":"2024-10-01T23:14:01.000Z","dependencies_parsed_at":"2024-06-06T12:06:43.503Z","dependency_job_id":"6a2c0769-23e7-4a68-9853-36a22758c96c","html_url":"https://github.com/booqoffsky/neo4j-python-migrations","commit_stats":{"total_commits":2,"total_committers":2,"mean_commits":1.0,"dds":0.5,"last_synced_commit":"fb0ddabf6bc077c2b12538471e1f271ea7c08a11"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/booqoffsky%2Fneo4j-python-migrations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/booqoffsky%2Fneo4j-python-migrations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/booqoffsky%2Fneo4j-python-migrations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/booqoffsky%2Fneo4j-python-migrations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/booqoffsky","download_url":"https://codeload.github.com/booqoffsky/neo4j-python-migrations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224091978,"owners_count":17254152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["migrations","neo4j","python"],"created_at":"2024-11-11T10:57:58.049Z","updated_at":"2024-11-11T10:57:58.895Z","avatar_url":"https://github.com/booqoffsky.png","language":"Python","readme":"![python version](https://img.shields.io/pypi/pyversions/neo4j-python-migrations?style=for-the-badge) \n[![version](https://img.shields.io/pypi/v/neo4j-python-migrations?style=for-the-badge)](https://pypi.org/project/neo4j-python-migrations/)\n![Codecov](https://img.shields.io/codecov/c/github/booqoffsky/neo4j-python-migrations?style=for-the-badge\u0026token=CP9ZKK430Z)\n\n# neo4j-python-migrations\n\n\u003e It is a database migration tool for [Neo4j](http://neo4j.com) written in Python\n\u003e that allows to apply not only Cypher migrations, but also arbitrary Python-based migrations.\n\u003e \n\u003e This tool is inspired by [Michael Simons tool for Java](https://github.com/michael-simons/neo4j-migrations)\n\u003e and works directly on [neo4j-python-driver](https://github.com/neo4j/neo4j-python-driver).\n\n# Features\n- Python migration support makes it possible to do any things in your migration that Python allows you to do.\n- Cypher-based migrations support.\n- It can be used either via the command line or directly in your code.\n- Multi-database support for Neo4j Enterprise Edition users.\n- The ability to separate logically independent migration chains within a single database (see the `project` option).\nMay be useful for Neo4j Community Edition users.\n\n# Installation\nFrom PyPi:\n\n`pip3 install neo4j-python-migrations`\n\nIf you want to install it from sources, try this:\n\n```\npython3 -m pip install poetry\npython3 -m pip install .\npython3 -m neo4j_python_migrations \n```\n\n# Usage\n## Creating migrations\n### Naming Convention\nEach migration will be a Cypher or Python file following the format `V\u003csem_ver\u003e__\u003cmigration_name\u003e.ext`.\n\nMake sure to follow the naming convention as stated in \n[Michael's tool documentation](https://michael-simons.github.io/neo4j-migrations/current/#concepts_naming-conventions)\n(except that .py files are allowed).\n\n### Cypher\nJust create a Cypher file with your custom script, for example `./migrations/V0001__initial.cypher`:\n```\nCREATE CONSTRAINT UniqueAuthor IF NOT EXISTS ON (a:AUTHOR) ASSERT a.uuid IS UNIQUE;\nCREATE INDEX author_uuid_index IF NOT EXISTS FOR (a:AUTHOR) ON (a.uuid);\n```\nThis script will be executed within a single transaction.\nTherefore, if you need both DDL and DML commands, split them into different files.\n\n### Python\nPython-based migrations should have a special format, for example `./migrations/V0002__drop_index.py`:\n```\nfrom neo4j import Transaction\n\n\n# This function must be present\ndef up(tx: Transaction):\n    tx.run(\"DROP INDEX author_uuid_index\")\n```\n\n## Applying migrations\n### CLI\nYou can apply migrations or verify the status of migrations using the command line interface:\n```\nUsage: python -m neo4j_python_migrations [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n  --username TEXT                 The login of the user connecting to the\n                                  database.  [env var: NEO4J_MIGRATIONS_USER;\n                                  default: neo4j]\n  --password TEXT                 The password of the user connecting to the\n                                  database.  [env var: NEO4J_MIGRATIONS_PASS;\n                                  default: neo4j]\n  --path PATH                     The path to the directory for scanning\n                                  migration files.  [env var:\n                                  NEO4J_MIGRATIONS_PATH; required]\n  --port INTEGER                  Port for connecting to the database  [env\n                                  var: NEO4J_MIGRATIONS_PORT; default: 7687]\n  --host TEXT                     Host for connecting to the database  [env\n                                  var: NEO4J_MIGRATIONS_HOST; default:\n                                  127.0.0.1]\n  --scheme TEXT                   Scheme for connecting to the database\n                                  [default: neo4j]\n  --project TEXT                  The name of the project for separating\n                                  logically independent migration chains\n                                  within a single database.  [env var:\n                                  NEO4J_MIGRATIONS_PROJECT]\n  --schema-database TEXT          The database that should be used for storing\n                                  information about migrations (Neo4j EE). If\n                                  not specified, then the database that should\n                                  be migrated is used.  [env var:\n                                  NEO4J_MIGRATIONS_SCHEMA_DATABASE]\n  --database TEXT                 The database that should be migrated (Neo4j\n                                  EE)  [env var: NEO4J_MIGRATIONS_DATABASE]\n  --install-completion [bash|zsh|fish|powershell|pwsh]\n                                  Install completion for the specified shell.\n  --show-completion [bash|zsh|fish|powershell|pwsh]\n                                  Show completion for the specified shell, to\n                                  copy it or customize the installation.\n  --help                          Show this message and exit.\n\nCommands:\n  analyze  Analyze migrations, find pending and missed.\n  migrate  Retrieves all pending migrations, verify and applies them.\n```\n\nSo, to apply migrations, just run the command:\n\n`python3 -m neo4j_python_migrations --username neo4j --password test --path ./migrations migrate`\n\n_Note: it is more secure to store the password in the environment variable NEO4J_MIGRATIONS_PASS._\n\n### Python Code\nYou can apply migrations directly into your application:\n\n```\nfrom pathlib import Path\n\nfrom neo4j import GraphDatabase\n\nfrom neo4j_python_migrations.executor import Executor\n\nwith GraphDatabase.driver(\"neo4j://localhost:7687\", auth=(\"neo4j\", \"test\")) as driver:\n    executor = Executor(driver, migrations_path=Path(\"./migrations\"))\n    executor.migrate()\n```\nAvailable methods: `migrate`, `analyze`. \n\n# How migrations are tracked\nInformation about the applied migrations is stored in the database using the schema\ndescribed in [Michael's README](https://michael-simons.github.io/neo4j-migrations/current/#concepts_chain).\n\nSupported migration types: СYPHER, PYTHON. Other types of migrations, such as JAVA, are not supported.\n\nNote: the `project` option are incompatible with this schema. \nWhen using the option, each migration nodes will have an additional property named `project`.\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbooqoffsky%2Fneo4j-python-migrations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbooqoffsky%2Fneo4j-python-migrations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbooqoffsky%2Fneo4j-python-migrations/lists"}