Generators

Used as learning tools for both db as well as channel/migrations

mix phx.gen.context Analytics AIPrompt ai_prompts request:map respons:map prompt text cleaned_text

mix phx.gen.context Accounts MagicToken magic_tokens value user_id:references:users

mix phx.gen.json Lessons Lesson lessons owner_id:references:users title description

mix phx.gen.context Lessons Activity activities lesson_id:references:lessons title notes duration:float type type_data:map

mix phx.gen.context Lessons Activity_Transition activity_transitions

Examples

mix phx.gen.json Boards Board boards owner_id:references:users title description

mix phx.gen.context Templates Template templates event_id:references:events description preview

mix phx.gen.context Templates TemplateXTag templates_x_tags template_id:references:templates template_tag_id:references:template_tags

mix phx.gen.context Templates TemplateTag template_tags name
  • No :type means it is a :string, but use :text if >256 chars

  • Often need to modify schema to have belong_to/has_many/has_one

  • Need to change migration if id type is string or

General Usage

Generating a schema in increasing complexity

Types: :integer | :float |:decimal |:boolean |:map (Will convert to string keys)|:string(255 char limit use text instead) |{:array, :string} |:references |:text(In ecto schema still string type) |:date | :time |:time_usec |:naive_datetime |:naive_datetime_usec |:utc_datetime |:utc_datetime_usec |:uuid |:binary |:datetime

DataTime Types

Only difference is the conversion to elixir, same DB type

type
precision
Elixir type
timezone

naive_datetime

sec

None

naive_datetime_usec

microsec

None

utc_datetime

sec

UTC

utc_datetime_usec

microsec

UTC

Finalize in db

Other

Advanced, Default to Binary_ID

BinaryID is uuid letting you generate ids on the client

Config.exs

Last updated