DavidVII

DavidVII

Hello, I’m curious about the reasoning behind prefixing the table names when creating a new resource via context generator. What would be the recommendation in the case that someone does what the docs refer to when mentioning that a resource may be a part of different contexts:

Note a resource may also be split over distinct contexts (such as Accounts.User and Payments.User).

What would be the recommended table name here? accounts_users or payments_users or something else?

I understand that you can change it, but being part of a generator somewhat implies that they want to drive the point that we should be thinking about things in terms of contexts and I’m curious what folks have to say about this.

Personally, I would just name my table users, but I’d like to hear from others and get a sense of the conversion.

Showing Posts 1 to 8

hubertlepicki

hubertlepicki

I is an opinionated decision of framework authors. The reasoning is that you keep your bounded contexts separated this way, also on database level. But you do not have to do it, I certainly don’t and do not feel bad about it :wink:

yurko

yurko

I’d do the same

Aetherus

Aetherus

Sounds like we can create a poll :grimacing:

By the way, I don’t add context prefix to table names, either.

wtd423

wtd423

Wouldn’t it be super annoying to keep a table for each context synced? At least I rather deal with NULLs on non-shared columns than update shared columns for each table.

jeremyjh

jeremyjh

If you are using Postgres you can use table inheritance.

minhajuddin

minhajuddin

I too name my tables without prefixes. I believe that contexts should not permeate into the database. So, I always use the --table option while generating models. One of us should send a PR which allows adding a --drop-table-prefix to the generator config (and adding it to the switches).

bglusman

bglusman

I’d second the general pattern of not having the context prefix on database column, but I still have some different schemas for each context… my understanding is this is half the purpose of contexts/ schemas as opposed to models, as each schema uses only the columns relevant to that context, but it doesn’t stop other contexts from having many of the same columns or having relations between columns… in the accounts_users and payments_users example, I’d imagine its still just a users table, but the payment context might have a credit_card_id foreign relation there, and the accounts section might have a profile_id, but payments doesn’t care about a profile and accounts doesn’t care about a credit card, so they don’t bother having in their seperate schemas, and therefore a) they can’t be used from there carelessly, and b) you save pulling that data from the DB on each load since the schema doesn’t know about it, so don’t have to select specific columns to get the savings… and if one table gets a ton of columns from a ton of different contexts, it will be pretty easy to avoid seeing the impact and bloat of that in any one context.

josevalim

josevalim

Creator of Elixir

We have reverted this behaviour in master. Phoenix v1.3 will no longer prefix tables: Keep table names simple · phoenixframework/phoenix@c335147 · GitHub

10
Post #8
— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews