Skip to content
Back to skills

Gap Analysis Pattern

ASecurity

Gap Analysis Pattern

  • 17 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 2, 2026
ai-agentsgosqldatabase

Security analysis

A100/100

Scanned September 2, 2026

npx -y skills add CarlosCaPe/octorato --skill gap-analysis-pattern --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Gap Analysis Pattern?

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

Security grade badge for Gap Analysis Pattern
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/carloscape-gap-analysis-pattern/badge)](https://www.skillsdirectory.com/skills/carloscape-gap-analysis-pattern)

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: gap-analysis-pattern
description: "Gap Analysis Pattern"
metadata:
  short-description: "Gap Analysis Pattern"
  original-index: 11
---

# Gap Analysis Pattern

## What

A pre-flight check that compares the **desired state** against the **current
state** of the database, reporting exactly what changes are needed before any
modifications are made.

## Why

Gap analysis answers three questions before any work begins:
1. **What needs to be done?** (changes pending)
2. **What's already done?** (idempotent re-runs)
3. **What's unexpected?** (anomalies that need investigation)

This information is logged as NOTICE messages, creating an audit trail of the
database state at the moment the script runs.

## How

```sql
-- Column gap analysis
IF EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_schema = 'public'
      AND table_name = 'Applicant'
      AND column_name = 'SpeialtyRequirement'  -- old name
) THEN
    RAISE NOTICE '  [--] COL 1 SpeialtyRequirement -> SpecialtyRequirement -- NEEDS RENAME';
    v_old_found := v_old_found + 1;
ELSIF EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_schema = 'public'
      AND table_name = 'Applicant'
      AND column_name = 'SpecialtyRequirement'  -- new name
) THEN
    RAISE NOTICE '  [OK] COL 1 SpecialtyRequirement -- ALREADY RENAMED';
    v_new_found := v_new_found + 1;
ELSE
    RAISE NOTICE '  [!!] COL 1 Neither old nor new column found -- UNEXPECTED';
END IF;
```

### The three-state pattern

| Marker | Meaning | Action |
|--------|---------|--------|
| `[--]` | Change needed | Will be applied in Phase 2 |
| `[OK]` | Already done | Skip (idempotent) |
| `[!!]` | Unexpected state | Investigate before proceeding |

## When to Use

- Phase 1 of every DDL script
- Before any ALTER TABLE, CREATE INDEX, or procedure modification
- When deploying to environments that may be in different states

## Where We Used It

- ****: 4 column checks + 4 procedure checks in Phase 1
- **/**: FK existence checks + orphan record checks
- **/**: Index existence checks + table row counts

## Gotchas

- Always count your findings (`v_old_found`, `v_new_found`) and report
  the totals -- this makes log review much faster
- The `[!!]` (unexpected) branch should raise attention but not necessarily
  abort -- sometimes the unexpected state is a valid edge case
- Gap analysis runs in Phase 1 (read-only) -- never modify data here

---

*Category: Architecture | Origin: All tickets*

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…

Newsletter

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