20210505174616_update_follow_recommendations_to_version_2.rb 628 B

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