Dry run gate pattern

From CarlosCaPe/octorato · View interactive version

Dry run gate pattern is an AI agent skill from the GitHub repository CarlosCaPe/octorato. Dry-Run Gate Pattern

How to use this skill

Skill file

Dry-Run Gate Pattern

What

A boolean flag that defaults to true, preventing any modifications unless the

caller explicitly opts in. The script runs all analysis and reporting but aborts

before making changes.

Why

Prevents accidental execution. Every script is read-only by default. The DBA

must consciously pass --execute 1 to apply changes. This is critical when the

same script targets DEV, QA, and PROD.

How

DO $$
DECLARE
    dry_run boolean := COALESCE(
        NULLIF(current_setting('da.execute', true), ''),
        '0'
    ) <> '1';
BEGIN
    -- ... gap analysis, reporting ...

    IF dry_run THEN
        RAISE NOTICE 'DRY-RUN COMPLETE -- no changes applied';
        RAISE NOTICE 'To execute, run with --execute 1';
        RAISE EXCEPTION 'DRY-RUN complete -- no changes applied.';
    END IF;
END $$;

The runner (scripts/run_sql_file.js) sets da.execute via:

SET da.execute = '1';

The COALESCE(NULLIF(...), '0') expression handles three edge cases:

(PG 16 docs: functions-admin.html -- "returns NULL if missing_ok is true")

All three default to dry-run mode.

When to Use

Where We Used It

Gotchas

statements from running -- this is the desired behavior for dry-run

"return NULL if setting doesn't exist" instead of throwing an error


Category: Safety | Origin: DA-102

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.