diff --git a/db/migrate/20210204114922_add_default_avatar.rb b/db/migrate/20210204114922_add_default_avatar.rb new file mode 100644 index 0000000..968058b --- /dev/null +++ b/db/migrate/20210204114922_add_default_avatar.rb @@ -0,0 +1,14 @@ +class AddDefaultAvatar < ActiveRecord::Migration[6.0] + def up + User.all.each do |user| + next if user.avatar.attached? + + user.avatar.attach( + io: File.open( + Rails.root.join('app/assets/images/default_avatar.png') + ), filename: 'default_avatar.png', content_type: 'image/png' + ) + user.save + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 61c27a8..61479fc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_02_02_132517) do +ActiveRecord::Schema.define(version: 2021_02_04_114922) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false