New Tool Makes PostgreSQL Code Easier to Compare
TL;DR: A code formatter for PostgreSQL, pgfmt, can now format code to match the standard pg_dump tool. This makes it much easier for developers to track and compare changes in database schemas.
Key facts
- Category
- Database
- Impact
- Medium
- Published
- Source
- PostgreSQL News
Full summary
A new version of the PostgreSQL code formatter pgfmt can now mimic the standard pg_dump tool's output style.
pgfmt, a specialized tool for automatically formatting PostgreSQL code, has been updated to version 2.1. Code formatters help maintain a consistent style across a project, making code easier to read and manage for teams. This new release introduces two major features that streamline workflows for developers and database administrators. The first is the ability to format SQL code to match the output style of pg_dump, a standard and widely used utility for backing up PostgreSQL databases. The second key feature is in-place formatting, which allows users to apply changes directly to a source file using a simple command-line flag. This update also makes the tool more accessible, as it is now available for installation through the popular macOS package manager Homebrew. Other installation methods, including using a direct install script or pre-built binaries, remain available for different operating systems and preferences.
The new pg_dump compatibility is a significant improvement for database schema management, particularly for teams using version control systems like Git. When a database schema is stored as code, minor formatting differences—like changes in whitespace or line breaks—can create a lot of "noise" when comparing versions. This makes it difficult to spot meaningful structural changes, such as a new column being added to a table. By ensuring the formatting is identical to the output of pg_dump, pgfmt eliminates this noise, resulting in clean and reliable comparisons, or "diffs." This allows developers and database administrators to focus solely on the substantive changes to the database structure. This capability is crucial for reviewing code, managing complex database migrations, and maintaining a clear history of how the database has evolved over time. The in-place formatting feature further simplifies this process by reducing the steps needed to apply consistent styling.
Related on Notifire
Related stories
Primary source: PostgreSQL News
