|
| 1 | +# rubocop:disable Metrics/BlockLength |
| 2 | +Sequel.migration do |
| 3 | + no_transaction # required for concurrently option on postgres |
| 4 | + |
| 5 | + up do |
| 6 | + if database_type == :postgres |
| 7 | + VCAP::Migration.with_concurrent_timeout(self) do |
| 8 | + add_index :events, %i[actee created_at guid], |
| 9 | + name: :events_actee_created_at_guid_index, |
| 10 | + if_not_exists: true, |
| 11 | + concurrently: true |
| 12 | + |
| 13 | + add_index :events, %i[space_guid created_at guid], |
| 14 | + name: :events_space_guid_created_at_guid_index, |
| 15 | + if_not_exists: true, |
| 16 | + concurrently: true |
| 17 | + |
| 18 | + add_index :events, %i[organization_guid created_at guid], |
| 19 | + name: :events_organization_guid_created_at_guid_index, |
| 20 | + if_not_exists: true, |
| 21 | + concurrently: true |
| 22 | + end |
| 23 | + else |
| 24 | + alter_table(:events) do |
| 25 | + # rubocop:disable Sequel/ConcurrentIndex |
| 26 | + unless @db.indexes(:events).key?(:events_actee_created_at_guid_index) |
| 27 | + add_index %i[actee created_at guid], |
| 28 | + name: :events_actee_created_at_guid_index |
| 29 | + end |
| 30 | + unless @db.indexes(:events).key?(:events_space_guid_created_at_guid_index) |
| 31 | + add_index %i[space_guid created_at guid], |
| 32 | + name: :events_space_guid_created_at_guid_index |
| 33 | + end |
| 34 | + unless @db.indexes(:events).key?(:events_organization_guid_created_at_guid_index) |
| 35 | + add_index %i[organization_guid created_at guid], |
| 36 | + name: :events_organization_guid_created_at_guid_index |
| 37 | + end |
| 38 | + # rubocop:enable Sequel/ConcurrentIndex |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + down do |
| 44 | + if database_type == :postgres |
| 45 | + VCAP::Migration.with_concurrent_timeout(self) do |
| 46 | + drop_index :events, nil, |
| 47 | + name: :events_actee_created_at_guid_index, |
| 48 | + if_exists: true, |
| 49 | + concurrently: true |
| 50 | + |
| 51 | + drop_index :events, nil, |
| 52 | + name: :events_space_guid_created_at_guid_index, |
| 53 | + if_exists: true, |
| 54 | + concurrently: true |
| 55 | + |
| 56 | + drop_index :events, nil, |
| 57 | + name: :events_organization_guid_created_at_guid_index, |
| 58 | + if_exists: true, |
| 59 | + concurrently: true |
| 60 | + end |
| 61 | + else |
| 62 | + alter_table(:events) do |
| 63 | + # rubocop:disable Sequel/ConcurrentIndex |
| 64 | + drop_index nil, name: :events_actee_created_at_guid_index if @db.indexes(:events).key?(:events_actee_created_at_guid_index) |
| 65 | + drop_index nil, name: :events_space_guid_created_at_guid_index if @db.indexes(:events).key?(:events_space_guid_created_at_guid_index) |
| 66 | + drop_index nil, name: :events_organization_guid_created_at_guid_index if @db.indexes(:events).key?(:events_organization_guid_created_at_guid_index) |
| 67 | + # rubocop:enable Sequel/ConcurrentIndex |
| 68 | + end |
| 69 | + end |
| 70 | + end |
| 71 | +end |
| 72 | +# rubocop:enable Metrics/BlockLength |
0 commit comments