{"id":26985604,"url":"https://github.com/fredimatteo/migropy","last_synced_at":"2025-04-03T18:30:09.223Z","repository":{"id":283844326,"uuid":"951371881","full_name":"fredimatteo/migropy","owner":"fredimatteo","description":"Lightweight and extensible Python library for managing database migrations","archived":false,"fork":false,"pushed_at":"2025-03-27T17:55:58.000Z","size":83,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T18:48:19.525Z","etag":null,"topics":["migration","postgresql","python3","sql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fredimatteo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2025-03-19T15:17:27.000Z","updated_at":"2025-03-27T17:20:53.000Z","dependencies_parsed_at":"2025-03-27T18:48:32.071Z","dependency_job_id":"188e084e-2625-44ac-b350-773d58cabb52","html_url":"https://github.com/fredimatteo/migropy","commit_stats":null,"previous_names":["fredimatteo/migratron","fredimatteo/migropy"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredimatteo%2Fmigropy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredimatteo%2Fmigropy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredimatteo%2Fmigropy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredimatteo%2Fmigropy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fredimatteo","download_url":"https://codeload.github.com/fredimatteo/migropy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247056078,"owners_count":20876327,"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":["migration","postgresql","python3","sql"],"created_at":"2025-04-03T18:30:08.715Z","updated_at":"2025-04-03T18:30:09.202Z","avatar_url":"https://github.com/fredimatteo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Python versions](https://img.shields.io/pypi/pyversions/migropy?style=flat-square\u0026logo=python\u0026logoColor=white\u0026color)\n![Test](https://img.shields.io/github/actions/workflow/status/fredimatteo/migratron/test.yml?style=flat-square\u0026logo=github\u0026logoColor=white\u0026color\u0026label=Test)\n![Pepy Total Downloads](https://img.shields.io/pepy/dt/migropy?style=flat-square\u0026logo=pypi\u0026logoColor=white\u0026color)\n\n# 🛠️ Migropy\n\n**Migropy** is a lightweight and extensible Python library for managing **database migrations**.  \nDesigned for simplicity and flexibility, it helps teams apply, track, and version-control schema changes across multiple\nenvironments.\n\n---\n\n## 📚 Table of Contents\n\n- [🚀 Features](#-features)\n- [📦 Installation](#-installation)\n- [📖 How to use - CLI](#-how-to-use---cli)\n  - [1. Initialize a new migration project](#1-initialize-a-new-migration-project)\n  - [2. Go to the migrations directory](#2-go-to-the-migrations-directory)\n  - [3. Fill the config.ini file](#3-fill-the-configini-file)\n  - [4. Create a new migration](#4-create-a-new-migration)\n  - [5. Apply the migrations](#5-apply-the-migrations)\n- [🐍 How to use - Python](#-how-to-use---python)\n- [📄 Migration example](#-migration-example)\n- [⚙️ Available commands](#-available-commands)\n- [🧪 Running Unit Tests](#-running-unit-tests)\n- [📝 Changelog](#-changelog)\n- [🤝 Contributing](#-contributing)\n- [📫 Support](#-support)\n- [📄 License](#-license)\n\n\n---\n\n## 🚀 Features\n\n- ✅ Versioned migrations with up/down support\n- ✅ Compatible with PostgreSQL \u0026 MySQL\n- ✅ CLI for common migration operations\n- ✅ Safe and idempotent execution\n- ✅ Customizable migration directory structure\n\n---\n\n## 📦 Installation\n\n```bash\npip install migropy\n```\n\n---\n\n## 📖 How to use - CLI\n\n### 1. Initialize a new migration project\n\nThis command will create a new directory called `migropy` with the necessary files to manage your migrations \u0026 db\nparameters.\n```bash\nmigropy init\n```\n\n### 2. Go to the migrations directory\n\n```bash\ncd migropy\n```\n\n### 3. Fill the config.ini file\n\n```ini\n[database]\n# database connection parameters\n# available types: postgres, mysql\nhost = localhost\nport = 5432\nuser = postgres\npassword = postgres\ndbname = my_database\ntype = postgres # or mysql\n\n[migrations]\n# path to migration scripts\n# use forward slashes (/) also on windows to provide an os agnostic path\nscript_location = migropy\n\n[logger]\n# available levels: DEBUG, INFO, WARNING, ERROR, CRITICAL\nlevel = DEBUG\n```\n\n### 4. Create a new migration\n\nThis command will create a new migration file in the `migropy/versions` directory with the following template:\n\n```bash\nmigropy generate 'migration name'\n```\n\n```sql\n-- Up migration\n\n-- Down migration\n```\n\n### 5. Apply the migrations\n\nThis command will apply all the migrations in the `migrations` directory. Please note the migrations are applied in\nthe prefix order.\n```bash\nmigropy upgrade\n```\n\n---\n\n## 🐍 How to use - Python\n\nYou can also use **Migropy** as a library in your Python code. Here is an example of how to use it:\n\n```python\n# Importing the function to load the migration configuration\nfrom migropy.configuration_parser import load_config\n\n# Importing the Postgres database adapter\nfrom migropy.databases.postgres import Postgres\n\n# Importing the common database configuration structure\nfrom migropy.databases.commons import DbConfig\n\n# Importing the migration engine responsible for applying migrations\nfrom migropy.migration_engine import MigrationEngine\n\n# Create a database configuration object with connection parameters\ndb_config = DbConfig(\n    host=\"localhost\",      # Database server hostname or IP\n    port=5432,             # Default PostgreSQL port\n    user=\"user\",           # Username to connect to the database\n    password=\"password\",   # Password for the given user\n    database=\"test\"        # Name of the target database\n)\n\n# Instantiate a Postgres database connection using the provided configuration\ndb = Postgres(db_config)\n\n# Create a MigrationEngine instance with:\n# - the database connection\n# - the loaded configuration (usually from a file like migropy.ini)\nengine = MigrationEngine(db=db, config=load_config())\n\n# Initialize the migropy environment and create the necessary tables\n# use it just once!!!\nengine.init()\n\n# Generate a new migration revision with a descriptive name\nengine.generate_revision(revision_name='first revision')\n\n# Apply all pending migrations to upgrade the database schema\nengine.upgrade()\n\n```\n\n---\n\n## 📄 Migration example\n\n```sql\n-- Up migration\nCREATE TABLE users\n(\n    id    SERIAL PRIMARY KEY,\n    name  VARCHAR(100) NOT NULL,\n    email VARCHAR(100) NOT NULL\n);\n\n-- Down migration\nDROP TABLE users;\n```\n\n---\n\n## ⚙️ Available commands\n\n| Comando                   | Descrizione                   |\n|---------------------------|-------------------------------|\n| `migropy init`            | Init migratron environment    |\n| `migropy generate \u003cname\u003e` | Generate a new sql migration  |\n| `migropy upgrade`         | Apply all the migration       |\n| `migropy downgrade`       | Rollback all revisions        |\n| `migropy list `           | Show current migration status |\n\n---\n\n## 🧪 Running Unit Tests\n\nTo run the unit tests using poetry, you can use the following command:\n\n```bash\npoetry run pytest --rootdir=tests\n```\n\n---\n\n## 📝 Changelog\n\nSee the full [CHANGELOG.md](https://github.com/fredimatteo/migratron/blob/main/CHANGELOG.md)\n\n### Latest Changes\n\n- **0.2.2** – Commands refactor \u0026 usage from python code\n- **0.2.1** – Increase minimum python version to 3.10 \u0026 refactor MigrationEngine\n- **0.2.0** – MySQL database support\n- **0.1.1** – Initial project setup with PostgreSQL\n\n---\n\n## 🤝 Contributing\n\nWe welcome contributions!  \nTo get started:\n\n1. Fork the repository\n2. Create a new branch (`git checkout -b feature/your-feature`)\n3. Commit your changes\n4. Open a pull request 🚀\n\n---\n\n## 📫 Support\n\nFor issues, feature requests or general questions, open an issue on [GitHub Issues](https://github.com/fredimatteo/migratron/issues).\n\n\n---\n\n## 📄 License\n\nMIT License © 2025 — teoxy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffredimatteo%2Fmigropy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffredimatteo%2Fmigropy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffredimatteo%2Fmigropy/lists"}