squawk-cli: PostgreSQL Migration Linter

2.47.0 · active · verified Thu Apr 16

Squawk-cli is a linter for PostgreSQL migrations and SQL, designed to identify potentially dangerous operations that could lead to database locks, downtime, or compatibility issues. It helps prevent unexpected downtime by enforcing best practices for schema changes. The current version is 2.47.0. It maintains a relatively active release cadence, with multiple minor versions often released within a few weeks to months.

Common errors

Warnings

Install

Quickstart

This quickstart demonstrates how to install `squawk-cli` and run it against a sample SQL migration file to detect potential issues. It creates a temporary SQL file, executes `squawk` on it, and then cleans up the file.

import os

# Create a dummy SQL migration file
sql_content = '''
-- migration_001.sql

CREATE TABLE users (
    id serial NOT NULL PRIMARY KEY,
    username varchar(255) NOT NULL,
    email varchar(255) NOT NULL UNIQUE
);

-- This will trigger a warning in squawk if not handled concurrently
CREATE INDEX email_idx ON users (email);

-- This might also trigger a warning depending on Postgres version and rules
ALTER TABLE users ADD COLUMN age integer DEFAULT 18;
'''

file_path = 'migration_001.sql'
with open(file_path, 'w') as f:
    f.write(sql_content)

print(f"Created {file_path}:")
print(sql_content)

# Run squawk-cli on the file
print(f"\nRunning squawk on {file_path}...")
os.system(f"squawk {file_path}")

# Clean up the dummy file
os.remove(file_path)
print(f"\nCleaned up {file_path}.")

view raw JSON →