Sha256: 3fb648e08aa0ff8816e4427f10b8e21f84deb334ae63bb0894b22d1e428abb77

Contents?: true

Size: 709 Bytes

Versions: 4

Compression:

Stored size: 709 Bytes

Contents

# -*- encoding : utf-8 -*-

class HistoryCleanup < Cardio::Migration::Transform
  def up
    delete_create_only_changes
  end

  # actions on cards where the create is the _ONLY_ action should not have
  # card_changes
  def delete_create_only_changes
    create_only_actions.pluck(:id).each_slice(200) do |action_ids|
      Card.connection.execute(
        "DELETE from card_changes where card_action_id in (#{action_ids.join ', '})"
      )
    end
  end

  def create_only_actions
    Card::Action.where(%{
      action_type = 0
      AND NOT EXISTS (select * from card_actions ca1
                      where card_actions.card_id = ca1.card_id
                      and action_type <> 0)
    })
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
card-1.108.1 mod/core/data/transform/20191115160748_history_cleanup.rb
card-1.108.0 mod/core/data/transform/20191115160748_history_cleanup.rb
card-1.107.0 mod/core/data/transform/20191115160748_history_cleanup.rb
card-1.106.0 mod/core/data/transform/20191115160748_history_cleanup.rb