Skip to content

Instantly share code, notes, and snippets.

@smpallen99
Last active September 9, 2018 21:57
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/fc59423d521f7f6773a5fa9236512faf to your computer and use it in GitHub Desktop.
Save smpallen99/fc59423d521f7f6773a5fa9236512faf to your computer and use it in GitHub Desktop.
Coherence 0.5.x to 0.6.0 Upgrade Instructions

Coherence 0.5.x to 0.6.0 Upgrade Instructions

Upgrade your generated Controllers

Coherence 0.6.0 introduces a new controller design that splits each controller into 2 files:

  • Coherence.xxxControllerBase contains all the functions previously found in Coherence.xxxController
    • The new functions are wrapped in a using macro, with one mandatory option. The schemas option specifies the name of your projects Schemas module.
    • All functions are overridable
    • All private functions have been made public to support overriding
  • Coherence.xxxController contains only a few lines, as shown by the following example:
defmodule MyAppWeb.Coherence.SessionController do
  @moduledoc """
  Handle the authentication actions.

  Module used for the session controller when the parent project does not
  generate controllers. Most of the work is done by the
  `Coherence.SessionControllerBase` inclusion.
  """
  use CoherenceWeb, :controller
  use Coherence.SessionControllerBase, schemas: MyApp.Coherence.Schemas

  plug :layout_view, view: Coherence.SessionView, caller: __MODULE__
  plug :redirect_logged_in when action in [:new, :create]
end

The following procedure is recommented to upgrade your project:

  • BEFORE doing the mix deps.update coherence do the following:
    • run mix coh.gen.controllers and overwrite the controllers
    • run git diff and review the customization
    • save the results of the diff for later reference
  • Run mix deps.update coherence to upgrade to v0.6.0 (may require changing the vesion in mix.exs first)
  • Run mix coh.install --reinstall and overwrite desired files
  • Run mix coh.gen.controllers to generate the controllers
  • Review each contoller that was previously customized and do the following:
    • Implement the customized actions in the newly genereated controllers
    • Use the base contoller base module as an example. It can be found in deps/coherence/lib/coherence/controllers/xxx_controller_base.ex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment