class DataForLicenseTypes < ActiveRecord::Migration
  def up
    License.find('by').update_attributes(license_type: 'cc')
    License.find('by-sa').update_attributes(license_type: 'cc')
    License.find('by-nd').update_attributes(license_type: 'cc')
    License.find('by-nc').update_attributes(license_type: 'cc')
    License.find('by-nc-sa').update_attributes(license_type: 'cc')
    License.find('by-nc-nd').update_attributes(license_type: 'cc')
    License.find('cc-sample').update_attributes(license_type: 'cc')

    License.find('public').update_attributes(license_type: 'public')
    License.find('copyright').update_attributes(license_type: 'copyright')

    License.find('gpl').update_attributes(license_type: 'gpl')
    License.find('gpl-v2').update_attributes(license_type: 'gpl')
    License.find('gpl-v3').update_attributes(license_type: 'gpl')
    License.find('copyleft').update_attributes(license_type: 'gpl')
  end

  def down
    # do nothing, when rolling back the next migration erases the column
  end
end

class DataForLicenseTypes < ActiveRecord::Migration
  def up
    ['by', 'by-sa', 'by-nd', 'by-nc', 'by-nc-sa', 'by-nc-nd', 'cc-sample'].each do |l|
      License.where(short_name: l).try(:update_attributes, license_type: 'cc')
    end

    License.where(short_name: 'public').try(:update_attributes, license_type: 'public')
    License.where(short_name: 'copyright').try(:update_attributes, license_type: 'copyright')

    ['gpl', 'gpl-v2', 'gpl-v3', 'copyleft'].each do |l|
      License.where(short_name: l).try(:update_attributes, license_type: 'gpl')
    end
  end

  def down
    # do nothing, when rolling back the next migration erases the column
  end
end

Correct migration so it won't fail when db is empty
Correct migration so it won't fail when db is empty
