I’ve been wanting to solve the upload migration problem for just about forever, and now with LLM help have gotten there. Sharing my notes for those who follow! Jay’s post above contained the special sauce needed to get me started so thanks for that.
My first pass at this worked exactly as Jay predicted. If you create a list of urls to the images on the site you are moving from and paste that into a post on your new site, they will be downloaded. Download remote images to local must be enabled for this to work.
My LLM created a script for that which I’ll share here for future travelers.
Summary
Run this in the rails console:
topic = Topic.find(=TOPIC_ID=)
posts = Post.where(topic_id: topic.id)
urls = []
posts.each do |p|
UploadReference.where(target: p).each do |ref|
urls << "=SOURCE_URL=#{ref.upload.url}"
end
end
puts urls.uniq.join("\n")
puts "\nTotal: #{urls.uniq.count} upload(s)"
Moving a whole category instead? Replace the first two lines with:
topic_ids = Topic.where(category_id: =TOPIC_ID=).pluck(:id) posts = Post.where(topic_id: topic_ids)In this case =TOPIC_ID= is your category ID, found at the end of its URL in Admin → Categories.
However for me that ended up not being good enough because I also have PDFs which do not get downloaded to local automatically.
So I had my LLM write me a python script to migrate the uploads. It works quite well so happy to share it as well. If you’d like to try it or have feedback, here’s the repo: tobias/discourse-upload-migrator - Digitally Sovereign Forgejo: Digitally Sovereign, for the win!
I also had my LLM write me a more complete runbook on moving topics or categories, which is up on my discourse: https://digitallysovereign.org/t/move-topics-or-categories-between-discourse-instances/742?u=tobias