summaryrefslogtreecommitdiff
path: root/db/migrate/20200407182205_create_partitioned_foreign_keys.rb
blob: 59e7d88b238d871b6ced2f3f92afb1c891055d0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

class CreatePartitionedForeignKeys < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    create_table :partitioned_foreign_keys do |t|
      t.boolean :cascade_delete, null: false, default: true
      t.text :from_table, null: false
      t.text :from_column, null: false
      t.text :to_table, null: false
      t.text :to_column, null: false
    end

    add_text_limit :partitioned_foreign_keys, :from_table, 63
    add_text_limit :partitioned_foreign_keys, :from_column, 63
    add_text_limit :partitioned_foreign_keys, :to_table, 63
    add_text_limit :partitioned_foreign_keys, :to_column, 63

    add_index :partitioned_foreign_keys, [:to_table, :from_table, :from_column], unique: true,
      name: "index_partitioned_foreign_keys_unique_index"
  end

  def down
    # rubocop:disable Migration/DropTable
    drop_table :partitioned_foreign_keys
    # rubocop:enable Migration/DropTable
  end
end