{"slug": "sql-skill-pack", "title": "SQL Skill Pack", "summary": "A new SQL Skill Pack from an unnamed course teaches building two validator skills: sql-migration-safety-check, which flags destructive migration patterns like dropped columns and unindexed foreign keys, and sql-query-review, which catches missing WHERE clauses, SELECT *, and N+1 patterns. The pack emphasizes strict failure handling to prevent softening blocking findings.", "body_md": "· Agentic AI · 5 min read\n\n### 📋 Prerequisites\n\n- Python Skill Pack (previous lesson)\n\n### 🎯 What You'll Learn\n\n- Build a Validator skill that catches destructive or unsafe migration patterns before they run\n- Build a Reviewer skill that checks query safety and performance against real anti-patterns\n- Design failure handling for a skill that could recommend a genuinely destructive action\n\n## What This Pack Covers\n\nTwo skills: one that checks database migrations for destructive or risky changes before they run, and one that reviews hand-written queries for correctness and performance issues. Both deal with actions that are expensive or dangerous to get wrong, which makes the failure-handling discipline from [Skill Engineering](/courses/production-agent-skills-engineering/skill-engineering-fundamentals) especially relevant here.\n\n## Skill 1: `sql-migration-safety-check`\n\n```\n---\nname: sql-migration-safety-check\ndescription: Reviews a SQL migration file for destructive or risky changes before it runs — dropped columns, missing defaults on new NOT NULL columns, and lock-heavy operations on large tables. Use when reviewing a migration, before running one against production, or when the user asks if a migration is safe.\nmetadata:\n  version: \"1.0.0\"\n---\n\n## Constraints\n\nNever state a migration is \"safe\" without checking every rule below. When\nuncertain about a table's size or production usage, say so explicitly\nrather than assuming it's small.\n\n## Review checklist\n\n1. **Dropped columns or tables.** Flag any `DROP COLUMN` or `DROP TABLE` —\n   these are irreversible without a backup. Confirm a rollback plan exists\n   before calling this acceptable.\n2. **NOT NULL without a default.** Adding a `NOT NULL` column to an\n   existing table without a `DEFAULT` will fail on any table with existing\n   rows. Flag this as a blocking issue, not a suggestion.\n3. **Unindexed foreign keys.** A new foreign key column without an\n   accompanying index will cause slow joins and slow cascade deletes as\n   the table grows.\n4. **Lock-heavy operations on large tables.** `ALTER TABLE` operations that\n   rewrite an entire table (adding a column with a non-null default on\n   most database engines, for example) lock the table for the duration.\n   Flag this and suggest a safer, phased approach when possible — add the\n   column nullable first, backfill, then add the constraint separately.\n\n## On failure\n\nIf any blocking issue is found, do not soften the assessment — state\nclearly that the migration should not run as written, and what needs to\nchange first.\n```\n\n**Pattern:** Validator, with an explicit constraint (from [Skill Engineering](/courses/production-agent-skills-engineering/skill-engineering-fundamentals)) against the failure mode that matters most here — a validator that’s been talked into softening a genuinely blocking finding is worse than no validator at all.\n\n## Skill 2: `sql-query-review`\n\n```\n---\nname: sql-query-review\ndescription: Reviews a SQL query for correctness and performance issues — missing WHERE clauses on UPDATE/DELETE, SELECT *, and likely N+1 query patterns. Use when reviewing a query before it ships, or when the user asks whether a query is safe or efficient.\nmetadata:\n  version: \"1.0.0\"\n---\n\n## Review checklist\n\n1. **UPDATE or DELETE without a WHERE clause.** This is the single highest-\n   severity finding this skill can report — flag it first, ahead of every\n   other check, and state plainly what rows would be affected (all of them).\n2. **SELECT \\*.** Flag in application code (fine in ad-hoc exploration, not\n   in code that ships) — it breaks when columns are added later and pulls\n   more data than needed.\n3. **Queries inside a loop.** If the surrounding code shows a query being\n   constructed or executed inside a loop over application-level records,\n   flag this as a likely N+1 pattern and suggest a single batched query\n   or a join instead.\n4. **Unparameterized string-built queries.** Any query built via string\n   concatenation or f-strings with user input inserted directly is a SQL\n   injection risk — flag this as blocking, not a style note.\n\nReport findings ordered by severity: missing WHERE clause and injection\nrisk first, then performance issues.\n```\n\n**Pattern:** Reviewer — assessing already-written SQL against criteria and reporting specific, prioritized findings, per [Skill Design Patterns](/courses/production-agent-skills-engineering/skill-design-patterns).\n\n## Why Severity Ordering Matters Here\n\nBoth skills above explicitly order their findings by severity rather than just listing checks in an arbitrary sequence. This matters more for a SQL pack than for most: a missing `WHERE`\n\nclause on a `DELETE`\n\nis catastrophic and a `SELECT *`\n\nis a minor style issue, and a skill that reports them with equal visual weight risks a genuinely dangerous finding getting lost among cosmetic ones. This is worth checking specifically during testing — not just whether a skill catches every issue, but whether the *most dangerous* one is impossible to miss in its output.\n\n## Testing Both Skills\n\nRun `sql-migration-safety-check`\n\nagainst a migration with no issues, one with exactly one blocking issue (a `DROP COLUMN`\n\n), and one with several issues at different severities — confirm the blocking issue is never softened into a mere suggestion. Run `sql-query-review`\n\nagainst a query that’s genuinely fine, one with an unqualified `DELETE`\n\n, and one with a plausible N+1 pattern in the surrounding code — this last case is the hardest to get reliably right, since it depends on the skill reading context beyond just the query text itself, and is worth testing with a real code snippet, not just the bare SQL.\n\n## Summary\n\n`sql-migration-safety-check`\n\nis a Validator focused on irreversible or lock-heavy changes, with an explicit constraint against softening a blocking finding`sql-query-review`\n\nis a Reviewer covering correctness (missing WHERE, injection risk) and performance (SELECT *, N+1 patterns), ordered by severity- Both skills deal with genuinely destructive or risky actions, which is exactly the case\n[Skill Engineering](/courses/production-agent-skills-engineering/skill-engineering-fundamentals)says warrants explicit, non-negotiable constraints rather than soft suggestions - Test not just whether each skill catches every issue, but whether the most severe one is impossible to miss in the output\n\nNext, a pack for the collaboration layer around code — pull requests, issue triage, and release notes, using the GitHub CLI.", "url": "https://wpnews.pro/news/sql-skill-pack", "canonical_source": "https://superml.org/tutorials/sql-skill-pack", "published_at": "2026-07-26 00:00:00+00:00", "updated_at": "2026-08-01 05:00:58.788941+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools"], "entities": [], "alternates": {"html": "https://wpnews.pro/news/sql-skill-pack", "markdown": "https://wpnews.pro/news/sql-skill-pack.md", "text": "https://wpnews.pro/news/sql-skill-pack.txt", "jsonld": "https://wpnews.pro/news/sql-skill-pack.jsonld"}}