|
1 | 1 | Sequel.migration do |
| 2 | + no_transaction # required for concurrently option on postgres |
2 | 3 | up do |
3 | 4 | transaction do |
4 | 5 | # Remove duplicate entries if they exist |
|
17 | 18 |
|
18 | 19 | self[:buildpacks].where(id: ids_to_remove).delete |
19 | 20 | end |
| 21 | + end |
20 | 22 |
|
| 23 | + if database_type == :postgres |
| 24 | + VCAP::Migration.with_concurrent_timeout(self) do |
| 25 | + drop_index :buildpacks, nil, |
| 26 | + name: :unique_name_and_stack, |
| 27 | + concurrently: true, |
| 28 | + if_exists: true |
| 29 | + add_index :buildpacks, %i[name stack lifecycle], |
| 30 | + name: :buildpacks_name_stack_lifecycle_index, |
| 31 | + unique: true, |
| 32 | + concurrently: true, |
| 33 | + if_not_exists: true |
| 34 | + end |
| 35 | + else |
21 | 36 | alter_table(:buildpacks) do |
22 | | - # rubocop:disable Sequel/ConcurrentIndex |
| 37 | + # rubocop:disable Sequel/ConcurrentIndex -- MySQL does not support concurrent index operations |
23 | 38 | drop_index %i[name stack], name: :unique_name_and_stack if @db.indexes(:buildpacks).key?(:unique_name_and_stack) |
24 | 39 | unless @db.indexes(:buildpacks).key?(:buildpacks_name_stack_lifecycle_index) |
25 | 40 | add_index %i[name stack lifecycle], unique: true, |
|
31 | 46 | end |
32 | 47 |
|
33 | 48 | down do |
34 | | - alter_table(:buildpacks) do |
35 | | - # rubocop:disable Sequel/ConcurrentIndex |
36 | | - drop_index %i[name stack lifecycle], name: :buildpacks_name_stack_lifecycle_index if @db.indexes(:buildpacks).key?(:buildpacks_name_stack_lifecycle_index) |
37 | | - add_index %i[name stack], unique: true, name: :unique_name_and_stack unless @db.indexes(:buildpacks).key?(:unique_name_and_stack) |
38 | | - # rubocop:enable Sequel/ConcurrentIndex |
| 49 | + if database_type == :postgres |
| 50 | + VCAP::Migration.with_concurrent_timeout(self) do |
| 51 | + drop_index :buildpacks, nil, |
| 52 | + name: :buildpacks_name_stack_lifecycle_index, |
| 53 | + concurrently: true, |
| 54 | + if_exists: true |
| 55 | + add_index :buildpacks, %i[name stack], |
| 56 | + name: :unique_name_and_stack, |
| 57 | + unique: true, |
| 58 | + concurrently: true, |
| 59 | + if_not_exists: true |
| 60 | + end |
| 61 | + else |
| 62 | + alter_table(:buildpacks) do |
| 63 | + # rubocop:disable Sequel/ConcurrentIndex -- MySQL does not support concurrent index operations |
| 64 | + drop_index %i[name stack lifecycle], name: :buildpacks_name_stack_lifecycle_index if @db.indexes(:buildpacks).key?(:buildpacks_name_stack_lifecycle_index) |
| 65 | + add_index %i[name stack], unique: true, name: :unique_name_and_stack unless @db.indexes(:buildpacks).key?(:unique_name_and_stack) |
| 66 | + # rubocop:enable Sequel/ConcurrentIndex |
| 67 | + end |
39 | 68 | end |
40 | 69 | end |
41 | 70 | end |
0 commit comments