All Projects → olirice → alembic_utils

olirice / alembic_utils

Licence: MIT license
An alembic/sqlalchemy extension for migrating sql views, functions, triggers, and policies

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to alembic utils

pyramid-cookiecutter-alchemy
[DEPRECATED - Please use https://github.com/pylons/pyramid-cookiecutter-starter instead] A Cookiecutter (project template) for creating a Pyramid project using SQLite for persistent storage, SQLAlchemy for an ORM, Alembic for database migrations, URL dispatch for routing, and Jinja2 for templating.
Stars: ✭ 39 (-62.86%)
Mutual labels:  sqlalchemy, alembic
mad-migration
Database migration tool for migrate different structured databases.
Stars: ✭ 29 (-72.38%)
Mutual labels:  sqlalchemy, alembic
graygram-web
www.graygram.com
Stars: ✭ 16 (-84.76%)
Mutual labels:  sqlalchemy, alembic
cloudrun-fastapi
FastAPI on Google Cloud Run
Stars: ✭ 112 (+6.67%)
Mutual labels:  sqlalchemy, alembic
flask-db
A Flask CLI extension to help migrate and manage your SQL database.
Stars: ✭ 56 (-46.67%)
Mutual labels:  sqlalchemy, alembic
carry
Python ETL(Extract-Transform-Load) tool / Data migration tool
Stars: ✭ 115 (+9.52%)
Mutual labels:  sqlalchemy, migration
fast-api-sqlalchemy-template
Dockerized web application on FastAPI, sqlalchemy1.4, PostgreSQL
Stars: ✭ 25 (-76.19%)
Mutual labels:  sqlalchemy, alembic
Flask Restplus Boilerplate
A boilerplate for flask restful web service
Stars: ✭ 466 (+343.81%)
Mutual labels:  sqlalchemy, migration
FRDP
Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin ⭐
Stars: ✭ 55 (-47.62%)
Mutual labels:  sqlalchemy
sqlathanor
Serialization / De-serialization support for the SQLAlchemy Declarative ORM
Stars: ✭ 105 (+0%)
Mutual labels:  sqlalchemy
Flask Boilerplate
Simple flask boilerplate with Postgres, Docker, and Heroku/Zeit now
Stars: ✭ 251 (+139.05%)
Mutual labels:  sqlalchemy
graphene-sqlalchemy-filter
Filters for Graphene SQLAlchemy integration
Stars: ✭ 117 (+11.43%)
Mutual labels:  sqlalchemy
SuperGrate
💾 Get moving with Super Grate; a free & open source Windows Profile Migration & Backup Utility. Super Grate is a GUI (Graphical User Interface) that assists Microsoft's USMT (User State Migration Utility) in performing remote migrations over a network connection.
Stars: ✭ 91 (-13.33%)
Mutual labels:  migration
fastapi-debug-toolbar
A debug toolbar for FastAPI.
Stars: ✭ 90 (-14.29%)
Mutual labels:  sqlalchemy
set-env-to-github env
A migration tools convert `::set-env`/`::set-output`/`::save-state` to $GITHUB_ENV/$GITHUB_OUTPUT/$GITHUB_STATE on GitHub Actions.
Stars: ✭ 27 (-74.29%)
Mutual labels:  migration
Statik
Multi-purpose static web site generator aimed at developers.
Stars: ✭ 249 (+137.14%)
Mutual labels:  sqlalchemy
Python For Entrepreneurs Course Demos
Contains all the "handout" materials for Talk Python's Python for Entrepreneurs course. This includes notes and the final version of the website code.
Stars: ✭ 247 (+135.24%)
Mutual labels:  sqlalchemy
sqlalchemy-utc
SQLAlchemy type to store aware datetime values
Stars: ✭ 87 (-17.14%)
Mutual labels:  sqlalchemy
laravel-migrate-check
An artisan command to check for pending migrations with proper exit code
Stars: ✭ 53 (-49.52%)
Mutual labels:  migration
Daisy-OLD
“ Hey there 👋 I'm Daisy „ PTB Group management bot with some extra features
Stars: ✭ 43 (-59.05%)
Mutual labels:  sqlalchemy

Alembic Utils

Test Status Pre-commit Status

License PyPI version Codestyle Black Download count

Python version PostgreSQL version


Documentation: https://olirice.github.io/alembic_utils

Source Code: https://github.com/olirice/alembic_utils


Autogenerate Support for PostgreSQL Functions, Views, Materialized View, Triggers, and Policies

Alembic is the defacto migration tool for use with SQLAlchemy. Without extensions, alembic can detect local changes to SQLAlchemy models and autogenerate a database migration or "revision" script. That revision can be applied to update the database's schema to match the SQLAlchemy model definitions.

Alembic Utils is an extension to alembic that adds support for autogenerating a larger number of PostgreSQL entity types, including functions, views, materialized views, triggers, and policies.

TL;DR

Update alembic's env.py to register a function or view:

# migrations/env.py
from alembic_utils.pg_function import PGFunction
from alembic_utils.replaceable_entity import register_entities


to_upper = PGFunction(
  schema='public',
  signature='to_upper(some_text text)',
  definition="""
  RETURNS text as
  $$
    SELECT upper(some_text)
  $$ language SQL;
  """
)

register_entities([to_upper])

You're done!

The next time you autogenerate a revision with

alembic revision --autogenerate -m 'create to_upper'

Alembic will detect if your entities are new, updated, or removed & populate the revison's upgrade and downgrade sections automatically.

For example:

"""create to_upper

Revision ID: 8efi0da3a4
Revises:
Create Date: 2020-04-22 09:24:25.556995
"""
from alembic import op
import sqlalchemy as sa
from alembic_utils.pg_function import PGFunction

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


def upgrade():
    public_to_upper_6fa0de = PGFunction(
        schema="public",
        signature="to_upper(some_text text)",
        definition="""
        returns text
        as
        $$ select upper(some_text) $$ language SQL;
        """
    )

    op.create_entity(public_to_upper_6fa0de)


def downgrade():
    public_to_upper_6fa0de = PGFunction(
        schema="public",
        signature="to_upper(some_text text)",
        definition="# Not Used"
    )

    op.drop_entity(public_to_upper_6fa0de)

Visit the quickstart guide for usage instructions.

—— ——

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].