summaryrefslogtreecommitdiff
path: root/db/migrate/20160902152513_change_project_to_polymorphic_relationship_on_labels.rb
blob: a2963109177fbd2e833d48a490764f61e6f75cd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class ChangeProjectToPolymorphicRelationshipOnLabels < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = true
  DOWNTIME_REASON = 'This migration renames an existing column'

  disable_ddl_transaction!

  def up
    rename_column :labels, :project_id, :subject_id
    add_column :labels, :subject_type, :string
    update_column_in_batches :labels, :subject_type, 'Project'
    add_concurrent_index :labels, :subject_type
  end

  def down
    rename_column :labels, :subject_id, :project_id
    remove_column :labels, :subject_type
  end
end