How to change field type in Ecto?
You have to use modify/3 to change the type. add/3 is only for adding new columns. alter table(:editables) do modify :content, :binary end
You have to use modify/3 to change the type. add/3 is only for adding new columns. alter table(:editables) do modify :content, :binary end
Put a file in your test directory somewhere (maybe test/fixtures) then use the Plug.Upload struct: upload = %Plug.Upload{path: “test/fixtures/example.png”, filename: “example.png”} conn() |> post(“/api/v1/originals”, %{ :image => upload })
Yep! Make sure you set the mix config to reference the env port, i.e. config :my_app, MyApp.Endpoint, http: [port: {:system, “PORT”}], Then from the terminal: $ PORT=4001 mix phoenix.server $ PORT=4002 mix phoenix.server $ PORT=4003 mix phoenix.server
This is an interesting problem because you need to perform multiple checks, exit early, and in the process transform some state (connection). I typically approach this problem as follows: I implement each check as a function which takes state as an input and returns {:ok, new_state} or {:error, reason}. Then, I build a generic function … Read more
This is an old question and the previously accepted answer was no longer the de facto way. Ecto now supports HABTM or many to many associations. https://hexdocs.pm/ecto/Ecto.Schema.html#many_to_many/3 many_to_many :users, MyApp.User, join_through: “chat_group_users”
The options that Dogbert has provided are both correct and should be used for Ecto 1.x. In Ecto 2.0 you can use Repo.aggregate/4 Repo.aggregate(Post, :count, :id)
String.trim/1 seems to do the trick as of Elixir 1.3.0. strip still works, but it was soft deprecated in the 1.3.0 release and it isn’t listed in the String docs.
Mix.env() doesn’t work in production or other environments where you use compiled releases (built using Exrm / Distillery) or when Mix just isn’t available. The solution is to specify it in your config/config.exs file: config :your_app, env: Mix.env() You can then get the environment atom in your application like this: Application.get_env(:your_app, :env) #=> :prod Update … Read more
The error you get is from the underlying database where the column type is set to varchar which is what’s created by default when you specify the column type as string in a migration. To store a variable length string over 255 characters, you need to specify the column type as text in the migration. … Read more
I’m not sure when this was added to Ecto, but at least in 2.1.6 there’s no need for raw SQL anymore. drop/1 now supports constraints (drop_if_exists/1 doesn’t though): def up do drop constraint(:videos, “videos_user_id_fkey”) alter table(:videos) do modify :user_id, references(:users, on_delete: :delete_all) end end def down do drop constraint(:videos, “videos_user_id_fkey”) alter table(:videos) do modify :user_id, … Read more