2017-08-31 12:06:56 +08:00
|
|
|
class AddUserAvatars < ActiveRecord::Migration[4.2]
|
2014-05-26 17:46:43 +08:00
|
|
|
def up
|
2014-05-22 15:37:02 +08:00
|
|
|
create_table :user_avatars do |t|
|
|
|
|
t.integer :user_id, null: false
|
|
|
|
t.integer :system_upload_id
|
|
|
|
t.integer :custom_upload_id
|
|
|
|
t.integer :gravatar_upload_id
|
|
|
|
t.datetime :last_gravatar_download_attempt
|
2017-08-07 23:48:36 +08:00
|
|
|
t.timestamps null: false
|
2014-05-22 15:37:02 +08:00
|
|
|
end
|
2014-05-26 17:46:43 +08:00
|
|
|
|
|
|
|
add_index :user_avatars, [:user_id]
|
|
|
|
|
|
|
|
execute <<SQL
|
|
|
|
INSERT INTO user_avatars(user_id, custom_upload_id)
|
|
|
|
SELECT id, uploaded_avatar_id
|
|
|
|
FROM users
|
|
|
|
SQL
|
2014-05-27 12:45:20 +08:00
|
|
|
|
|
|
|
execute <<SQL
|
|
|
|
UPDATE users SET uploaded_avatar_id = NULL
|
|
|
|
WHERE NOT use_uploaded_avatar
|
|
|
|
SQL
|
|
|
|
|
|
|
|
# NOTE we should nuke use_uploaded_avatar later on
|
2014-05-26 17:46:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
drop_table :user_avatars
|
2014-05-22 15:37:02 +08:00
|
|
|
end
|
|
|
|
end
|