Skip to content
Back to skills

Database Postgresql

ASecurity

Use an expand -> backfill -> contract rollout. In PostgreSQL, the safe pattern is to make the schema change non-breaking first, deploy code that can handle both old and new states, backfill gradually, then remove the old path only after production traffic is fully moved. Recommended sequence: 1. Expand the schema with a backward-compatible change. - Add the new column as nullable, or with a default that does not force a risky table rewrite on your PostgreSQL version and table shape. - Do not ...

  • 584 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 5, 2026
developmentsqlrails

Security analysis

A100/100

Pro scans all 11 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill database-postgresql --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Database Postgresql?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Database Postgresql
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-database-postgresql-agent-skills-standard/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-database-postgresql-agent-skills-standard)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
Use an expand -> backfill -> contract rollout. In PostgreSQL, the safe pattern is to make the schema change non-breaking first, deploy code that can handle both old and new states, backfill gradually, then remove the old path only after production traffic is fully moved.

Recommended sequence:

1. Expand the schema with a backward-compatible change.
   - Add the new column as nullable, or with a default that does not force a risky table rewrite on your PostgreSQL version and table shape.
   - Do not immediately add `NOT NULL` if existing rows are not ready.
   - Use an explicit migration; do not depend on ORM schema synchronization in production.

2. Deploy application code that can read and write both representations.
   - New writes should populate the new column.
   - Reads should tolerate rows where the new column is still null.
   - If the column changes meaning or format, keep translation logic in the application temporarily.

3. Backfill existing rows in controlled batches.
   - Avoid one giant `UPDATE` on a large hot table.
   - Batch by primary key or time range so you reduce lock time, WAL spikes, and replication lag.
   - If this is one business operation, keep each batch transaction scoped and explicit.

4. Add follow-up constraints and indexes after the data is ready.
   - Add indexes that match the real query shape: filters, joins, and sort order.
   - If the new column participates in tenant or RLS predicates, index it appropriately.
   - Only enforce `NOT NULL` after verifying backfill completeness.

5. Contract the old path.
   - Remove application fallback logic.
   - Drop the old column or old code path in a later migration after production verification.

Example:

```sql
-- expand
ALTER TABLE orders ADD COLUMN status_v2 text;

-- backfill (often done in batches outside one monolithic migration)
UPDATE orders
SET status_v2 = status
WHERE status_v2 IS NULL;

-- later, after app is writing status_v2 and all rows are backfilled
ALTER TABLE orders ALTER COLUMN status_v2 SET NOT NULL;

-- contract in a later release
ALTER TABLE orders DROP COLUMN status;
ALTER TABLE orders RENAME COLUMN status_v2 TO status;
```

Practical guardrails:

- Avoid destructive one-step changes in production.
- Match the transaction boundary to one business action, not an entire long-running migration campaign.
- Be explicit about pagination or batching strategy during backfill.
- Verify on production-like data before contract: row counts, null counts, write-path health, and query plans for any new index-backed reads.

Files in this skill

  • eval-1.baseline.md3.1 KB
  • eval-1.with-skill.md2.5 KB
  • eval-2.baseline.md3.8 KB
  • eval-2.with-skill.md2.1 KB
  • eval-3.baseline.md4 KB
  • eval-3.with-skill.md2.6 KB
  • trigger-1.md161 B
  • trigger-2.md159 B
  • trigger-3.md135 B
  • trigger-4.md162 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.