Jsonb unstructured data with Ecto?

def MyApp.User do
  use MyApp.Web, :model 
  schema "users" do
    field :first_name, :string 
    field :last_name, :string 
    field :preferences, :map 
  end 
end

The problem is that preferences are different for each application that uses the users table. For example, mobile app A would want to store some mobile preference settings, while mobile app B would like to store its own settings. The user table is common to both. How do we model this?

One solution that comes to mind each mobile app would have its own structured data so changesets can be created. For example,

def MobileAppA do
  embedded_schema do
    ....copy all fields of MyApp.User schema over here again
   field :pref1, :string 
   field :pref2, :string 
  end
end

Now do validations on this schema and if everything passes, write to the DB. Do the same for mobileAppB.

However, the user schema fields are copied over and over again into each embedded schema.

To solve the repetition problem, we could define a macro just for the fields and use that macro everywhere we need to have those fields. Is this the best way? Any better way of doing this? This has got to be a common problem I would think. Wondering how others are approaching this problem. Thanks in advance!

What about ditching embed schemas, stuff it all into a completely unstructured field, and handle the differences in the applications themselves?

or maybe an embeds many in the user schema? This might help: https://robots.thoughtbot.com/embedding-elixir-structs-in-ecto-models

Why separate fields are not applicable here?

def MyApp.User do
  use MyApp.Web, :model 
  schema "users" do
    field :first_name, :string 
    field :last_name, :string 
    field :preferences_for_a_app, MobileAppA
    field :preferences_for_b_app, MobileAppB
  end
end

@astery - because user model should not know about any particular app - appA or appB or appZ. Its a unidirectional relationship only i.e user does not know anything about apps, but apps know about users.