Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
1.1 KB
Raw Blame
# frozen_string_literal: true

# Workers can run alongside db:prepare. Do not enqueue this refresh from the
# October price correction: device_id and session_expires_at do not exist yet.
# Refresh all linked portfolios once, including installations that already ran
# the correction (or whose earlier refresh failed). The old migration did not
# persist the affected item IDs, and corrected prices cannot identify them now.
class RefreshTradeRepublicBalancesAfterBondRescale < ActiveRecord::Migration[8.1]
  # This migration only schedules refreshes. Commit each item inside the rescue
  # so an after-commit enqueue failure cannot abort the entire migration.
  disable_ddl_transaction!

  def up
    TradeRepublicItem.reset_column_information
    item_ids = TradeRepublicAccount.where(kind: "portfolio").joins(:account_provider).select(:trade_republic_item_id)

    TradeRepublicItem.syncable.where(id: item_ids).find_each do |item|
      item.sync_later
    rescue => e
      say "Could not schedule a sync for Trade Republic item #{item.id} (#{e.message}); it refreshes on its next sync"
    end
  end

  def down
    # A refresh does not need to be undone.
  end
end