agentleFS
kienbui1995kienbui1995/magic-powers/skills/database-optimization/SKILL.md

database-optimization

Skill0 starsChanged 8 months agoMITView on GitHub

Use when reviewing database schemas, slow queries, missing indexes, or planning migrations

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When designing schemas, reviewing slow queries, planning migrations, or auditing database performance.

    line 9
  2. Distinctive:

    Add columns as nullable first, backfill, then add NOT NULL

    line 35
  3. Distinctive:

    Create indexes CONCURRENTLY when possible

    line 36
  4. Distinctive:

    Never rename columns in one step — add new, migrate, drop old

    line 37
  5. Distinctive:

    Always include rollback migration

    line 38
  6. Distinctive:

    Test on production-size dataset

    line 39

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Database Optimization

When to Use

When designing schemas, reviewing slow queries, planning migrations, or auditing database performance.

Process

  1. Schema review — normalization, types, constraints, naming
  2. Index analysis — identify missing indexes from query patterns
  3. Query optimization — rewrite N+1, subqueries, full scans
  4. Migration safety — check for locks, data loss, rollback plan

Schema Checklist

  • Primary keys on all tables
  • Foreign keys with appropriate ON DELETE
  • NOT NULL where business logic requires
  • Appropriate column types (no text for dates, etc.)
  • Created/updated timestamps
  • Indexes on foreign keys and frequent WHERE/JOIN columns

Query Red Flags

  • SELECT * in production code
  • Missing LIMIT on unbounded queries
  • N+1 query patterns (loop of individual selects)
  • Subqueries that could be JOINs
  • Missing indexes on WHERE/ORDER BY columns
  • Full table scans on large tables

Migration Safety

  • Add columns as nullable first, backfill, then add NOT NULL
  • Create indexes CONCURRENTLY when possible
  • Never rename columns in one step — add new, migrate, drop old
  • Always include rollback migration
  • Test on production-size dataset

Output Format

  • 🔴 Critical — data loss risk or production outage
  • 🟡 Warning — performance issue or schema smell
  • 🟢 Suggestion — optimization opportunity

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.