20210505174616_update_follow_recommendations_to_version_2.rb 659 B

1234567891011121314151617181920
  1. # frozen_string_literal: true
  2. class UpdateFollowRecommendationsToVersion2 < ActiveRecord::Migration[6.1]
  3. # We're switching from a normal to a materialized view so we need
  4. # custom `up` and `down` paths.
  5. def up
  6. drop_view :follow_recommendations
  7. create_view :follow_recommendations, version: 2, materialized: { no_data: true }
  8. # To be able to refresh the view concurrently,
  9. # at least one unique index is required
  10. safety_assured { add_index :follow_recommendations, :account_id, unique: true }
  11. end
  12. def down
  13. drop_view :follow_recommendations, materialized: true
  14. create_view :follow_recommendations, version: 1
  15. end
  16. end