semvec/pypi-packages huggingface dataset:
pg-migrate 0.0.2
Asyncpg migration DB
License: Apache License 2.0
Requires Python: ~=3.9

Asyncpg migration DB
====================

.. image:: https://github.com/kostya-ten/pg-migrate/actions/workflows/main.yml/badge.svg
     :target: https://github.com/kostya-ten/pg-migrate/actions/workflows/main.yml
     :alt: GihHub Action

.. image:: https://img.shields.io/github/last-commit/kostya-ten/pg-migrate
     :target: https://github.com/kostya-ten/pg-migrate/commits/main
     :alt: GitHub last commit

.. image:: https://img.shields.io/github/license/kostya-ten/pg-migrate?style=plastic
     :target: https://github.com/kostya-ten/pg-migrate/blob/master/LICENSE
     :alt: license

Requirements
""""""""""""
* Python 3.9+
* Asyncpg 0.23.0+

Getting It
""""""""""
You can get pg-migrate by using pip::

    $ pip install pg-migrate

If you want to install it from source, grab the git repository from GitHub and run setup.py::

    $ git clone git://github.com/kostya-ten/pg-migrate.git
    $ cd pg-migrate
    $ python setup.py install

Usage
"""""

1. Create dir *migrations*
2. Create file *0001_foo_test.py* in dir *migrations*
3. Save the code below

.. code-block:: python

    from pg_migrate import migration

    class Migration(migration.Migration):

        upgrade = [
            migration.RunSQL('CREATE TABLE foo (id CHAR(36), val VARCHAR(20), PRIMARY KEY (id));'),
        ]

        downgrade = [
            migration.RunSQL('DROP TABLE IF EXISTS foo;'),
        ]



**Simple code**

.. code-block:: python

    import asyncpg

    from pg_migrate.migration import Manager

    pg = await asyncpg.connect('postgres://user:password@localhost:5432/db')
    migration = Manager(pg=pg)

    # upgrade db
    await migration.upgrade()

    # downgrade db
    await migration.downgrade()