Define a macro which will expand to add schema

I am working on an independent umbrella app(which might later become library) in which I had to tell user schema and association dynamically from other(data) app. How can I pass data app association dynamically and independently so that same codebase can be used anywhere else.

schema "roles" do
 many_to_many(:user_roles, @user_role_schema, join_through: "users_roles")

somehow user_role_schema have to be passed and configured dynamically after data app load


I have also tried writing macros for these schemas but schema macro of Ecto wont expand and add fields. if there is a way to expand macro and add all the fields without defining all fields that would be awesome. I would write macros and just pass user schema or other schemas when using that macro and it should expand and add all the fields

1 Like

If you make a small GitHub repo I’m willing to try and help you.