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
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
Finalize in db
Other
Advanced, Default to Binary_ID
BinaryID is uuid letting you generate ids on the client
Config.exs
Last updated