Custom Ecto Table Names

16d
I have a problem with table naming in Ecto…

I have many different Bounded Contexts in my app.

Each Bounded Context has it’s own Repo and Repo Config (although they may point to the same database).

Some Schema (and therefore tables) are in different Bounded Contexts but have the same name, e.g. Web.

I am trying to find the right way to rename my tables to be prefixed with the Bounded Context they are in. e.g. inter_web, spider_web,

However, my Repos already use a prefix for Tenanting.

I know that I could pass a tuple like {“inter_web”, Web} in place of a Schema, but I was wondering if I’ve missed anything obvious or anyone could provide a better solution?

Thanks

I am trying to find the right way to rename my tables to be prefixed with the Bounded Context they are in. e.g. inter_web, spider_web,

You can create migrations to rename the tables and then use the new names in your ecto schemas.

use Ecto.Schema
schema "inter_web" do
  # ...
end

Just a friendly heads up. This post seems to be in the wrong category. This would probably be a better fit for Questions/Help rather than Adoption & Media.

2 Likes