Skip to main content

SQLAlchemy

Migrations

Proxying

To run your migrations through the proxy edit your alembic env.py or alembic.ini to set the sqlalchemy url to connect via the proxy:

pwd = os.environ['PG_PROXY_PASSWORD']
port = os.environ['PG_PROXY_PORT']

url = "postgresql://postgres:{}@localhost:{}/mydb".format(pwd, port)

Applying DDLX statements

Use the Operations.execute method.

First, create a migration:

alembic revision -m "electrify items"

Then execute the SQL in the upgrade function:

# ... docstring and revision identifiers ...

from alembic import op
import sqlalchemy as sa

def upgrade():
op.execute('ALTER TABLE items ENABLE ELECTRIC')

Event sourcing

One way of consuming a change feed from Postgres in Python is to use the psycopg2.extras.LogicalReplicationConnection.

See Integrations -> Event sourcing for more information.