Skip to main content

Multi schema postgres migrations using alembic

Project description

alembic-multischema

This module provides the ability to act on multiple postgres schemas at once when using alembic.

Functions:

perSchema(**kwargs)

Used to decorate the upgrade() and downgrade() functions in a migration. When upgrade or downgrade are decorated with perSchema() the decorated function will be called for a list of schemas in the current database.

kwargs:

  • schemas A list of schema names to run the function against. If omitted perSchema() will automatically generate a list of non-system schemas from the current database by using getAllNonSystemSchemas()

getAllSchemas()

Returns a list of all schemas in the current database.

getAllNonSystemSchemas()

Returns a list of schemas in the current database, omitting information_schema and pg_catalog.

Example Usage:

"""CreateUsersTable

Revision ID: a6a219646b55
Revises:
Create Date: 2019-10-16 14:43:11.347575

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import text
from almebic_multischema import perSchema

# revision identifiers, used by Alembic.
revision = 'a6a219646b55'
down_revision = None
branch_labels = None
depends_on = None

@perSchema(schemas=["public", "foo", "bar"])
def upgrade():
    users = text(
      """CREATE TABLE users
          (
            id serial PRIMARY KEY,
            firstname VARCHAR (50) UNIQUE,
            lastname VARCHAR (50)
          );
      """)
    op.execute(users)

@perSchema(schemas=["public", "foo", "bar"])
def downgrade():
    op.execute(text("DROP TABLE users"))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alembic_multischema-0.0.6-py2.py3-none-any.whl (6.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file alembic_multischema-0.0.6-py2.py3-none-any.whl.

File metadata

  • Download URL: alembic_multischema-0.0.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.8.0 tqdm/4.36.1 CPython/2.7.16

File hashes

Hashes for alembic_multischema-0.0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 18dd37fbb20686b4ae5337fc1ea05db822afe3c77021c29a117cd5c4fd4a32e8
MD5 13759e3b469f4bda388c6cd66245cc3f
BLAKE2b-256 122bf51bf4f8ec1dc13242c7ee9dad03181ad469f6e48c54588131cb81c6da3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page