dkarter

dkarter

Transitive compile dependencies question

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.

Marked As Solved

dkarter

dkarter

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:

Also Liked

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.

Where Next?

Popular in Questions Top

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
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement