Skip to main content

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/⌘ + ⇧ + P → Dev 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

Metadata

Release files for pg-idempotent 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pg-idempotent 0.2.0
File Size Uploaded
pg_idempotent-0.2.0.tar.gz 146.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pg-idempotent 0.2.0
File Interpreter ABI Platform
pg_idempotent-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 187.6 kB

Release files / pg_idempotent-0.2.0.tar.gz

Download URL pg_idempotent-0.2.0.tar.gz
Size 146.0 kB
Tags Source
SHA-256 checksum
How to use checksums
525b68ced88f1773b2e62cf07031e8630425d924df67451e8ece61552fc34825
BLAKE2b-256 checksum
How to use checksums
740a40de600fc5e9c1fbec6263f509f547ec93b0a6c8b9b6c2d258a7a85f96f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.16

Release files / pg_idempotent-0.2.0-py3-none-any.whl

Download URL pg_idempotent-0.2.0-py3-none-any.whl
Size 41.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32f06c3a1ac7ed71287cd641fa6ca13bd19ccd30da3f28ddd6bfe3ca767fd020
BLAKE2b-256 checksum
How to use checksums
99214726b47c115be55ff98b6f066563504fb63a634948dd3652442de68dca4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.16

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page