postgres-migrations

Resolve PostgreSQL migration errors and design idempotent schema changes.

121|16|Updated Oct 10, 2025
One-click install
npx skills add https://github.com/pr-pm/prpm --skill postgres-migrations
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres-migrations
Source: https://github.com/pr-pm/prpm/tree/main/.claude/skills/postgres-migrations
Command: npx skills add https://github.com/pr-pm/prpm --skill postgres-migrations

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates the frustration of PostgreSQL migration errors by providing proven solutions for common issues like ungrouped columns, immutable functions, and circular dependencies.

Core Features & Use Cases

  • Error Resolution: Detailed fixes for common PostgreSQL migration errors with working code examples.
  • Best Practices: Idempotent migration patterns, index optimization, and performance tuning techniques.
  • Use Case: Imagine you're deploying a new feature that requires database schema changes. Use this Skill to identify and fix migration errors before they impact production.

Quick Start

Use the postgres-migrations skill to help me fix the "Functions in index expression must be marked IMMUTABLE" error in my current migration file.

Frequently Asked Questions about postgres-migrations

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix the 'Functions in index expression must be marked IMMUTABLE' error in PostgreSQL migrations?

Functions used in index expressions must be declared IMMUTABLE so PostgreSQL can safely use them during index creation. Wrap your function with the IMMUTABLE keyword, or create an immutable wrapper function that calls your existing logic. This ensures the function's output depends only on its inputs.

What are idempotent PostgreSQL migrations and why do they matter?

Idempotent migrations are designed to run safely multiple times without errors or side effects. Use patterns like CREATE TABLE IF NOT EXISTS and DROP TABLE IF EXISTS so re-running a migration doesn't fail. This is critical for reliable deployments across multiple PostgreSQL instances.

How do I handle schema changes safely in PostgreSQL without breaking production?

Design migrations that are reversible, test them in staging first, and use transactions to group related schema changes. Avoid locks on large tables during peak hours, add indexes separately from constraint changes, and validate data integrity before and after each migration step.

Can I use generated columns in PostgreSQL and how do migrations handle them?

Generated columns compute values automatically from other columns and are supported in PostgreSQL 12+. When adding generated columns in migrations, use the GENERATED ALWAYS AS syntax and ensure any functions referenced are marked IMMUTABLE to avoid migration failures.

What's the best way to optimize indexes during schema migrations?

Create indexes concurrently using CREATE INDEX CONCURRENTLY to avoid blocking writes on production tables. Plan index placement based on query patterns, drop unused indexes to reduce write overhead, and use EXPLAIN ANALYZE to validate index effectiveness before and after migrations.

How do I resolve circular dependency issues in PostgreSQL migrations?

Circular dependencies occur when tables reference each other. Break cycles by deferring constraints, creating tables without foreign keys first, then adding constraints in a separate migration step. Use ALTER TABLE ADD CONSTRAINT with DEFERRABLE INITIALLY DEFERRED for flexible ordering.