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
-
Generate an SSH key and add the SSH key to your GitHub account.
-
Configure SSH to automatically load your SSH keys:
cat << EOF >> ~/.ssh/config Host * AddKeysToAgent yes IgnoreUnknown UseKeychain UseKeychain yes ForwardAgent yes EOF
-
Install VS Code and VS Code's Dev Containers extension. Alternatively, install PyCharm.
-
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:
-
⭐️ GitHub Codespaces: click on Open in GitHub Codespaces to start developing in your browser.
-
⭐️ 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.
-
⭐️ 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
-
VS Code Dev Container: clone this repository, open it with VS Code, and run Ctrl/⌘ + ⇧ + P → Dev Containers: Reopen in Container.
-
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
poefrom 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 topyproject.tomlanduv.lock. Add--devto install a development dependency. - Run
uv sync --upgradefrom within the development environment to upgrade all dependencies to the latest versions allowed bypyproject.toml. Add--only-devto upgrade the development dependencies only. - Run
cz bumpto bump the package's version, update theCHANGELOG.md, and create a git tag. Then push the changes and the git tag withgit 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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pg_idempotent-0.2.0.tar.gz | 146.0 kB | Without provenance | Details for pg_idempotent-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pg_idempotent-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pg_idempotent-0.2.0-py3-none-any.whl |
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
|
Security for pg-idempotent 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.