Sha256: 6eaf8275337d430d37543085b080e454c486db93bb43998d58a1972b1b05c43a

Contents?: true

Size: 698 Bytes

Versions: 20

Compression:

Stored size: 698 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

20 entries across 20 versions & 1 rubygems

Version Path
card-1.105.6 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.105.5 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.105.4 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.105.3 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.105.2.pre1 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.105.2 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.105.1 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.105.0 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.104.2 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.104.1 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.104.0 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.103.4 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.103.3 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.103.2 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.103.1 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.103.0 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.101.7 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.102.0 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.101.6 db/migrate_core_cards/20191115160748_history_cleanup.rb
card-1.101.5 db/migrate_core_cards/20191115160748_history_cleanup.rb