agentleFS
jhonatan-oliveiradevjhonatan-oliveiradev/agent-skills/skills/evolving-postgres-schemas-safely/SKILL.md

evolving-postgres-schemas-safely

Skill1 starsChanged 3 months agoMITView on GitHub

Use when changing a PostgreSQL schema that already contains production data or serves live traffic, especially for columns, constraints, indexes, types, backfills, renames, or destructive cleanup.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 7 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Expand: add compatible columns, tables, indexes, or read paths without removing what the running application still needs.

    line 14
  2. Distinctive:

    Constrain: add or validate invariants after existing data satisfies them.

    line 16
  3. Distinctive:

    Contract: remove legacy columns, constraints, indexes, or compatibility code only when no supported application version depends on them.

    line 18
  4. Very specific:

    Use CREATE INDEX CONCURRENTLY when production locking risk justifies it and its operational limitations are acceptable.

    line 21
  5. Distinctive:

    Treat volatile defaults and type changes as potential rewrite work until verified for the PostgreSQL version and data shape in use.

    line 22
  6. Distinctive:

    If dual-write is required temporarily, define the source of truth and exit condition before enabling it.

    line 24
  7. Distinctive:

    Prefer forward repair over assuming a destructive down migration can safely restore old data.

    line 25
  8. Distinctive:

    Before declaring the migration complete, verify:

    line 28

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Evolving PostgreSQL Schemas Safely

Core principle

Separate compatibility from cleanup. Production schema evolution is safer when additive changes land first, existing data is migrated deliberately, constraints are proven, application traffic switches, and destructive work happens only after the compatibility window closes.

Expand → migrate → contract

  1. Inspect the affected table size, write rate, query traffic, dependencies, and current schema before choosing DDL.
  2. Classify each operation by lock, table-rewrite, and compatibility risk. Do not assume a syntactically small ALTER TABLE is operationally small.
  3. Expand: add compatible columns, tables, indexes, or read paths without removing what the running application still needs.
  4. Migrate: backfill existing rows in bounded, resumable batches when a large update could create long transactions or contention.
  5. Constrain: add or validate invariants after existing data satisfies them. Prefer staged validation when the chosen PostgreSQL feature supports it.
  6. Switch: deploy application code that uses the new representation and verify real reads/writes before cleanup.
  7. Contract: remove legacy columns, constraints, indexes, or compatibility code only when no supported application version depends on them.

Operational rules

  • Use CREATE INDEX CONCURRENTLY when production locking risk justifies it and its operational limitations are acceptable; it cannot run inside a transaction block.
  • Treat volatile defaults and type changes as potential rewrite work until verified for the PostgreSQL version and data shape in use.
  • Make backfills restartable and observable. Record progress outside a single giant transaction.
  • If dual-write is required temporarily, define the source of truth and exit condition before enabling it.
  • Prefer forward repair over assuming a destructive down migration can safely restore old data.

Verification

Before declaring the migration complete, verify:

  • old and new application versions remain compatible for the intended rollout window;
  • constraints hold for existing and new rows;
  • backfills are complete and repeatable;
  • lock duration and query latency stay within the system's operational budget;
  • destructive cleanup has an explicit dependency check.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.