asyncpg-trek


Nameasyncpg-trek JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/adriangb/asyncpg-trek
SummaryA simple migrations system for asyncpg
upload_time2022-12-23 09:10:13
maintainer
docs_urlNone
authorAdrian Garcia Badaracco
requires_python>=3.7,<4
licenseMIT
keywords asyncpg postgres postgresql migrations
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # asyncpg-trek: simple migrations for asyncpg

A simple library for managing migrations.

## Target audience

Me.
But maybe if you use [asyncpg] and prefer to write migrations as raw SQL (i.e. you're not using SQLAlchemy/Alembic) then you as well.

## Features

- **async**: migrations usually don't benefit from being async, but you benefit from using the same database driver in as your application uses (only [asyncpg] is supported).
- **simple**: you just create `.sql` or Python files in a folder of your choosing and point this tool at that folder. No need to fight a new API to write migrations in.
- **API centric**: there is no CLI to figure out, _you_ decide how migrations get called, _you_ control how the database connection gets created. This makes it trivial to run migrations in tests, wrap them in a CLI or run them via an exposed HTTP endpoint.
- **declarative**: just specify the version you want and the library figures out if it needs an upgrade, downgrade or no action.

## Example usage

```python
from pathlib import Path

import asyncpg
from asyncpg_trek import plan, execute, Direction
from asyncpg_trek.asyncpg import AsyncpgBackend

MIGRATIONS_DIR = Path(__file__).parent / "migrations"

async def migrate(
    conn: asyncpg.Connection,
    target_revision: str,
) -> None:
    backend = AsyncpgBackend(conn)
    async with backend.connect() as conn:
        planned = await plan(conn, backend, MIGRATIONS_DIR, target_revision=target_revision, direction=Direction.up)
        await execute(conn, backend, planned)
```

You could make this an entrypoint in a docker image, an admin endpoint in your API or a helper function in your tests (or all of the above).
How you run your migrations depends on the complexity of your system.
For example, for simple systems it may be easy to run migrations on app startup based on a hardcoded revision.
For more complex systems you may want to run migrations manually or via an admin API.

See this release on GitHub: [v0.3.0](https://github.com/adriangb/asyncpg-trek/releases/tag/0.3.0)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/adriangb/asyncpg-trek",
    "name": "asyncpg-trek",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4",
    "maintainer_email": "",
    "keywords": "asyncpg,postgres,postgresql,migrations",
    "author": "Adrian Garcia Badaracco",
    "author_email": "adrian@adriangb.com",
    "download_url": "https://files.pythonhosted.org/packages/69/f7/ced4ac9c1a2f84879bc32c9a7167285c328734f32310ad869ca8ace45779/asyncpg_trek-0.3.0.tar.gz",
    "platform": null,
    "description": "# asyncpg-trek: simple migrations for asyncpg\n\nA simple library for managing migrations.\n\n## Target audience\n\nMe.\nBut maybe if you use [asyncpg] and prefer to write migrations as raw SQL (i.e. you're not using SQLAlchemy/Alembic) then you as well.\n\n## Features\n\n- **async**: migrations usually don't benefit from being async, but you benefit from using the same database driver in as your application uses (only [asyncpg] is supported).\n- **simple**: you just create `.sql` or Python files in a folder of your choosing and point this tool at that folder. No need to fight a new API to write migrations in.\n- **API centric**: there is no CLI to figure out, _you_ decide how migrations get called, _you_ control how the database connection gets created. This makes it trivial to run migrations in tests, wrap them in a CLI or run them via an exposed HTTP endpoint.\n- **declarative**: just specify the version you want and the library figures out if it needs an upgrade, downgrade or no action.\n\n## Example usage\n\n```python\nfrom pathlib import Path\n\nimport asyncpg\nfrom asyncpg_trek import plan, execute, Direction\nfrom asyncpg_trek.asyncpg import AsyncpgBackend\n\nMIGRATIONS_DIR = Path(__file__).parent / \"migrations\"\n\nasync def migrate(\n    conn: asyncpg.Connection,\n    target_revision: str,\n) -> None:\n    backend = AsyncpgBackend(conn)\n    async with backend.connect() as conn:\n        planned = await plan(conn, backend, MIGRATIONS_DIR, target_revision=target_revision, direction=Direction.up)\n        await execute(conn, backend, planned)\n```\n\nYou could make this an entrypoint in a docker image, an admin endpoint in your API or a helper function in your tests (or all of the above).\nHow you run your migrations depends on the complexity of your system.\nFor example, for simple systems it may be easy to run migrations on app startup based on a hardcoded revision.\nFor more complex systems you may want to run migrations manually or via an admin API.\n\nSee this release on GitHub: [v0.3.0](https://github.com/adriangb/asyncpg-trek/releases/tag/0.3.0)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple migrations system for asyncpg",
    "version": "0.3.0",
    "split_keywords": [
        "asyncpg",
        "postgres",
        "postgresql",
        "migrations"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "9cdef0e32d83f202eb9865ac7ce7c7ec",
                "sha256": "a21449063f8efaf6c15c8efc995b4ed19820b7f5dd195a5fb4c0d9488d65e650"
            },
            "downloads": -1,
            "filename": "asyncpg_trek-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9cdef0e32d83f202eb9865ac7ce7c7ec",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4",
            "size": 8485,
            "upload_time": "2022-12-23T09:10:12",
            "upload_time_iso_8601": "2022-12-23T09:10:12.575032Z",
            "url": "https://files.pythonhosted.org/packages/6e/34/58c68adad19a8a113a300a87875218211b557fa0d1bd685ad4fc02f59d64/asyncpg_trek-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "7da408a1f554e44033692ba66ad5b3cc",
                "sha256": "3500a865173e892b7a9d368ca0768b34f6465591e7a887d29202e147697ff9d1"
            },
            "downloads": -1,
            "filename": "asyncpg_trek-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7da408a1f554e44033692ba66ad5b3cc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4",
            "size": 7789,
            "upload_time": "2022-12-23T09:10:13",
            "upload_time_iso_8601": "2022-12-23T09:10:13.814047Z",
            "url": "https://files.pythonhosted.org/packages/69/f7/ced4ac9c1a2f84879bc32c9a7167285c328734f32310ad869ca8ace45779/asyncpg_trek-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-23 09:10:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "adriangb",
    "github_project": "asyncpg-trek",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "asyncpg-trek"
}
        
Elapsed time: 0.02047s