Skip to content
Back to skills

Atomic 3phase Ddl Scripts

ASecurity

Atomic 3-Phase DDL Scripts

  • 17 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 2, 2026
ai-agentsgosqlnodedatabase

Security analysis

A100/100

Scanned September 2, 2026

npx -y skills add CarlosCaPe/octorato --skill atomic-3phase-ddl-scripts --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Atomic 3phase Ddl Scripts?

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

Security grade badge for Atomic 3phase Ddl Scripts
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/carloscape-atomic-3phase-ddl-scripts/badge)](https://www.skillsdirectory.com/skills/carloscape-atomic-3phase-ddl-scripts)

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
---
name: atomic-3phase-ddl-scripts
description: "Atomic 3-Phase DDL Scripts"
metadata:
  short-description: "Atomic 3-Phase DDL Scripts"
  original-index: 01
---

# Atomic 3-Phase DDL Scripts

## What

A script architecture that separates database modifications into three
distinct phases within a single SQL file:

| Phase | Purpose | Behavior on Failure |
|-------|---------|---------------------|
| Phase 1 | Pre-check, gap analysis, dry-run gate | RAISE EXCEPTION stops all |
| Phase 2 | Execute changes (single DO block) | Rolls back atomically |
| Phase 3 | Post-check, verify final state | Reports pass/fail counts |

## Why

Separating concerns makes scripts **auditable**, **safe**, and **debuggable**.
Phase 1 tells you what *will* happen before anything changes. Phase 2 does the
work atomically. Phase 3 proves it worked.

## How

```sql
-- Phase 1: Pre-check
DO $$
BEGIN
    -- gap analysis: what needs doing?
    -- dry-run gate: RAISE EXCEPTION if dry_run = true
END $$;

-- Phase 2: Execute (atomic DO block)
DO $$
BEGIN
    -- all modifications inside ONE block
    -- if any fails, everything rolls back
END $$;

-- Phase 3: Post-check
DO $$
BEGIN
    -- verify every expected outcome
    -- report confirmed/failed counts
END $$;
```

The key insight is that Phase 2 is a **single DO block**. If any statement inside
it fails, PostgreSQL rolls back the entire block -- you never get a half-applied
state.

## When to Use

- Any DDL change that touches multiple objects (columns + procedures)
- Changes that need auditable before/after evidence
- Scripts that will be deployed across environments (DEV, QA, PROD)

## Where We Used It

- ****: 4 column renames + 4 procedure updates in one atomic Phase 2
- **/**: FK constraints + indexes in atomic blocks
- **/**: Index creation with pre/post verification

## Gotchas

- `CREATE INDEX CONCURRENTLY` cannot run inside a transaction block -- it needs
  its own phase outside a DO block
- Each DO block is its own transaction when autocommit is on (default in psql
  and our Node.js runner). If wrapped in explicit BEGIN/COMMIT, multiple DO
  blocks share one transaction -- avoid this for 3-Phase scripts
- `RAISE EXCEPTION` inside a DO block aborts that block's transaction and
  prevents subsequent statements from running (PG 16 docs:
  plpgsql-errors-and-messages.html)

---

*Category: Architecture | Origin: *

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.

Comments

Loading comments…