I have already created a User Model using devise, but I now want to add support for token_authenticable, so I need to migrate these additions. Is the following correct, and what type should token_authenticatable be?
class AddAuthenticationTokenToUser < ActiveRecord::Migration
def change
add_column :users, :token_authenticatable
add_index :users, :authentication_token, :unique => true
end
end
From the devise 2.0 generator (line 74) on Github:
# t.string :authentication_token
If you are going to be looking up a user based on their token, then adding an index is a good idea.
Here is the devise 1.5 file
add_column :users, :token_authenticatable, :string
Don't forget to add devise :token_authenticatable
to your user model.
The full list of deleted helpers for migrations in devise 2 is as follows:
create_table(TABLE_NAME) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
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
## Invitable
# t.string :invitation_token
t.timestamps
end
Taken from the devise wiki
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With