2014-05-22 03:37:02 -04:00
|
|
|
class AddUserAvatars < ActiveRecord::Migration
|
2014-05-26 05:46:43 -04:00
|
|
|
def up
|
2014-05-22 03:37:02 -04: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 11:48:36 -04:00
|
|
|
t.timestamps null: false
|
2014-05-22 03:37:02 -04:00
|
|
|
end
|
2014-05-26 05:46:43 -04: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 00:45:20 -04: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 05:46:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
drop_table :user_avatars
|
2014-05-22 03:37:02 -04:00
|
|
|
end
|
|
|
|
end
|