Transform PostgreSQL migrations into idempotent versions that can be run multiple times without errors. Includes native Supabase integration.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
525b68ced88f1773b2e62cf07031e8630425d924df67451e8ece61552fc34825
|
|
| MD5 |
08f7c83e18152f0b47cd427d388d38d3
|
|
| BLAKE2b-256 |
740a40de600fc5e9c1fbec6263f509f547ec93b0a6c8b9b6c2d258a7a85f96f3
|
File details
Details for the file pg_idempotent-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pg_idempotent-0.2.0-py3-none-any.whl
- Upload date:
- Size: 41.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32f06c3a1ac7ed71287cd641fa6ca13bd19ccd30da3f28ddd6bfe3ca767fd020
|
|
| MD5 |
cc89721316cf5e334c54aa55f248ea43
|
|
| BLAKE2b-256 |
99214726b47c115be55ff98b6f066563504fb63a634948dd3652442de68dca4a
|