DEV Community

Cover image for How ORM Migrations Are Hiding Missing Indexes (And How to Actually See Your Database)
Jackson Kasi
Jackson Kasi Subscriber

Posted on

How ORM Migrations Are Hiding Missing Indexes (And How to Actually See Your Database)

I spent 4 hours last week debugging a slow API endpoint.

The culprit? A missing index on a foreign key that my ORM "helpfully" abstracted away during a schema migration.

When you use modern tools like Prisma or Drizzle, it’s incredibly easy to forget what your database actually looks like. The visual connection between tables is lost in hundreds of lines of TypeScript.

πŸ›‘ The Hidden Danger of ORMs

Let's look at a standard relational setup: you have Users and Orders. In your ORM, you define a relation. The ORM generates a migration adding a user_id column to Orders with a foreign key constraint.

What it doesn't always do automatically is add a B-Tree index to user_id.

-- What the ORM generated
ALTER TABLE "orders" ADD CONSTRAINT "fk_user" FOREIGN KEY ("user_id") REFERENCES "users"("id");

-- What you actually needed for performance
CREATE INDEX "idx_orders_user_id" ON "orders"("user_id");
Enter fullscreen mode Exit fullscreen mode

Without that index, every time you query a user's orders, Postgres has to perform a sequential scan on the Orders table. At 1,000 rows, it's fine. At 10,000,000 rows, your API grinds to a halt.

Because developers only look at their schema.ts file, they never visually spot the missing index.


πŸ‘οΈ Stop Guessing. Look at your Database.

I wanted a tool that let me see my PostgreSQL schema and design it visually, without losing the power of raw SQL. When I couldn't find a good one that wasn't locked behind a massive enterprise paywall, I built one.

Meet Tiger SQL 🐯

It’s a lightweight, open-source Postgres visualizer with built-in AI assistance.

βœ… Visual ERDs: You paste your schema (or connect your DB), and it maps the relationships instantly.
βœ… AI-Assisted Optimization: It analyzes your tables and actively warns you about missing indexes or poorly optimized queries before they hit production.
βœ… Zero Bloat: It runs entirely in your browser/local environment.

πŸš€ Take Control of Your SQL

Don't let your ORM build a black box. You need to understand the underlying relational structure of your application.

Tiger SQL is completely free and open-source. Fork it, run it, and find the missing indexes in your own projects:

πŸ‘‰ Fork Tiger SQL on GitHub (jacksonkasi1)

How do you currently visualize and audit your Postgres schemas in your team? Let me know below.

Top comments (0)