[Docker] Add seeding for mascots

Will only work after deploy, because of the added field in the API response
This commit is contained in:
Earlopain 2022-10-20 18:52:07 +02:00
parent 0de7135df9
commit cc2a395b37
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
2 changed files with 21 additions and 0 deletions

View File

@ -81,5 +81,9 @@ class Mascot < ApplicationRecord
q.order("lower(artist_name)")
end
def method_attributes
super + [:url_path]
end
include FileMethods
end

View File

@ -73,8 +73,25 @@ def import_posts
end
end
def import_mascots
api_request("/mascots.json").each do |mascot|
puts mascot["url_path"]
Mascot.create!(
creator: CurrentUser.user,
mascot_file: Downloads::File.new(mascot["url_path"]).download!,
display_name: mascot["display_name"],
background_color: mascot["background_color"],
artist_url: mascot["artist_url"],
artist_name: mascot["artist_name"],
safe_mode_only: mascot["safe_mode_only"],
active: mascot["active"],
)
end
end
unless Rails.env.test?
CurrentUser.user = admin
CurrentUser.ip_addr = "127.0.0.1"
import_posts
import_mascots
end