{"id":18891473,"url":"https://github.com/olirice/alembic_utils","last_synced_at":"2025-05-16T11:05:15.098Z","repository":{"id":40340376,"uuid":"257604535","full_name":"olirice/alembic_utils","owner":"olirice","description":"An alembic/sqlalchemy extension for migrating sql views, functions, triggers, and policies","archived":false,"fork":false,"pushed_at":"2025-04-10T18:57:51.000Z","size":5841,"stargazers_count":252,"open_issues_count":17,"forks_count":58,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-14T03:11:19.837Z","etag":null,"topics":["alembic","migration","postgres","postgresql","sqlalchemy"],"latest_commit_sha":null,"homepage":"https://olirice.github.io/alembic_utils","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olirice.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-21T13:28:03.000Z","updated_at":"2025-05-11T18:58:08.000Z","dependencies_parsed_at":"2024-07-29T23:05:18.832Z","dependency_job_id":"ae533ad1-f3ea-48f6-a6db-b787ce0234c4","html_url":"https://github.com/olirice/alembic_utils","commit_stats":{"total_commits":216,"total_committers":20,"mean_commits":10.8,"dds":"0.12037037037037035","last_synced_commit":"c8d21f564ea8bad3b6affcd99c72e8287e4a03b2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olirice%2Falembic_utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olirice%2Falembic_utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olirice%2Falembic_utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olirice%2Falembic_utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olirice","download_url":"https://codeload.github.com/olirice/alembic_utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518384,"owners_count":22084374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alembic","migration","postgres","postgresql","sqlalchemy"],"created_at":"2024-11-08T08:00:12.731Z","updated_at":"2025-05-16T11:05:10.090Z","avatar_url":"https://github.com/olirice.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alembic Utils\n\n\u003cp\u003e\n    \u003ca href=\"https://github.com/olirice/alembic_utils/actions\"\u003e\n        \u003cimg src=\"https://github.com/olirice/alembic_utils/workflows/Tests/badge.svg\" alt=\"Test Status\" height=\"18\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/olirice/alembic_utils/actions\"\u003e\n        \u003cimg src=\"https://github.com/olirice/alembic_utils/workflows/pre-commit%20hooks/badge.svg\" alt=\"Pre-commit Status\" height=\"18\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/olirice/alembic_utils\"\u003e\u003cimg src=\"https://codecov.io/gh/olirice/alembic_utils/branch/master/graph/badge.svg\" height=\"18\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp\u003e\n    \u003ca href=\"https://github.com/olirice/alembic_utils/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/pypi/l/markdown-subtemplate.svg\" alt=\"License\" height=\"18\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://badge.fury.io/py/alembic_utils\"\u003e\u003cimg src=\"https://badge.fury.io/py/alembic_utils.svg\" alt=\"PyPI version\" height=\"18\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/psf/black\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" alt=\"Codestyle Black\" height=\"18\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/alembic_utils/\"\u003e\u003cimg src=\"https://img.shields.io/pypi/dm/alembic_utils.svg\" alt=\"Download count\" height=\"18\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp\u003e\n    \u003ca href=\"https://www.python.org/downloads/\"\u003e\u003cimg src=\"https://img.shields.io/badge/python-3.6+-blue.svg\" alt=\"Python version\" height=\"18\"\u003e\u003c/a\u003e\n    \u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/postgresql-11+-blue.svg\" alt=\"PostgreSQL version\" height=\"18\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n**Documentation**: \u003ca href=\"https://olirice.github.io/alembic_utils\" target=\"_blank\"\u003ehttps://olirice.github.io/alembic_utils\u003c/a\u003e\n\n**Source Code**: \u003ca href=\"https://github.com/olirice/alembic_utils\" target=\"_blank\"\u003ehttps://github.com/olirice/alembic_utils\u003c/a\u003e\n\n---\n\n**Autogenerate Support for PostgreSQL Functions, Views, Materialized View, Triggers, and Policies**\n\n[Alembic](https://alembic.sqlalchemy.org/en/latest/) is the defacto migration tool for use with [SQLAlchemy](https://www.sqlalchemy.org/). 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.\n\nAlembic Utils is an extension to alembic that adds support for autogenerating a larger number of [PostgreSQL](https://www.postgresql.org/) entity types, including [functions](https://www.postgresql.org/docs/current/sql-createfunction.html), [views](https://www.postgresql.org/docs/current/sql-createview.html), [materialized views](https://www.postgresql.org/docs/current/sql-creatematerializedview.html), [triggers](https://www.postgresql.org/docs/current/sql-createtrigger.html), and [policies](https://www.postgresql.org/docs/current/sql-createpolicy.html).\n\n### TL;DR\n\nUpdate alembic's `env.py` to register a function or view:\n\n```python\n# migrations/env.py\nfrom alembic_utils.pg_function import PGFunction\nfrom alembic_utils.replaceable_entity import register_entities\n\n\nto_upper = PGFunction(\n  schema='public',\n  signature='to_upper(some_text text)',\n  definition=\"\"\"\n  RETURNS text as\n  $$\n    SELECT upper(some_text)\n  $$ language SQL;\n  \"\"\"\n)\n\nregister_entities([to_upper])\n```\n\nYou're done!\n\nThe next time you autogenerate a revision with\n```shell\nalembic revision --autogenerate -m 'create to_upper'\n```\nAlembic will detect if your entities are new, updated, or removed \u0026 populate the revison's `upgrade` and `downgrade` sections automatically.\n\nFor example:\n\n```python\n\"\"\"create to_upper\n\nRevision ID: 8efi0da3a4\nRevises:\nCreate Date: 2020-04-22 09:24:25.556995\n\"\"\"\nfrom alembic import op\nimport sqlalchemy as sa\nfrom alembic_utils.pg_function import PGFunction\n\n# revision identifiers, used by Alembic.\nrevision = '8efi0da3a4'\ndown_revision = None\nbranch_labels = None\ndepends_on = None\n\n\ndef upgrade():\n    public_to_upper_6fa0de = PGFunction(\n        schema=\"public\",\n        signature=\"to_upper(some_text text)\",\n        definition=\"\"\"\n        returns text\n        as\n        $$ select upper(some_text) $$ language SQL;\n        \"\"\"\n    )\n\n    op.create_entity(public_to_upper_6fa0de)\n\n\ndef downgrade():\n    public_to_upper_6fa0de = PGFunction(\n        schema=\"public\",\n        signature=\"to_upper(some_text text)\",\n        definition=\"# Not Used\"\n    )\n\n    op.drop_entity(public_to_upper_6fa0de)\n```\n\n\nVisit the [quickstart guide](https://olirice.github.io/alembic_utils/quickstart/) for usage instructions.\n\n\u003cp align=\"center\"\u003e\u0026mdash;\u0026mdash;  \u0026mdash;\u0026mdash;\u003c/p\u003e\n\n### Contributing\n\nTo run the tests\n```\n# install pip dependencies\npip install wheel \u0026\u0026 pip install -e \".[dev]\"\n\n# run the tests\npytest src/test\n```\n\nTo invoke the linter automated formatting and generally make use of precommit checks:\n```\npip install pre-commit\npre-commit install\n\n# manually run\npre-commit run --all\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folirice%2Falembic_utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folirice%2Falembic_utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folirice%2Falembic_utils/lists"}