Sha256: 2979e7126cc7c9ea64837704fbde34e31db16d3b86146a27a86925f4030805e9

Contents?: true

Size: 805 Bytes

Versions: 5

Compression:

Stored size: 805 Bytes

Contents

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

class UpdateFileHistory < Cardio::Migration::Core
  def up
    Card.search(type: [:in, "file", "image"]).each do |card|
      card.actions.each do |action|
        next unless (content_change = action.change :db_content)
        next if content_change.new_record?
        original_filename, file_type, action_id, mod = content_change.value.split("\n")
        next unless file_type.present? && action_id.present?
        value =
          if mod.present?
            ":#{card.codename}/#{mod}#{::File.extname(original_filename)}"
          else
            "~#{card.id}/#{action_id}#{::File.extname(original_filename)}"
          end
        content_change.update! value: value
      end
    end
    Card.search(right: { codename: "machine_output" }).each(&:delete!)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
card-1.101.4 db/migrate_core_cards/20150824135418_update_file_history.rb
card-1.101.3 db/migrate_core_cards/20150824135418_update_file_history.rb
card-1.101.2 db/migrate_core_cards/20150824135418_update_file_history.rb
card-1.101.1 db/migrate_core_cards/20150824135418_update_file_history.rb
card-1.101.0 db/migrate_core_cards/20150824135418_update_file_history.rb