2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-30 23:06:56 -05:00
|
|
|
class AddUserAvatars < ActiveRecord::Migration[4.2]
|
2014-05-26 04:46:43 -05:00
|
|
|
def up
|
2014-05-22 02:37:02 -05: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 10:48:36 -05:00
|
|
|
t.timestamps null: false
|
2014-05-22 02:37:02 -05:00
|
|
|
end
|
2014-05-26 04:46:43 -05: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-26 23:45:20 -05: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 04:46:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
drop_table :user_avatars
|
2014-05-22 02:37:02 -05:00
|
|
|
end
|
|
|
|
end
|