Sha256: 422aa7775cff22bc91859658e7d3cdd9ca8331edcb9d40b9321c27a827968c8b

Contents?: true

Size: 699 Bytes

Versions: 5

Compression:

Stored size: 699 Bytes

Contents

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

class HistoryCleanup < Cardio::Migration

  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

5 entries across 5 versions & 1 rubygems

Version Path
card-1.101.4 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.101.3 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.101.2 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.101.1 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.101.0 db/migrate_core_cards/20191115160748_history_cleanup.rb