Added export migration task.

This commit is contained in:
Eugene Burmakin 2025-04-06 16:31:39 +02:00
parent 92e1cbec84
commit 50144fddf2
5 changed files with 33 additions and 3 deletions

View file

@ -46,11 +46,14 @@ In this release we're changing the way import files are being stored. Previously
This is an optional task, that will not affect your points or other data. This is an optional task, that will not affect your points or other data.
Big imports might take a while to migrate, so be patient. Big imports might take a while to migrate, so be patient.
Also, you can now migrate existing exports to the new storage using the `rake exports:migrate_to_new_storage` task (in the container shell) or just delete them.
If your hardware doesn't have enough memory to migrate the imports, you can delete your imports and re-import them. If your hardware doesn't have enough memory to migrate the imports, you can delete your imports and re-import them.
## Added ## Added
- Sentry is now can be used for error tracking. - Sentry is now can be used for error tracking.
- Subscription management is now available in non self-hosted mode.
## Changed ## Changed

View file

@ -2,6 +2,7 @@
class AppVersionCheckingJob < ApplicationJob class AppVersionCheckingJob < ApplicationJob
queue_as :default queue_as :default
sidekiq_options retry: false
def perform def perform
Rails.cache.delete(CheckAppVersion::VERSION_CACHE_KEY) Rails.cache.delete(CheckAppVersion::VERSION_CACHE_KEY)

View file

@ -17,9 +17,22 @@ class Export < ApplicationRecord
Exports::Create.new(export: self).call Exports::Create.new(export: self).call
end end
def migrate_to_new_storage
file.attach(io: File.open("public/#{url}"), filename: name)
update!(url: nil)
File.delete("public/#{url}")
rescue StandardError => e
Rails.logger.debug("Error migrating export #{id}: #{e.message}")
end
private private
def remove_attached_file def remove_attached_file
file.purge_later file.purge_later
File.delete("public/#{url}")
rescue StandardError => e
Rails.logger.debug("Error removing export #{id}: #{e.message}")
end end
end end

View file

@ -41,10 +41,10 @@
<td><%= export.status %></td> <td><%= export.status %></td>
<td> <td>
<% if export.completed? %> <% if export.completed? %>
<% if export.url.present? %> <% if export.file.present? %>
<%= link_to 'Download', export.url, class: "px-4 py-2 bg-blue-500 text-white rounded-md", download: export.name %> <%= link_to 'Download', rails_blob_path(export.file, disposition: 'attachment'), class: "px-4 py-2 bg-blue-500 text-white rounded-md", download: export.name %>
<% else %> <% else %>
<%= link_to 'Download', export.file.url, class: "px-4 py-2 bg-blue-500 text-white rounded-md", download: export.name %> <%= link_to 'Download', export.url, class: "px-4 py-2 bg-blue-500 text-white rounded-md", download: export.name %>
<% end %> <% end %>
<% end %> <% end %>
<%= link_to 'Delete', export, data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?", turbo_method: :delete }, method: :delete, class: "px-4 py-2 bg-red-500 text-white rounded-md" %> <%= link_to 'Delete', export, data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?", turbo_method: :delete }, method: :delete, class: "px-4 py-2 bg-red-500 text-white rounded-md" %>

13
lib/tasks/exports.rake Normal file
View file

@ -0,0 +1,13 @@
# frozen_string_literal: true
namespace :exports do
desc 'Migrate existing exports from file system to the new file storage'
task migrate_to_new_storage: :environment do
Export.find_each do |export|
export.migrate_to_new_storage
rescue StandardError => e
puts "Error migrating export #{export.id}: #{e.message}"
end
end
end