|
1 | | -Sequel.migration do |
| 1 | +Sequel.migration do # rubocop:disable Metrics/BlockLength |
| 2 | + no_transaction # required for concurrently option on postgres |
| 3 | + |
2 | 4 | up do |
3 | 5 | transaction do |
4 | 6 | duplicates = self[:security_groups].select(:name). |
|
14 | 16 | map(:id) |
15 | 17 | self[:security_groups].where(id: ids_to_remove).delete |
16 | 18 | end |
| 19 | + end |
17 | 20 |
|
| 21 | + if database_type == :postgres |
| 22 | + VCAP::Migration.with_concurrent_timeout(self) do |
| 23 | + drop_index :security_groups, nil, |
| 24 | + name: :sg_name_index, |
| 25 | + concurrently: true, |
| 26 | + if_exists: true |
| 27 | + add_index :security_groups, :name, |
| 28 | + name: :security_group_name_index, |
| 29 | + unique: true, |
| 30 | + concurrently: true, |
| 31 | + if_not_exists: true |
| 32 | + end |
| 33 | + else |
18 | 34 | alter_table(:security_groups) do |
19 | | - # Cannot add unique constraint concurrently as it requires a transaction |
20 | | - # rubocop:disable Sequel/ConcurrentIndex |
| 35 | + # rubocop:disable Sequel/ConcurrentIndex -- MySQL does not support concurrent index operations |
21 | 36 | drop_index :name, name: :sg_name_index if @db.indexes(:security_groups).key?(:sg_name_index) |
22 | 37 | add_index :name, name: :security_group_name_index, unique: true unless @db.indexes(:security_groups).key?(:security_group_name_index) |
23 | 38 | # rubocop:enable Sequel/ConcurrentIndex |
|
26 | 41 | end |
27 | 42 |
|
28 | 43 | down do |
29 | | - alter_table(:security_groups) do |
30 | | - # rubocop:disable Sequel/ConcurrentIndex |
31 | | - drop_index :name, name: :security_group_name_index if @db.indexes(:security_groups).key?(:security_group_name_index) |
32 | | - add_index :name, name: :sg_name_index unless @db.indexes(:security_groups).key?(:sg_name_index) |
33 | | - # rubocop:enable Sequel/ConcurrentIndex |
| 44 | + if database_type == :postgres |
| 45 | + VCAP::Migration.with_concurrent_timeout(self) do |
| 46 | + drop_index :security_groups, nil, |
| 47 | + name: :security_group_name_index, |
| 48 | + concurrently: true, |
| 49 | + if_exists: true |
| 50 | + add_index :security_groups, :name, |
| 51 | + name: :sg_name_index, |
| 52 | + concurrently: true, |
| 53 | + if_not_exists: true |
| 54 | + end |
| 55 | + else |
| 56 | + alter_table(:security_groups) do |
| 57 | + # rubocop:disable Sequel/ConcurrentIndex -- MySQL does not support concurrent index operations |
| 58 | + drop_index :name, name: :security_group_name_index if @db.indexes(:security_groups).key?(:security_group_name_index) |
| 59 | + add_index :name, name: :sg_name_index unless @db.indexes(:security_groups).key?(:sg_name_index) |
| 60 | + # rubocop:enable Sequel/ConcurrentIndex |
| 61 | + end |
34 | 62 | end |
35 | 63 | end |
36 | 64 | end |
0 commit comments