dogweather

dogweather

Anyone thinking about porting Active Record Doctor to Ecto?

I realized I could really use something like this in my Phoenix project:

I asked Claude 4 Sonnet if a port exists - it said no, and gave me this rundown:

Summary

Great question! Active Record Doctor is indeed fantastic for Rails apps. Here’s what exists in the Phoenix/Elixir and PostgreSQL worlds:

1. Phoenix/Elixir World

Unfortunately, there’s no direct equivalent to Active Record Doctor for Phoenix/Ecto yet. However, there are some tools that provide partial coverage:

Ecto-specific Tools:

  • Ecto.Linter - Basic linting for Ecto schemas and queries (though less active)
  • Boundary - Architectural analysis (not database-focused)
  • Credo - Code analysis that includes some database-related checks

What’s Missing:

The Phoenix ecosystem could really use a tool that checks for:

  • Missing foreign key constraints
  • Missing indexes on associations
  • Schema/validation mismatches
  • Unused indexes
  • Missing presence validations for NOT NULL columns

This would be a great open-source opportunity for someone to build an “Ecto Doctor” equivalent!

2. PostgreSQL Level

There are several excellent PostgreSQL-native tools:

Schema Analysis:

Database Health:

Custom Queries:

You can write PostgreSQL queries to detect many issues Active Record Doctor finds:

-- Find tables without primary keys
SELECT schemaname, tablename 
FROM pg_tables 
WHERE schemaname = 'public' 
AND tablename NOT IN (
  SELECT tablename 
  FROM pg_indexes 
  WHERE indexname LIKE '%_pkey'
);

-- Find foreign keys without indexes
SELECT conname, conrelid::regclass, confrelid::regclass
FROM pg_constraint 
WHERE contype = 'f' 
AND NOT EXISTS (
  SELECT 1 FROM pg_index 
  WHERE indrelid = conrelid 
  AND indkey[0] = conkey[1]
);

Recommendation

For your Phoenix app, I’d suggest:

  1. Create custom Mix tasks that run PostgreSQL queries to detect common issues
  2. Build a simple “Ecto Doctor” - this could be a valuable contribution to the community
  3. Use PostgreSQL-native tools for performance and schema analysis

Given your appreciation for C.J. Date’s rigorous approach to database design, you might actually enjoy building such a tool - it would enforce good relational practices in the Elixir ecosystem!

Most Liked

kevinschweikert

kevinschweikert

There is Ecto PSQL Extras — ecto_psql_extras v0.8.8 and the same exists for MySQL and SQLite

Schultzer

Schultzer

Nothing like that exists for Ecto, most of this could be done in a mix of runtime and compiletime.

One of my goal with SQL is to provide most of this at compiletime.

Where Next?

Popular in Discussions Top

bartblast
With the core component system and HTTP/WebSocket infrastructure solid, it’s time to tackle Pub/Sub support. What We Have vs What’s Miss...
New
jdumont
I could write forever about this, but I’ll do my best to keep it succinct. For anyone familiar with event sourcing, what is your opinion...
New
Morzaram
Hey everyone. I’m feeling a bit conflicted. I’ve learned Flutter and built a somewhat MVP of this app. I’m a solo dev and throughout this...
New
bartblast
Hey there! :slight_smile: I’m working on updating the Hologram website home page and would love to get your input. Current situation: ...
New
ashkan117
I’m wondering how do people structure their JSON Api’s with Phoenix. Using the blogs example, let’s say I have a blogs view like the foll...
New
garrison
I have been thinking about how I might write a new web framework in Elixir. (Not committing to anything, just thinking about it.) One th...
New
bartblast
Some great comments in the home page thread shifted toward what you’d like to see in Hologram’s future, particularly standalone mode. I’v...
New
AstonJ
A remark @Garrison made… ..has already inspired a thread for the technical side of reclaiming our internet, but there is of course anot...
New
matreyes
I haven’t seen this paper being discussed by the community, but I think this makes Elixir more relevant than ever. TLDR; The paper...
New
PragTob
:wave: I’m currently extracting the statistics calculation part from benchee and stumbled upon how to present error conditions. In the c...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement