about summary refs log tree commit diff
path: root/db/migrate/20211213040746_update_account_summaries_to_version_2.rb
blob: 0d1f092ec6152c2a2d94a4b43ac3e902129de708 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class UpdateAccountSummariesToVersion2 < ActiveRecord::Migration[6.1]
  def up
    reapplication_follow_recommendations_v2 do
      drop_view :account_summaries, materialized: true
      create_view :account_summaries, version: 2, materialized: { no_data: true }
      safety_assured { add_index :account_summaries, :account_id, unique: true }
    end
  end

  def down
    reapplication_follow_recommendations_v2 do
      drop_view :account_summaries, materialized: true
      create_view :account_summaries, version: 1, materialized: { no_data: true }
      safety_assured { add_index :account_summaries, :account_id, unique: true }
    end
  end

  def reapplication_follow_recommendations_v2
    drop_view :follow_recommendations, materialized: true
    yield
    create_view :follow_recommendations, version: 2, materialized: { no_data: true }
    safety_assured { add_index :follow_recommendations, :account_id, unique: true }
  end
end