Skip to main content

Transform PostgreSQL migrations into idempotent versions that can be run multiple times without errors. Includes native Supabase integration.

Project description

Open in Dev Containers Open in GitHub Codespaces

PG Idempotent

Transform PostgreSQL migrations into idempotent versions that can be safely run multiple times without errors. Includes native Supabase integration!

What It Does

  • Makes SQL migrations safe to re-run - No more broken deployments from partial migration failures
  • Native Supabase support - Automatically detects and processes Supabase migration files
  • Preserves original functionality - Adds safety checks without changing behavior
  • Works with any PostgreSQL setup - Supabase, raw PostgreSQL, Docker, etc.

Quick Start

Installation

# Basic installation (core functionality)
pip install pg-idempotent

# With all optional features (test generation, validation, etc.)
pip install pg-idempotent[all]

For Supabase Projects

# Check your migration files
pg-idempotent supabase check

# Fix them to be idempotent
pg-idempotent supabase fix

# Now safely deploy
supabase db push

For General PostgreSQL

# Transform a single file
pg-idempotent transform migration.sql

# Process multiple files
pg-idempotent batch migrations/ --recursive

CLI Commands

pg-idempotent --help

Contributing

Prerequisites
  1. Generate an SSH key and add the SSH key to your GitHub account.

  2. Configure SSH to automatically load your SSH keys:

    cat << EOF >> ~/.ssh/config
    
    Host *
      AddKeysToAgent yes
      IgnoreUnknown UseKeychain
      UseKeychain yes
      ForwardAgent yes
    EOF
    
  3. Install Docker Desktop.

  4. Install VS Code and VS Code's Dev Containers extension. Alternatively, install PyCharm.

  5. Optional: install a Nerd Font such as FiraCode Nerd Font and configure VS Code or PyCharm to use it.

Development environments

The following development environments are supported:

  1. ⭐️ GitHub Codespaces: click on Open in GitHub Codespaces to start developing in your browser.

  2. ⭐️ VS Code Dev Container (with container volume): click on Open in Dev Containers to clone this repository in a container volume and create a Dev Container with VS Code.

  3. ⭐️ uv: clone this repository and run the following from root of the repository:

    # Create and install a virtual environment
    uv sync --python 3.10 --all-extras
    
    # Activate the virtual environment
    source .venv/bin/activate
    
    # Install the pre-commit hooks
    pre-commit install --install-hooks
    
  4. VS Code Dev Container: clone this repository, open it with VS Code, and run Ctrl/⌘ + + PDev Containers: Reopen in Container.

  5. PyCharm Dev Container: clone this repository, open it with PyCharm, create a Dev Container with Mount Sources, and configure an existing Python interpreter at /opt/venv/bin/python.

Developing
  • This project follows the Conventional Commits standard to automate Semantic Versioning and Keep A Changelog with Commitizen.
  • Run poe from within the development environment to print a list of Poe the Poet tasks available to run on this project.
  • Run uv add {package} from within the development environment to install a run time dependency and add it to pyproject.toml and uv.lock. Add --dev to install a development dependency.
  • Run uv sync --upgrade from within the development environment to upgrade all dependencies to the latest versions allowed by pyproject.toml. Add --only-dev to upgrade the development dependencies only.
  • Run cz bump to bump the package's version, update the CHANGELOG.md, and create a git tag. Then push the changes and the git tag with git push origin main --tags.

📦pg-idempotent ┣ 📂.devcontainer ┃ ┗ 📜devcontainer.json ┣ 📂.github ┃ ┣ 📂workflows ┃ ┃ ┣ 📜publish.yml ┃ ┃ ┗ 📜test.yml ┃ ┗ 📜dependabot.yml ┣ 📂.shrimpy ┃ ┗ 📜tasks.json ┃ ┗ 📜simple.sql ┣ 📂scripts ┃ ┣ 📜README.md ┃ ┣ 📜__init__.py ┃ ┣ 📜benchmark_generator.py ┃ ┣ 📜check_fireworks_models.py ┃ ┗ 📜generate_sql_tests_parallel.py ┣ 📂src ┃ ┗ 📂pg_idempotent ┃ ┃ ┣ 📂__pycache__ ┃ ┃ ┃ ┣ 📜__init__.cpython-312.pyc ┃ ┃ ┃ ┗ 📜cli.cpython-312.pyc ┃ ┃ ┣ 📂cli ┃ ┃ ┣ 📂parser ┃ ┃ ┣ 📂transformer ┃ ┃ ┣ 📂utils ┃ ┃ ┣ 📜__init__.py ┃ ┃ ┗ 📜cli.py ┣ 📂tests ┃ ┣ 📂fixtures ┃ ┣ 📂integration ┃ ┣ 📂unit ┃ ┣ 📜__init__.py ┃ ┣ 📜test_cli.py ┃ ┗ 📜test_import.py ┣ 📜.copier-answers.yml ┣ 📜.dockerignore ┣ 📜.gitignore ┣ 📜.pre-commit-config.yaml ┣ 📜DEVELOPMENT_GUIDE.md ┣ 📜Dockerfile ┣ 📜README.md ┣ 📜docker-compose.yml ┣ 📜justfile ┣ 📜pyproject.toml ┣ 📜quickstart.sh ┗ 📜uv.lock

Project details


Download files

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

Source Distribution

pg_idempotent-0.2.0.tar.gz (146.0 kB view details)

Uploaded Source

Built Distribution

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

pg_idempotent-0.2.0-py3-none-any.whl (41.6 kB view details)

Uploaded Python 3

File details

Details for the file pg_idempotent-0.2.0.tar.gz.

File metadata

  • Download URL: pg_idempotent-0.2.0.tar.gz
  • Upload date:
  • Size: 146.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.16

File hashes

Hashes for pg_idempotent-0.2.0.tar.gz
Algorithm Hash digest
SHA256 525b68ced88f1773b2e62cf07031e8630425d924df67451e8ece61552fc34825
MD5 08f7c83e18152f0b47cd427d388d38d3
BLAKE2b-256 740a40de600fc5e9c1fbec6263f509f547ec93b0a6c8b9b6c2d258a7a85f96f3

See more details on using hashes here.

File details

Details for the file pg_idempotent-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pg_idempotent-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32f06c3a1ac7ed71287cd641fa6ca13bd19ccd30da3f28ddd6bfe3ca767fd020
MD5 cc89721316cf5e334c54aa55f248ea43
BLAKE2b-256 99214726b47c115be55ff98b6f066563504fb63a634948dd3652442de68dca4a

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