Export and Import tickets via rails

We are exploring the possibility to export all tickets from a deprecating instance and merge them into a brand new instance by utilizing the rails console (or the API). [Doing this is not encuraged afaik, but we unfortunatly need to dig into it]
We are not afraid of the manual migrations needed to achieve this! Thus, changing custom field names or other things (like new IDs, other customer IDs and so on) is of course our task, so this is not part of the question.
Our problem though: How can we export all information including raw eml files and importing them back via rails? Technically we could “simply” write all relevant infos about tickets and articles to a CSV file and then create new tickets and articles, but how would we export and import eml files and other attachments via rails (or if not feasible: via API)?
If this question is out of scope for the community, please advice as on how to get the information needed :slight_smile:

Hi @SePro ,

tickets can be found here:

ticket articles can be found here:

attachments are acessable via concern here:

All files are accessible and stored via the Store and Store::File model:

Here is a simple script to show tickets and their articles + attachment ids:

zammad run rails r test.rb

test.rb

Ticket.find_each do |ticket|
  ticket.articles.each do |article|
    puts "ticket #{ticket.id} - article #{article.id}"

    article.attachments.each do |attachment|
      puts "-> attachment #{attachment.id}"
    end
  end
end
1 Like