PgDiffPy is a command-line tool for comparing two PostgreSQL database schema dumps and generating a SQL script to update the old schema to match the new one. It is based on the original apgdiff tool but rewritten in Python.
This tool is useful for database administrators and developers who need to manage and version-control their database schemas. It simplifies the process of deploying schema changes from a development environment to a production environment.
You can install PgDiffPy directly from the source repository using pip. It is recommended to do this within a Python virtual environment to avoid conflicts with system-wide packages.
-
Clone the repository:
git clone https://github.com/Dancer3809/PgDiffPy.git cd PgDiffPy -
Install the package:
pip install .
This will install the pgdiff command-line tool and its dependencies. If you are using a virtual environment, the command will be available directly in your shell.
If you prefer not to use a virtual environment, you can install the package for your user account:
pip install --user .This installs the package in your user's local directory (e.g., ~/.local). To run the pgdiff command directly, you may need to add the local bin directory (e.g., ~/.local/bin) to your shell's PATH.
Once installed, you can use the pgdiff command-line tool to compare two database dumps:
pgdiff [options] <old_dump.sql> <new_dump.sql>old_dump.sql: The path to the SQL file containing the old database schema.new_dump.sql: The path to the SQL file containing the new database schema.
--add-transaction: AddsSTART TRANSACTIONandCOMMIT TRANSACTIONto the generated diff file.--add-defaults: AddsDEFAULT ...in case a new column has aNOT NULLconstraint but no default value.--ignore-start-with: IgnoresSTART WITHmodifications onSEQUENCEs.--ignore-function-whitespace: Ignores multiple spaces and new lines when comparing function content.
pgdiff original_schema.sql new_schema.sql > migration_script.sqlThis will generate a migration_script.sql file that you can run on the original database to apply the schema changes.
This project is licensed under the MIT License - see the LICENSE file for details.
