Various updates to the user management, including the creation of a
preferences table and moving tokens into a tokens table so that a user can have more than one.
This commit is contained in:
parent
b61e4f77e8
commit
0a8c26e596
11 changed files with 151 additions and 74 deletions
58
db/migrate/004_user_enhancements.rb
Normal file
58
db/migrate/004_user_enhancements.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
class UserEnhancements < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column "diary_entries", "latitude", :double
|
||||
add_column "diary_entries", "longitude", :double
|
||||
add_column "diary_entries", "language", :string, :limit => 3
|
||||
|
||||
create_table "user_preferences", innodb_table do |t|
|
||||
t.column "user_id", :bigint, :limit => 20, :null => false
|
||||
t.column "k", :string, :null => false
|
||||
t.column "v", :string, :null => false
|
||||
end
|
||||
|
||||
add_primary_key "user_preferences", ["user_id", "k"]
|
||||
|
||||
create_table "user_tokens", innodb_table do |t|
|
||||
t.column "id", :bigint, :limit => 20, :null => false
|
||||
t.column "user_id", :bigint, :limit => 20, :null => false
|
||||
t.column "token", :string, :null => false
|
||||
t.column "expiry", :datetime, :null => false
|
||||
end
|
||||
|
||||
add_primary_key "user_tokens", ["id"]
|
||||
add_index "user_tokens", ["token"], :name => "user_tokens_token_idx", :unique => true
|
||||
add_index "user_tokens", ["user_id"], :name => "user_tokens_user_id_idx"
|
||||
|
||||
change_column "user_tokens", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
|
||||
|
||||
User.find(:all, :conditions => "token is not null").each do |user|
|
||||
UserToken.create(:user_id => user.id, :token => user.token, :expiry => 1.week.from_now)
|
||||
end
|
||||
|
||||
remove_column "users", "token"
|
||||
remove_column "users", "timeout"
|
||||
remove_column "users", "within_lon"
|
||||
remove_column "users", "within_lat"
|
||||
add_column "users", "nearby", :integer, :default => 50
|
||||
add_column "users", "pass_salt", :string
|
||||
|
||||
User.update_all("nearby = 50");
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column "users", "pass_salt"
|
||||
remove_column "users", "nearby"
|
||||
add_column "users", "within_lat", :double
|
||||
add_column "users", "within_lon", :double
|
||||
add_column "users", "timeout", :datetime
|
||||
add_column "users", "token", :string
|
||||
|
||||
drop_table "user_tokens"
|
||||
|
||||
drop_table "user_preferences"
|
||||
|
||||
remove_column "diary_entries", "language"
|
||||
remove_column "diary_entries", "longitude"
|
||||
remove_column "diary_entries", "latitude"
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue