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

marcandre
Compilation time for our project degraded from ~26 seconds to ~32 seconds (~23% slower) :disappointed_face:. Did anyone else compare com...
New
garrison
The Elixir ecosystem is one of our biggest strengths, and the BEAM really lends itself to native implementations (e.g. Cachex over Redis,...
New
bglusman
I’m curious how others in the community deal with first class enums… especially crossing boundaries like database, code logic, and absin...
New
stevensonmt
Has anyone else ever wanted to merge two maps, but have the resulting map only include keys common to both maps? I think of it as analogo...
New
AstonJ
@Garrison’s comment in another thread reminded me of this post by Joe: With the big five exerting more control than ever, new (AI) play...
New
Sergiusz
Hello everyone, I don’t know if my post is appropriate. If it isn’t, you can delete it. After a year of designing and defining the requ...
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
dogweather
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 ga...
New
bartblast
I recently started a discussion about reactive patterns in Hologram, but I realized I need to step back and design the composability arch...
New
gushonorato
Hey everyone, I’ve been working with Elixir for over 5 years and I’m a big enthusiast of the language. However, when starting new projec...
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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement