Skip to content

Instantly share code, notes, and snippets.

@moll
Created September 2, 2013 21:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moll/6417606 to your computer and use it in GitHub Desktop.
Save moll/6417606 to your computer and use it in GitHub Desktop.
Because Devise 3 (and/or Warden) changed the signature of the session info, all sessions were invalidated and thereby people logged out. You do *not* log people out unless they ask for it. Capisce? This migration migrates migraines by migrating those sessions. Replace the word "account" and "Account" if your account model isn't named Account, bu…
class MigrateSessionsToDevise3 < ActiveRecord::Migration
class Session < ActiveRecord::Base
attr_protected
serialize :data, JSON
end
def up
Session.find_each do |session|
warden = session.data["warden.user.account.key"]
next unless warden
next unless warden[0] == "Account"
warden.shift
session.data["warden.user.account.key"] = warden
session.update_column(:data, JSON.dump(session.data))
end
end
def down
Session.find_each do |session|
warden = session.data["warden.user.account.key"]
next unless warden
next if warden[0] == "Account"
warden.unshift "Account"
session.data["warden.user.account.key"] = warden
session.update_column(:data, JSON.dump(session.data))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment