Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Phoenix Upgrade Instructions 0.8.x to 0.9.0

Endpoint

Plug.Static added an :only option which greatly improves performance by skipping disk reads at runtime. Replace your Plug.Static lines in endpoint.ex with the following configuration:

  plug Plug.Static,
    at: "/", from: :my_app,
    only: ~w(css images js favicon.ico robots.txt)

Router / Controller

The destroy action has been renamed to delete, update your controller actions and url builders accordingly.

Channels

Update your phoenix.js file

Before you forget, be sure to update your vendored phoenix.js file with the new version: phoenix.js

Update your {:error, ... return signatures

The error return signature has been changed from {:error, socket, reason} to {:error, reason, socket}

Update your broadcasting

Broadcasting outside of a channel or without the context of a socket, now requires calling broadcast on your Endpoint module:

0.8.x:

Phoenix.Channel.broadcast("rooms:123", "new:msg", %{...})

0.9.0:

MyApp.Endpoint.broadcast("rooms:123", "new:msg", %{...})

It is also recommended to transition all your broadcast calls to broadcast!. The non-raising API still works, but broadcast! is reccomended for most channels so an exception is raised if the PubSub adapter is unable to deliver the message.

      def handle_in("new:msg", %{"uid" => uid, "body" => body}, socket) do
        broadcast! socket, "new:msg", %{uid: uid, body: body}
        {:ok, socket}
      end

PubSub

The new PubSub system allows third-party pubsub adapters and now includes a Redis adapter for multinode pubsub without distributed Elixir for hosts like Heroku. The PubSub adapter must now be specified in your Endpoint configuration.

Configuration for existing <= 0.8 PG2 setups

To continue to use the PG2 setup (which is still the default), simply add the following child to your config.exs file:

      config :my_app, MyApp.Endpiont,
        ...
        pubsub: [adapter: Phoenix.PubSub.PG2]

Configuration for the new Redis adapter

If you'd like to use the new redis adapter instead, simply add the following to your config.exs file, and update your deps:

With localhost redis and no auth:

      config :my_app, MyApp.Endpiont,
        ...
        pubsub: [adapter: Phoenix.PubSub.Redis]

With explicit host and auth:

      config :my_app, MyApp.Endpiont,
        ...
        pubsub: [adapter: Phoenix.PubSub.Redis,
                 options: [host: "182.168.100.1", port: 1234, password: "secret"]

next, add :eredis, and :poolboy to your deps:

      defp deps do
        [{:eredis, github: "wooga/eredis"},
         {:poolboy, "~> 1.4.2"},
        ...]
      end

finally, add :poolboy to your applications:

      def application do
        [mod: {MyApp, []},
         applications: [..., :phoenix, :poolboy],
         ...]
      end

If you were ever calling the Phoenix.PubSub API directly, you will now need to provide the PubSub adapter's registered server name to all calls. The default pubsub server name when your Endpoint starts the adapter is inflected from the base module name, ie:

Phoenix.PubSub.subscribe(MyApp.PubSub, self, "foo:bar")
Phoenix.PubSub.broadcast(MyApp.PubSub, "foo:bar", %{baz: :bang})

Plug/CSRF

Plug.CSRFProtection & :protect_from_forgery now uses a cookie instead of session and expects a "_csrf_token" parameter instead of "csrf_token".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment