Skip to content

Instantly share code, notes, and snippets.

@smpallen99
Last active August 4, 2016 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smpallen99/ae80753a5cdea5d20a1c03639b9a801e to your computer and use it in GitHub Desktop.
Save smpallen99/ae80753a5cdea5d20a1c03639b9a801e to your computer and use it in GitHub Desktop.

Coherence 0.2.0 to 0.3.0 Upgrade Instructions

Update your Coherence deps

def deps do
  [{:coherence, "~> 0.3.0"},
  ...]
end

Now update your coherece deps to get the latest version:

$ mix deps.update coherence

Update your web/router.ex:

Coherence has moved away from recommeding that the :browser pipeline be used for protected resources to unprotected resources.

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
    plug Coherence.Authentication.Session    # remove the , login: true
  end

Coherence starts using the keyword :protecte for resources requiring authentication. So change the :public pipeline to:

  pipeline :protected do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
    plug Coherence.Authentication.Session, protected: true  # note that protected: true change here
  end

Change the two coherence routes scope blocks:

  scope "/" do
    pipe_through :browser
    coherence_routes       # :public has been deprecated and the default is not public routes
  end
  scope "/" do
    pipe_through :protected
    coherence_routes :protected
  end

or if you are using generated Coherence controllers:

  scope "/", MyProject do
    pipe_through :browser
    coherence_routes
  end
  scope "/", MyProject do
    pipe_through :protected
    coherence_routes :protected
  end

And, finally, add your unprotected routes blocks to use the :browser pipeline and your protected routes to use the :protected pipeline:

  scope "/", MyProject do
    pipe_through :browser
    get "/", PageController, :index
  end

  scope "/", MyProject do
    pipe_through :protected
    resources "/posts", PostController
    resources "/users", UserController
  end

Update the :confirmed_send_at column

If you project has enabled the confirmable option, then you will need to update your database schema for the name change.

Create a new migration:

$ mix ecto.gen.migration alter_confirmation_send_at
* creating priv/repo/migrations
* creating priv/repo/migrations/20160804011958_alter_confirmation_send_at.exs

Edit the miration file:

defmodule MyProject.Repo.Migrations.AlterConfirmationSendAt do
  use Ecto.Migration

  def change do
    rename table(:users), :confirmation_send_at, to: :confirmation_sent_at
  end
end

Run the migration:

$ mix ecto.migrate

Update your generated files

There have been a number of changes to the controllers and the view helpers. You may want to rerun the installer and select yes for the files that you want to replace. If your code is commited to git before you run the installer again, you can aways do a git checkout file to restore any file changes you don't want to keep.

Test it

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