dkarter

dkarter

I’m working on a new project and trying to be very thoughtful about both the boundaries of my API and about reducing transitive compile dependencies (if that’s the correct terminology for this).

I read somewhere that one useful way to check for compile dependencies is:

mix xref graph --label compile-connected --fail-above 0

However it is failing under the following conditions:

I have 3 modules

MyApp.Schemas.AccountSchema
MyApp.Schemas.InstallRequestSchema
MyApp.Schemas.Base

MyApp.Schemas.Base is a __using__ macro used to set a bunch of repetitive settings that are shared between schemas such as binary ids, timestamp formats etc. It looks like this:

defmodule MyApp.Schemas.Base do
  @moduledoc false

  defmacro __using__(_opts) do
    quote do
      use Ecto.Schema

      @foreign_key_type :binary_id
      @primary_key {:id, :binary_id, read_after_writes: true}
      @schema_prefix unquote(MyApp.Repos.Local.prefix())
      @timestamps_opts [type: :utc_datetime_usec]
    end
  end
end

Which I then “use” in my schemas:

defmodule MyApp.Schemas.AccountSchema do
  use MyApp.Schemas.Base
  import Ecto.Changeset
  # etc...
end

When running the xref check I get the following output:

❯ mix xref graph --label compile-connected --fail-above 0
lib/my_app/schemas/account_schema.ex
└── lib/my_app/schemas/base.ex (compile)
lib/my_app/schemas/install_request_schema.ex
└── lib/my_app/schemas/base.ex (compile)

This output makes sense to me.. but I wonder if there’s any to avoid this around it, or at the very least a way to tell xref command to exclude this particular module (without increasing the --fail-above counter which is error prone).

Or maybe I’m just thinking about this all wrong…

Anyway I’m hoping someone has bumped into this before and can share their insights.

First 2 of 2 Posts Switch mode

dkarter

dkarter OP

This appears to be the offending line

@schema_prefix unquote(MyApp.Repos.Local.prefix())

Once I changed that to a static string the issue was resolved

@schema_prefix "my_app"

I’m still trying to figure out why that was the case :thinking:

al2o3cr

al2o3cr

compile-connected is looking for transitive compile-time dependencies; when Base has this line:

@schema_prefix unquote(MyApp.Repos.Local.prefix())

then every module that does use MyApp.Schemas.Base gets a compile-time dependency on Base (naturally) and transitively also on MyApp.Repos.Local.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement