# Pogo migrate - asyncpg migration tooling
[![image](https://img.shields.io/pypi/v/pogo_migrate.svg)](https://pypi.org/project/pogo_migrate/)
[![image](https://img.shields.io/pypi/l/pogo_migrate.svg)](https://pypi.org/project/pogo_migrate/)
[![image](https://img.shields.io/pypi/pyversions/pogo_migrate.svg)](https://pypi.org/project/pogo_migrate/)
![style](https://github.com/NRWLDev/pogo-migrate/actions/workflows/style.yml/badge.svg)
![tests](https://github.com/NRWLDev/pogo-migrate/actions/workflows/tests.yml/badge.svg)
[![codecov](https://codecov.io/gh/NRWLDev/pogo-migrate/branch/main/graph/badge.svg)](https://codecov.io/gh/NRWLDev/pogo-migrate)
`pogo-migrate` assists with maintaining your database schema (and data if
required) as it evolves. Pogo supports migrations written in raw sql, as well
as python files (useful when data needs to be migrated).
A migration can be as simple as:
```sql
-- a descriptive message
-- depends: 20210101_01_abcdef-previous-migration
-- migrate: apply
CREATE TABLE foo (id INT, bar VARCHAR(20), PRIMARY KEY (id));
-- migrate: rollback
DROP TABLE foo;
```
Pogo manages these migration scripts and provides command line tools to apply,
rollback and show migration history.
## Configuration
Add pogo to pyproject.toml
```toml
[tool.pogo]
migrations_location = "./migrations"
database_config = "{POSTGRES_DSN}"
```
If you have an existing environment with separate configuration values for
postgres, you can build the DSN in config.
```toml
[tool.pogo]
migrations_location = "./migrations"
database_config = "postgres://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}:{POSTGRES_PORT}/{PORTGRES_DATABASE}"
```
## New migrations
To create a new migration use `pogo new`. This will template out the migration
file and open the file in your configured text editor (`vi` by default).
Supported flags:
- `--sql` generate a sql migration (defaults to `.py`)
- `--no-interactive` skip the editor step and just write the migration template
to the migrations directory.
```bash
$ pogo new -m "a descriptive message"
```
## Testing
To assist in testing, `pogo-migrate` provides the `pogo_migrate.testing`
module. The apply/rollback methods in the testing module will pick up your
configuration and connect to the configured test database based on environment
variables, or you can provide a database connection directly.
```python
import asyncpg
import pogo_migrate.testing
@pytest.fixture(scope="session")
async def _engine(config): # noqa: PT005
db = await asyncpg.connect(config.my_postgres_dsn)
await pogo_migrate.testing.apply(db)
yield
await pogo_migrate.testing.rollback(db)
```
Alternatively add `pytest-pogo` to your test dependencies and use the provided
fixture `pogo_engine` which will apply and rollback your migrations for your
test session, like the above example.
## Thanks and Credit
Inspiration for this tool is drawn from
[yoyo](https://ollycope.com/software/yoyo/latest/) and
[dbmate](https://github.com/amacneil/dbmate).
Raw data
{
"_id": null,
"home_page": "https://github.com/NRWLDev/pogo-migrate",
"name": "pogo-migrate",
"maintainer": "Daniel Edgecombe",
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": "daniel@nrwl.co",
"keywords": "migrations, migrate, database, asyncpg, yoyo",
"author": "Daniel Edgecombe",
"author_email": "daniel@nrwl.co",
"download_url": "https://files.pythonhosted.org/packages/ef/bc/fa50b211b1f9b5a14cdbcdc8b7a919dc80eb09c7aebb8ee5636d5c526732/pogo_migrate-0.0.14.tar.gz",
"platform": null,
"description": "# Pogo migrate - asyncpg migration tooling\n[![image](https://img.shields.io/pypi/v/pogo_migrate.svg)](https://pypi.org/project/pogo_migrate/)\n[![image](https://img.shields.io/pypi/l/pogo_migrate.svg)](https://pypi.org/project/pogo_migrate/)\n[![image](https://img.shields.io/pypi/pyversions/pogo_migrate.svg)](https://pypi.org/project/pogo_migrate/)\n![style](https://github.com/NRWLDev/pogo-migrate/actions/workflows/style.yml/badge.svg)\n![tests](https://github.com/NRWLDev/pogo-migrate/actions/workflows/tests.yml/badge.svg)\n[![codecov](https://codecov.io/gh/NRWLDev/pogo-migrate/branch/main/graph/badge.svg)](https://codecov.io/gh/NRWLDev/pogo-migrate)\n\n`pogo-migrate` assists with maintaining your database schema (and data if\nrequired) as it evolves. Pogo supports migrations written in raw sql, as well\nas python files (useful when data needs to be migrated).\n\nA migration can be as simple as:\n\n```sql\n-- a descriptive message\n-- depends: 20210101_01_abcdef-previous-migration\n\n-- migrate: apply\nCREATE TABLE foo (id INT, bar VARCHAR(20), PRIMARY KEY (id));\n\n-- migrate: rollback\nDROP TABLE foo;\n```\n\nPogo manages these migration scripts and provides command line tools to apply,\nrollback and show migration history.\n\n## Configuration\n\nAdd pogo to pyproject.toml\n\n```toml\n[tool.pogo]\nmigrations_location = \"./migrations\"\ndatabase_config = \"{POSTGRES_DSN}\"\n```\n\nIf you have an existing environment with separate configuration values for\npostgres, you can build the DSN in config.\n\n```toml\n[tool.pogo]\nmigrations_location = \"./migrations\"\ndatabase_config = \"postgres://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}:{POSTGRES_PORT}/{PORTGRES_DATABASE}\"\n```\n\n## New migrations\n\nTo create a new migration use `pogo new`. This will template out the migration\nfile and open the file in your configured text editor (`vi` by default).\n\nSupported flags:\n\n- `--sql` generate a sql migration (defaults to `.py`)\n- `--no-interactive` skip the editor step and just write the migration template\n to the migrations directory.\n\n```bash\n$ pogo new -m \"a descriptive message\"\n```\n\n## Testing\n\nTo assist in testing, `pogo-migrate` provides the `pogo_migrate.testing`\nmodule. The apply/rollback methods in the testing module will pick up your\nconfiguration and connect to the configured test database based on environment\nvariables, or you can provide a database connection directly.\n\n```python\nimport asyncpg\nimport pogo_migrate.testing\n\n@pytest.fixture(scope=\"session\")\nasync def _engine(config): # noqa: PT005\n db = await asyncpg.connect(config.my_postgres_dsn)\n\n await pogo_migrate.testing.apply(db)\n\n yield\n\n await pogo_migrate.testing.rollback(db)\n```\n\nAlternatively add `pytest-pogo` to your test dependencies and use the provided\nfixture `pogo_engine` which will apply and rollback your migrations for your\ntest session, like the above example.\n\n\n## Thanks and Credit\n\nInspiration for this tool is drawn from\n[yoyo](https://ollycope.com/software/yoyo/latest/) and\n[dbmate](https://github.com/amacneil/dbmate).\n",
"bugtrack_url": null,
"license": "Apache",
"summary": "Database migration tool for asyncpg",
"version": "0.0.14",
"project_urls": {
"Homepage": "https://github.com/NRWLDev/pogo-migrate"
},
"split_keywords": [
"migrations",
" migrate",
" database",
" asyncpg",
" yoyo"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e8c84c9a98c51a97aedc08272ee7febac6d7c2f4f807f9a867cc345e1c0cbc49",
"md5": "26a9e1c44bda30e2a6b9998094786869",
"sha256": "eaca5d14e8f8a06f178311cd98e6ad6f1dd4e5883d2fa326d36e09aedff00035"
},
"downloads": -1,
"filename": "pogo_migrate-0.0.14-py3-none-any.whl",
"has_sig": false,
"md5_digest": "26a9e1c44bda30e2a6b9998094786869",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 15313,
"upload_time": "2024-04-16T10:19:06",
"upload_time_iso_8601": "2024-04-16T10:19:06.307866Z",
"url": "https://files.pythonhosted.org/packages/e8/c8/4c9a98c51a97aedc08272ee7febac6d7c2f4f807f9a867cc345e1c0cbc49/pogo_migrate-0.0.14-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "efbcfa50b211b1f9b5a14cdbcdc8b7a919dc80eb09c7aebb8ee5636d5c526732",
"md5": "e890185b9cf8b31ff10f910c9a612e82",
"sha256": "efd15588dc016fc967b66a2341418ca17190534f70c657846270eed715ee7046"
},
"downloads": -1,
"filename": "pogo_migrate-0.0.14.tar.gz",
"has_sig": false,
"md5_digest": "e890185b9cf8b31ff10f910c9a612e82",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 14020,
"upload_time": "2024-04-16T10:19:07",
"upload_time_iso_8601": "2024-04-16T10:19:07.786429Z",
"url": "https://files.pythonhosted.org/packages/ef/bc/fa50b211b1f9b5a14cdbcdc8b7a919dc80eb09c7aebb8ee5636d5c526732/pogo_migrate-0.0.14.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-16 10:19:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "NRWLDev",
"github_project": "pogo-migrate",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pogo-migrate"
}