Sha256: 79310b36526a957682ac349499c5fd085ac8452166f77fb6cac080245617f534

Contents?: true

Size: 801 Bytes

Versions: 12

Compression:

Stored size: 801 Bytes

Contents

class ConvertPullRequestLabelsToArray < ActiveRecord::Migration
  def up
    rename_column :pull_requests, :labels, :old_labels
    add_column :pull_requests, :labels, :text, array: true, default: []

    Github::PullRequest.reset_column_information
    Github::PullRequest.pluck(:id, :old_labels).each do |id, old_labels|
      Github::PullRequest.where(id: id).update_all(labels: old_labels.split(/\n/))
    end
  end

  def down
    raise IrreversibleMigration unless Github::PullRequest.column_names.member? "old_labels"

    Github::PullRequest.pluck(:id, :labels).each do |id, labels|
      Github::PullRequest.where(id: id).update_all(old_labels: Array(labels).uniq.join("\n"))
    end

    remove_column :pull_requests, :labels
    rename_column :pull_requests, :old_labels, :labels
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
houston-core-0.8.0.pre db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.7.0 db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.7.0.beta4 db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.7.0.beta3 db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.7.0.beta2 db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.7.0.beta db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.6.3 db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.6.2 db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.6.1 db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.6.0 db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.5.6 db/migrate/20151108221505_convert_pull_request_labels_to_array.rb
houston-core-0.5.5 db/migrate/20151108221505_convert_pull_request_labels_to_array.rb