Skip to content

docs: add pgfence as complementary migration safety tool#693

Closed
flvmnt wants to merge 3 commits intosupabase-community:mainfrom
flvmnt:docs/add-pgfence-complementary-check
Closed

docs: add pgfence as complementary migration safety tool#693
flvmnt wants to merge 3 commits intosupabase-community:mainfrom
flvmnt:docs/add-pgfence-complementary-check

Conversation

@flvmnt
Copy link
Contributor

@flvmnt flvmnt commented Feb 25, 2026

Summary

  • Adds a new section to the Continuous Integration guide showing how to combine Postgres Language Server with pgfence for comprehensive migration checking
  • Includes a complete GitHub Actions workflow example running both tools together
  • Documents pgfence's --ci and --max-risk flags for CI gating

Why

PGLT catches SQL syntax and semantic issues. pgfence adds a complementary layer: it analyzes what PostgreSQL lock mode each DDL statement acquires, what it blocks, scores the runtime risk level, and provides safe rewrite recipes for dangerous patterns (e.g., CREATE INDEX without CONCURRENTLY, ADD COLUMN ... NOT NULL without the expand/contract sequence).

Running both tools in CI gives teams comprehensive migration checking — correctness (PGLT) and safety (pgfence).

Test plan

  • Verify the markdown renders correctly on the docs site
  • Confirm the YAML workflow example is syntactically valid
  • Verify external links resolve (pgfence.dev, npm package)

Add a section to the CI guide showing how to combine Postgres Language
Server with pgfence for comprehensive migration checking. PGLT catches
SQL syntax and semantic issues, while pgfence analyzes PostgreSQL lock
modes, risk levels, and provides safe rewrite recipes.
Copilot AI review requested due to automatic review settings February 25, 2026 22:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds documentation to the Continuous Integration guide explaining how to run Postgres Language Server (PGLT) alongside pgfence in CI to validate both SQL correctness and migration operational safety.

Changes:

  • Adds a new “Combining with pgfence for Migration Safety” section.
  • Includes a GitHub Actions workflow example running PGLT checks and pgfence analysis.
  • Documents pgfence CI gating flags (--ci, --max-risk) with examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


### Combining with pgfence for Migration Safety

While Postgres Language Server catches SQL syntax and semantic issues, it does not analyze the **lock modes** and **runtime risk** of DDL statements. [pgfence](https://pgfence.dev) is a complementary CLI that fills this gap — it tells you what PostgreSQL lock each migration statement acquires, what it blocks, and provides safe rewrite recipes when it detects dangerous patterns.
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor grammar: “what PostgreSQL lock each migration statement acquires” reads as singular; consider pluralizing to “locks” (or rephrasing to “lock mode”) for clarity.

Suggested change
While Postgres Language Server catches SQL syntax and semantic issues, it does not analyze the **lock modes** and **runtime risk** of DDL statements. [pgfence](https://pgfence.dev) is a complementary CLI that fills this gap — it tells you what PostgreSQL lock each migration statement acquires, what it blocks, and provides safe rewrite recipes when it detects dangerous patterns.
While Postgres Language Server catches SQL syntax and semantic issues, it does not analyze the **lock modes** and **runtime risk** of DDL statements. [pgfence](https://pgfence.dev) is a complementary CLI that fills this gap — it tells you which PostgreSQL lock mode each migration statement acquires, what it blocks, and provides safe rewrite recipes when it detects dangerous patterns.

Copilot uses AI. Check for mistakes.
Comment on lines +73 to +78
- name: Check SQL syntax (PGLT)
run: postgres-language-server check sql/

# 2. Check migration safety with pgfence
- name: Check migration safety (pgfence)
run: npx --yes @flvmnt/pgfence analyze --ci migrations/*.sql
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pgfence section mixes example paths (postgres-language-server check sql/ vs migrations/*.sql), and the dedicated migrations guide uses supabase/migrations. This is likely to confuse readers; consider using a single consistent migrations path across both tools (or explicitly note that the paths are placeholders to be adjusted).

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +88
npx @flvmnt/pgfence analyze --ci migrations/*.sql

# Block on MEDIUM or above (stricter)
npx @flvmnt/pgfence analyze --ci --max-risk medium migrations/*.sql
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shell examples use npx @flvmnt/pgfence ... without --yes, while the CI workflow uses npx --yes .... Without --yes, npx can prompt for confirmation in non-interactive environments, potentially hanging CI. Consider adding --yes to these examples (or explaining when it’s required).

Suggested change
npx @flvmnt/pgfence analyze --ci migrations/*.sql
# Block on MEDIUM or above (stricter)
npx @flvmnt/pgfence analyze --ci --max-risk medium migrations/*.sql
npx --yes @flvmnt/pgfence analyze --ci migrations/*.sql
# Block on MEDIUM or above (stricter)
npx --yes @flvmnt/pgfence analyze --ci --max-risk medium migrations/*.sql

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +88
run: npx --yes @flvmnt/pgfence analyze --ci migrations/*.sql
```

pgfence exits with code 1 when it finds high-risk issues, so it integrates naturally as a CI gate. You can adjust the threshold with `--max-risk`:

```sh
# Block on HIGH or above (default)
npx @flvmnt/pgfence analyze --ci migrations/*.sql

# Block on MEDIUM or above (stricter)
npx @flvmnt/pgfence analyze --ci --max-risk medium migrations/*.sql
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The npx invocations of @flvmnt/pgfence download and execute the latest version of a third-party npm package on every CI run without pinning a version or verifying integrity. If that package or the npm registry is compromised, an attacker could execute arbitrary code in your CI environment (with access to repository contents, tokens, and secrets). To reduce supply-chain risk, pin @flvmnt/pgfence to a specific version or otherwise ensure the code being executed in CI is immutably identified and integrity-checked.

Copilot uses AI. Check for mistakes.
@flvmnt
Copy link
Contributor Author

flvmnt commented Feb 25, 2026

Addressed feedback: pinned pgfence version in all examples, ensured --yes flag on all npx commands, removed hidden Unicode characters.

@flvmnt
Copy link
Contributor Author

flvmnt commented Feb 25, 2026

Verified: scanned for hidden Unicode characters (zero-width spaces, bidi marks, BOM) — none found. All three npx commands already include --yes and are pinned to @0.2.1. No changes needed.

@flvmnt
Copy link
Contributor Author

flvmnt commented Feb 25, 2026

Pushed fixes: improved grammar, consistent migration paths across examples. All review feedback addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants