Git Product home page Git Product logo

alembic-multischema's Introduction

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()
  • exclude A list of schema names to exclude from running the function against

getAllSchemas()

Returns a list of all schemas in the current database.

kwargs:

  • exclude A list of schema names to exclude from running the function against

getAllNonSystemSchemas()

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

kwargs:

  • exclude A list of schema names to exclude from running the function against

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"))

alembic-multischema's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.