Repository navigation
How To: Upgrade to Devise 2.0 migration schema style
josevalim edited this page Dec 5, 2011
·
8 revisions
Since Devise 2.0, it no longer includes helpers for your migrations. Instead, it simply lists the database fields explicitly. This page shows the before and after of the migrations so you can easily compare and update your code.
create_table(TABLE_NAME) do |t| t.database_authenticatable :null => false t.recoverable t.rememberable t.trackable # t.encryptable # t.confirmable # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both # t.token_authenticatable end
create_table(TABLE_NAME) do |t| ## Database authenticatable t.string :email, :null => false t.string :encrypted_password, :null => false ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable t.integer :sign_in_count t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip t.string :last_sign_in_ip ## Encryptable # t.string :password_salt ## Confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at # Token authenticatable # t.string :authentication_token end
Before Devise 2.0, Devise automatically configured your MongoDB. This is no longer true. In order to upgrade, you need to set Devise.apply_schema to false and add the following to your model according to the strategies you are using:
## Database authenticatable field :email, :type => String, :null => false field :encrypted_password, :type => String, :null => false ## Recoverable field :reset_password_token, :type => String field :reset_password_sent_at, :type => Time ## Rememberable field :remember_created_at, :type => Time ## Trackable field :sign_in_count, :type => Integer field :current_sign_in_at, :type => Time field :last_sign_in_at, :type => Time field :current_sign_in_ip, :type => String field :last_sign_in_ip, :type => String ## Encryptable # field :password_salt, :type => String ## Confirmable # field :confirmation_token, :type => String # field :confirmed_at, :type => Time # field :confirmation_sent_at, :type => Time # field :unconfirmed_email, :type => String # Only if using reconfirmable ## Lockable # field :failed_attempts, :type => Integer # Only if lock strategy is :failed_attempts # field :unlock_token, :type => String # Only if unlock strategy is :email or :both # field :locked_at, :type => Time # Token authenticatable # field :authentication_token, :type => String